|
| 1 | +/* eslint-disable react/no-array-index-key */ |
| 2 | +import React from 'react'; |
| 3 | +import { Document, Page, View } from '..'; |
| 4 | +import renderToImage from './renderComponent'; |
| 5 | + |
| 6 | +const mount = async children => { |
| 7 | + const image = await renderToImage( |
| 8 | + <Document> |
| 9 | + <Page size={[100, 100]}>{children}</Page> |
| 10 | + </Document>, |
| 11 | + ); |
| 12 | + |
| 13 | + return image; |
| 14 | +}; |
| 15 | + |
| 16 | +const items = [ |
| 17 | + 'red', |
| 18 | + 'red', |
| 19 | + 'red', |
| 20 | + 'green', |
| 21 | + 'green', |
| 22 | + 'green', |
| 23 | + 'blue', |
| 24 | + 'blue', |
| 25 | + 'blue', |
| 26 | +]; |
| 27 | + |
| 28 | +describe('flex', () => { |
| 29 | + test('should support gap', async () => { |
| 30 | + const image = await mount( |
| 31 | + <View |
| 32 | + style={{ |
| 33 | + height: '100%', |
| 34 | + width: '100%', |
| 35 | + display: 'flex', |
| 36 | + flexWrap: 'wrap', |
| 37 | + backgroundColor: '#e2e2e2', |
| 38 | + gap: 30, |
| 39 | + }} |
| 40 | + > |
| 41 | + {items.map((color, index) => ( |
| 42 | + <View |
| 43 | + key={index} |
| 44 | + style={{ |
| 45 | + width: 10, |
| 46 | + height: 10, |
| 47 | + backgroundColor: color, |
| 48 | + }} |
| 49 | + /> |
| 50 | + ))} |
| 51 | + </View>, |
| 52 | + ); |
| 53 | + |
| 54 | + expect(image).toMatchImageSnapshot(); |
| 55 | + }); |
| 56 | + |
| 57 | + test('should support rowGap and columnGap', async () => { |
| 58 | + const image = await mount( |
| 59 | + <View |
| 60 | + style={{ |
| 61 | + height: '100%', |
| 62 | + width: '100%', |
| 63 | + display: 'flex', |
| 64 | + flexWrap: 'wrap', |
| 65 | + backgroundColor: '#e2e2e2', |
| 66 | + rowGap: '60px', |
| 67 | + columnGap: '80px', |
| 68 | + }} |
| 69 | + > |
| 70 | + {items.slice(0, 4).map((color, index) => ( |
| 71 | + <View |
| 72 | + key={index} |
| 73 | + style={{ |
| 74 | + width: 10, |
| 75 | + height: 10, |
| 76 | + backgroundColor: color, |
| 77 | + }} |
| 78 | + /> |
| 79 | + ))} |
| 80 | + </View>, |
| 81 | + ); |
| 82 | + |
| 83 | + expect(image).toMatchImageSnapshot(); |
| 84 | + }); |
| 85 | + |
| 86 | + test('should throw when value is percent', async () => { |
| 87 | + expect(mount(<View style={{ gap: '10%' }} />)).rejects.toThrow( |
| 88 | + "You can't pass percentage values to columnGap property", |
| 89 | + ); |
| 90 | + }); |
| 91 | +}); |
0 commit comments