1 | import React from 'react'
|
2 | import renderer from 'react-test-renderer'
|
3 | import { matchers } from 'jest-emotion'
|
4 | import {
|
5 | Text,
|
6 | Heading,
|
7 | Button,
|
8 | Link,
|
9 | Image,
|
10 | Card,
|
11 | } from '../src'
|
12 |
|
13 | expect.extend(matchers)
|
14 |
|
15 | const render = el => renderer.create(el).toJSON()
|
16 |
|
17 | describe('Text', () => {
|
18 | test('renders', () => {
|
19 | const json = render(
|
20 | <Text textAlign='center' fontWeight='bold' fontStyle='italic' />
|
21 | )
|
22 | expect(json.type).toBe('div')
|
23 | expect(json).toHaveStyleRule('text-align', 'center')
|
24 | expect(json).toHaveStyleRule('font-weight', 'bold')
|
25 | expect(json).toHaveStyleRule('font-style', 'italic')
|
26 | })
|
27 |
|
28 | test('renders with text variants', () => {
|
29 | const json = render(
|
30 | <Text
|
31 | theme={{
|
32 | text: {
|
33 | caps: {
|
34 | textTransform: 'uppercase',
|
35 | letterSpacing: '0.2em',
|
36 | }
|
37 | }
|
38 | }}
|
39 | variant='caps'
|
40 | />
|
41 | )
|
42 | expect(json).toHaveStyleRule('text-transform', 'uppercase')
|
43 | expect(json).toHaveStyleRule('letter-spacing', '0.2em')
|
44 | })
|
45 | })
|
46 |
|
47 | describe('Heading', () => {
|
48 | test('renders', () => {
|
49 | const json = render(
|
50 | <Heading />
|
51 | )
|
52 | expect(json.type).toBe('h2')
|
53 | expect(json).toHaveStyleRule('font-size', '24px')
|
54 | expect(json).toHaveStyleRule('font-weight', 'heading')
|
55 | })
|
56 |
|
57 | test('renders with text variants', () => {
|
58 | const json = render(
|
59 | <Heading
|
60 | theme={{
|
61 | text: {
|
62 | display: {
|
63 | fontSize: 64,
|
64 | fontWeight: 900,
|
65 | }
|
66 | }
|
67 | }}
|
68 | variant='display'
|
69 | />
|
70 | )
|
71 | expect(json).toHaveStyleRule('font-size', '64px')
|
72 | expect(json).toHaveStyleRule('font-weight', '900')
|
73 | })
|
74 | })
|
75 |
|
76 | describe('Button', () => {
|
77 | test('renders', () => {
|
78 | const json = render(
|
79 | <Button />
|
80 | )
|
81 | expect(json.type).toBe('button')
|
82 | expect(json).toHaveStyleRule('color', 'white')
|
83 | expect(json).toHaveStyleRule('background-color', 'primary')
|
84 | })
|
85 |
|
86 | test('renders as <a>', () => {
|
87 | const json = render(
|
88 | <Button as='a' />
|
89 | )
|
90 | expect(json.type).toBe('a')
|
91 | })
|
92 | })
|
93 |
|
94 | describe('Link', () => {
|
95 | test('renders', () => {
|
96 | const json = render(
|
97 | <Link />
|
98 | )
|
99 | expect(json.type).toBe('a')
|
100 | })
|
101 |
|
102 | test('renders with theme', () => {
|
103 | const json = render(
|
104 | <Link
|
105 | theme={{
|
106 | variants: {
|
107 | link: {
|
108 | color: 'primary',
|
109 | }
|
110 | }
|
111 | }}
|
112 | />
|
113 | )
|
114 | expect(json).toHaveStyleRule('color', 'primary')
|
115 | })
|
116 | })
|
117 |
|
118 | describe('Image', () => {
|
119 | test('renders', () => {
|
120 | const json = render(
|
121 | <Image />
|
122 | )
|
123 | expect(json.type).toBe('img')
|
124 | expect(json).toHaveStyleRule('max-width', '100%')
|
125 | })
|
126 | })
|
127 |
|
128 | describe('Card', () => {
|
129 | test('renders', () => {
|
130 | const json = render(
|
131 | <Card
|
132 | p={3}
|
133 | bg='tomato'
|
134 | sx={{
|
135 | borderRadius: 8,
|
136 | boxShadow: '0 0 48px tomato',
|
137 | }}
|
138 | />
|
139 | )
|
140 | expect(json.type).toBe('div')
|
141 | expect(json).toHaveStyleRule('padding', '16px')
|
142 | expect(json).toHaveStyleRule('background-color', 'tomato')
|
143 | expect(json).toHaveStyleRule('border-radius', '8px')
|
144 | expect(json).toHaveStyleRule('box-shadow', '0 0 48px tomato')
|
145 | })
|
146 |
|
147 | test('renders with default variant', () => {
|
148 | const json = render(
|
149 | <Card
|
150 | theme={{
|
151 | variants: {
|
152 | card: {
|
153 | p: 3,
|
154 | bg: 'tomato',
|
155 | borderRadius: 4,
|
156 | }
|
157 | }
|
158 | }}
|
159 | />
|
160 | )
|
161 | expect(json).toHaveStyleRule('padding', '16px')
|
162 | expect(json).toHaveStyleRule('background-color', 'tomato')
|
163 | expect(json).toHaveStyleRule('border-radius', '4px')
|
164 | })
|
165 | })
|