Skip to content

Commit e5bfbfc

Browse files
author
Luke Bowerman
authored
test(components-providers): Add coverage for ExtendComponentsProvider and ThemeProvider (#1898)
1 parent 4aed07e commit e5bfbfc

File tree

4 files changed

+127
-0
lines changed

4 files changed

+127
-0
lines changed

packages/components-providers/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"tabbable": "^5.1.4"
2424
},
2525
"devDependencies": {
26+
"@testing-library/react": "^11.2.5",
2627
"@types/lodash": "^4.14.167",
2728
"@types/react": "^16.9.56",
2829
"@types/styled-components": "^5.1.5",
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
3+
MIT License
4+
5+
Copyright (c) 2020 Looker Data Sciences, Inc.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
27+
import React from 'react'
28+
import { renderWithTheme } from '@looker/components-test-utils'
29+
import { screen } from '@testing-library/react'
30+
import styled from 'styled-components'
31+
import { ComponentsProvider } from './ComponentsProvider'
32+
import { ExtendComponentsThemeProvider } from './ExtendComponentsProvider'
33+
34+
const FauxParagraph = styled.p`
35+
background: ${({ theme }) => theme.colors.background};
36+
color: ${({ theme }) => theme.colors.key};
37+
`
38+
39+
describe('ExtendComponentsProvider', () => {
40+
test('Extends existing theme', () => {
41+
const Test = () => {
42+
return (
43+
<ComponentsProvider
44+
themeCustomizations={{
45+
colors: { background: 'black', key: 'purple' },
46+
}}
47+
>
48+
<FauxParagraph>Standard</FauxParagraph>
49+
50+
<ExtendComponentsThemeProvider
51+
themeCustomizations={{
52+
colors: { key: 'red' },
53+
}}
54+
>
55+
<FauxParagraph>Extended</FauxParagraph>
56+
</ExtendComponentsThemeProvider>
57+
</ComponentsProvider>
58+
)
59+
}
60+
61+
renderWithTheme(<Test />)
62+
63+
expect(screen.getByText('Standard')).toHaveStyle('color: purple')
64+
expect(screen.getByText('Standard')).toHaveStyle('background: black')
65+
expect(screen.getByText('Extended')).toHaveStyle('color: red')
66+
expect(screen.getByText('Extended')).toHaveStyle('background: black')
67+
})
68+
})
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
3+
MIT License
4+
5+
Copyright (c) 2020 Looker Data Sciences, Inc.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
25+
*/
26+
27+
import React from 'react'
28+
import { renderWithTheme } from '@looker/components-test-utils'
29+
import { screen } from '@testing-library/react'
30+
import styled from 'styled-components'
31+
import { ThemeProvider } from './ThemeProvider'
32+
33+
const FauxParagraph = styled.p`
34+
color: ${({ theme }) => theme.colors.key};
35+
`
36+
37+
describe('ThemeProvider', () => {
38+
test('builtIn default works', () => {
39+
const Test = () => {
40+
return (
41+
<ThemeProvider>
42+
<FauxParagraph>Standard</FauxParagraph>
43+
</ThemeProvider>
44+
)
45+
}
46+
47+
renderWithTheme(<Test />)
48+
expect(screen.getByText('Standard')).toHaveStyle('color: rgb(108, 67, 224)')
49+
})
50+
})

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3894,6 +3894,14 @@
38943894
"@babel/runtime" "^7.12.5"
38953895
"@testing-library/dom" "^7.28.1"
38963896

3897+
"@testing-library/react@^11.2.5":
3898+
version "11.2.5"
3899+
resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-11.2.5.tgz#ae1c36a66c7790ddb6662c416c27863d87818eb9"
3900+
integrity sha512-yEx7oIa/UWLe2F2dqK0FtMF9sJWNXD+2PPtp39BvE0Kh9MJ9Kl0HrZAgEuhUJR+Lx8Di6Xz+rKwSdEPY2UV8ZQ==
3901+
dependencies:
3902+
"@babel/runtime" "^7.12.5"
3903+
"@testing-library/dom" "^7.28.1"
3904+
38973905
"@testing-library/user-event@^12.5.0":
38983906
version "12.5.0"
38993907
resolved "https://registry.yarnpkg.com/@testing-library/user-event/-/user-event-12.5.0.tgz#7c6f69cee4dbd11037ac9c3f62c5d81b9a4ccf30"

0 commit comments

Comments
 (0)