xref: /expo/apps/test-suite/tests/HTML.js (revision 07efce3d)
1import {
2  A,
3  Article,
4  B,
5  BlockQuote,
6  BR,
7  Caption,
8  Code,
9  Del,
10  EM,
11  Footer,
12  H1,
13  H2,
14  H3,
15  H4,
16  H5,
17  H6,
18  Header,
19  HR,
20  I,
21  LI,
22  Main,
23  Mark,
24  Nav,
25  P,
26  Pre,
27  Q,
28  S,
29  Section,
30  Strong,
31  Table,
32  TBody,
33  TD,
34  TFoot,
35  TH,
36  THead,
37  Time,
38  TR,
39  UL,
40} from '@expo/html-elements';
41import React from 'react';
42import { View } from 'react-native';
43
44import { mountAndWaitFor as originalMountAndWaitFor } from './helpers';
45
46export const name = 'html-elements';
47
48const textElements = {
49  H1,
50  H2,
51  H3,
52  H4,
53  H5,
54  H6,
55  A,
56  P,
57  B,
58  S,
59  Pre,
60  Del,
61  Strong,
62  I,
63  EM,
64  Mark,
65  Code,
66  TH,
67  TD,
68  Caption,
69  LI,
70  Q,
71  Time,
72};
73
74const viewElements = {
75  Article,
76  Header,
77  Main,
78  Section,
79  Nav,
80  BR,
81  HR,
82  Footer,
83  Table,
84  THead,
85  TBody,
86  TFoot,
87  TR,
88  Caption,
89  UL,
90  LI,
91  BlockQuote,
92  Pre,
93};
94
95export async function test(
96  { it, describe, beforeAll, jasmine, afterAll, expect, afterEach, beforeEach },
97  { setPortalChild, cleanupPortal }
98) {
99  afterEach(async () => {
100    await cleanupPortal();
101  });
102
103  const mountAndWaitFor = (child, propName = 'onLayout') =>
104    originalMountAndWaitFor(child, propName, setPortalChild);
105
106  describe(name, () => {
107    describe('Text', () => {
108      for (const elementName of Object.keys(textElements)) {
109        it(`renders text element ${elementName}`, async () => {
110          const Element = textElements[elementName];
111          await mountAndWaitFor(<Element>Test contents</Element>);
112        });
113      }
114    });
115    describe('Views', () => {
116      for (const elementName of Object.keys(viewElements)) {
117        it(`renders view elements ${elementName}`, async () => {
118          const Element = viewElements[elementName];
119          await mountAndWaitFor(
120            <Element>
121              <View />
122            </Element>
123          );
124        });
125      }
126    });
127  });
128}
129