|
| 1 | +import { it, describe, expect } from 'vitest' |
| 2 | + |
| 3 | +import { initFonts, toImage } from './utils.js' |
| 4 | +import satori from '../src/index.js' |
| 5 | + |
| 6 | +describe('Text Align', () => { |
| 7 | + let fonts |
| 8 | + initFonts((f) => (fonts = f)) |
| 9 | + |
| 10 | + it('Should work correctly when `text-align: left`', async () => { |
| 11 | + const svg = await satori( |
| 12 | + <div |
| 13 | + style={{ |
| 14 | + height: '100%', |
| 15 | + width: '100%', |
| 16 | + display: 'flex', |
| 17 | + flexDirection: 'column', |
| 18 | + alignItems: 'center', |
| 19 | + justifyContent: 'center', |
| 20 | + backgroundColor: '#fff', |
| 21 | + fontSize: 20, |
| 22 | + fontWeight: 600, |
| 23 | + }} |
| 24 | + > |
| 25 | + <div |
| 26 | + style={{ |
| 27 | + display: 'flex', |
| 28 | + maxWidth: '190px', |
| 29 | + textAlign: 'left', |
| 30 | + alignItems: 'center', |
| 31 | + justifyContent: 'center', |
| 32 | + backgroundColor: '#ff6c2f', |
| 33 | + color: 'white', |
| 34 | + letterSpacing: '1px', |
| 35 | + }} |
| 36 | + > |
| 37 | + God kisses the finite in his love and man the infinite |
| 38 | + </div> |
| 39 | + </div>, |
| 40 | + { width: 200, height: 200, fonts, embedFont: true } |
| 41 | + ) |
| 42 | + expect(toImage(svg, 200)).toMatchImageSnapshot() |
| 43 | + }) |
| 44 | + |
| 45 | + it('Should work correctly when `text-align: center`', async () => { |
| 46 | + const svg = await satori( |
| 47 | + <div |
| 48 | + style={{ |
| 49 | + height: '100%', |
| 50 | + width: '100%', |
| 51 | + display: 'flex', |
| 52 | + flexDirection: 'column', |
| 53 | + alignItems: 'center', |
| 54 | + justifyContent: 'center', |
| 55 | + backgroundColor: '#fff', |
| 56 | + fontSize: 20, |
| 57 | + fontWeight: 600, |
| 58 | + }} |
| 59 | + > |
| 60 | + <div |
| 61 | + style={{ |
| 62 | + display: 'flex', |
| 63 | + maxWidth: '190px', |
| 64 | + textAlign: 'center', |
| 65 | + alignItems: 'center', |
| 66 | + justifyContent: 'center', |
| 67 | + backgroundColor: '#ff6c2f', |
| 68 | + color: 'white', |
| 69 | + letterSpacing: '1px', |
| 70 | + }} |
| 71 | + > |
| 72 | + God kisses the finite in his love and man the infinite |
| 73 | + </div> |
| 74 | + </div>, |
| 75 | + { width: 200, height: 200, fonts, embedFont: true } |
| 76 | + ) |
| 77 | + expect(toImage(svg, 200)).toMatchImageSnapshot() |
| 78 | + }) |
| 79 | + |
| 80 | + it('Should work correctly when `text-align: right`', async () => { |
| 81 | + const svg = await satori( |
| 82 | + <div |
| 83 | + style={{ |
| 84 | + height: '100%', |
| 85 | + width: '100%', |
| 86 | + display: 'flex', |
| 87 | + flexDirection: 'column', |
| 88 | + alignItems: 'center', |
| 89 | + justifyContent: 'center', |
| 90 | + backgroundColor: '#fff', |
| 91 | + fontSize: 20, |
| 92 | + fontWeight: 600, |
| 93 | + }} |
| 94 | + > |
| 95 | + <div |
| 96 | + style={{ |
| 97 | + display: 'flex', |
| 98 | + maxWidth: '190px', |
| 99 | + textAlign: 'right', |
| 100 | + alignItems: 'center', |
| 101 | + justifyContent: 'center', |
| 102 | + backgroundColor: '#ff6c2f', |
| 103 | + color: 'white', |
| 104 | + letterSpacing: '1px', |
| 105 | + }} |
| 106 | + > |
| 107 | + God kisses the finite in his love and man the infinite |
| 108 | + </div> |
| 109 | + </div>, |
| 110 | + { width: 200, height: 200, fonts, embedFont: true } |
| 111 | + ) |
| 112 | + expect(toImage(svg, 200)).toMatchImageSnapshot() |
| 113 | + }) |
| 114 | + |
| 115 | + it('Should work correctly when `text-align: end`', async () => { |
| 116 | + const svg = await satori( |
| 117 | + <div |
| 118 | + style={{ |
| 119 | + height: '100%', |
| 120 | + width: '100%', |
| 121 | + display: 'flex', |
| 122 | + flexDirection: 'column', |
| 123 | + alignItems: 'center', |
| 124 | + justifyContent: 'center', |
| 125 | + backgroundColor: '#fff', |
| 126 | + fontSize: 20, |
| 127 | + fontWeight: 600, |
| 128 | + }} |
| 129 | + > |
| 130 | + <div |
| 131 | + style={{ |
| 132 | + display: 'flex', |
| 133 | + maxWidth: '190px', |
| 134 | + textAlign: 'end', |
| 135 | + alignItems: 'center', |
| 136 | + justifyContent: 'center', |
| 137 | + backgroundColor: '#ff6c2f', |
| 138 | + color: 'white', |
| 139 | + letterSpacing: '1px', |
| 140 | + }} |
| 141 | + > |
| 142 | + God kisses the finite in his love and man the infinite |
| 143 | + </div> |
| 144 | + </div>, |
| 145 | + { width: 200, height: 200, fonts, embedFont: true } |
| 146 | + ) |
| 147 | + expect(toImage(svg, 200)).toMatchImageSnapshot() |
| 148 | + }) |
| 149 | +}) |
1 commit comments
vercel[bot] commentedon Aug 11, 2023
Successfully deployed to the following URLs:
satori-playground – ./
satori-playground.vercel.app
satori-playground.vercel.sh
og-playground.vercel.app
og-playground.vercel.sh
satori-playground-git-main.vercel.sh