Skip to content

Commit e005061

Browse files
committed
feat: test
1 parent 96cd845 commit e005061

File tree

5 files changed

+241
-4
lines changed

5 files changed

+241
-4
lines changed

.pnp.cjs

+89-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.run/test-unit.run.xml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="test-unit" type="ShConfigurationType">
3+
<option name="SCRIPT_TEXT" value="yarn test unit" />
4+
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
5+
<option name="SCRIPT_PATH" value="" />
6+
<option name="SCRIPT_OPTIONS" value="" />
7+
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
8+
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
9+
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
10+
<option name="INTERPRETER_PATH" value="/bin/zsh" />
11+
<option name="INTERPRETER_OPTIONS" value="" />
12+
<option name="EXECUTE_IN_TERMINAL" value="true" />
13+
<option name="EXECUTE_SCRIPT_FILE" value="false" />
14+
<envs />
15+
<method v="2" />
16+
</configuration>
17+
</component>

packages/payment-widget/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@
2323
"styled-tools": "1.7.2"
2424
},
2525
"devDependencies": {
26+
"@emotion/jest": "11.9.4",
2627
"@emotion/react": "11.9.3",
2728
"@emotion/styled": "11.9.3",
29+
"@testing-library/react": "14.1.0",
2830
"@types/react": "18.2.20",
31+
"@types/react-dom": "18",
2932
"@types/styled-system": "5.1.16",
3033
"csstype": "3.1.2",
3134
"react": "18.2.0",
35+
"react-dom": "18.2.0",
3236
"styled-system": "5.1.5"
3337
},
3438
"peerDependencies": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* @jest-environment jsdom
3+
*/
4+
5+
import { matchers } from '@emotion/jest'
6+
import { RenderResult } from '@testing-library/react'
7+
import { fireEvent } from '@testing-library/react'
8+
import { render } from '@testing-library/react'
9+
import { screen } from '@testing-library/react'
10+
11+
import React from 'react'
12+
import { IntlProvider } from 'react-intl'
13+
import { theme } from './theme/src'
14+
import { ThemeProvider } from './theme/src'
15+
import { Settings } from '../interfaces'
16+
import { Form } from './form.component'
17+
18+
expect.extend(matchers)
19+
20+
type CustomRender = (element: React.ReactNode | React.ReactNode[]) => RenderResult
21+
22+
global.ResizeObserver = jest.fn().mockImplementation(() => ({
23+
observe: jest.fn(),
24+
unobserve: jest.fn(),
25+
disconnect: jest.fn(),
26+
}))
27+
28+
const customRender: CustomRender = (element) => {
29+
return render(
30+
// @ts-ignore
31+
<ThemeProvider>
32+
<IntlProvider locale='ru' onError={() => {}}>
33+
{element}
34+
</IntlProvider>
35+
</ThemeProvider>
36+
)
37+
}
38+
39+
describe('Form fragment', () => {
40+
const settings: Settings = {
41+
storeId: '123'
42+
}
43+
44+
it.only('button reacts to filled in amount', () => {
45+
customRender(<Form settings={settings} />)
46+
47+
const button = screen.getByRole('button', { name: 'Оплатить' })
48+
49+
expect(button).toBeTruthy()
50+
expect(button).toHaveStyleRule('background-color', theme.colors.button.disabled.backgroundColor)
51+
52+
const input = screen.getByPlaceholderText('payment_widget.order_price')
53+
54+
fireEvent.change(input, { target: { value: '100' }})
55+
56+
expect(screen.getByRole('button', { name: 'Оплатить' })).toHaveStyleRule('background-color', theme.colors.button.default.backgroundColor)
57+
})
58+
})

yarn.lock

+73-2
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,16 @@ __metadata:
269269
"@atls-ui-parts/input": "npm:0.0.13"
270270
"@atls-ui-parts/layout": "npm:0.0.7"
271271
"@atls-ui-parts/text": "npm:0.0.11"
272+
"@emotion/jest": "npm:11.9.4"
272273
"@emotion/react": "npm:11.9.3"
273274
"@emotion/styled": "npm:11.9.3"
275+
"@testing-library/react": "npm:^14.1.0"
274276
"@types/react": "npm:18.2.20"
277+
"@types/react-dom": "npm:^18"
275278
"@types/styled-system": "npm:5.1.16"
276279
csstype: "npm:3.1.2"
277280
react: "npm:18.2.0"
281+
react-dom: "npm:18.2.0"
278282
react-intl: "npm:6.4.4"
279283
react-laag: "npm:2.0.5"
280284
styled-system: "npm:5.1.5"
@@ -771,7 +775,7 @@ __metadata:
771775
languageName: node
772776
linkType: hard
773777

774-
"@emotion/css-prettifier@npm:^1.1.3":
778+
"@emotion/css-prettifier@npm:^1.0.1, @emotion/css-prettifier@npm:^1.1.3":
775779
version: 1.1.3
776780
resolution: "@emotion/css-prettifier@npm:1.1.3"
777781
dependencies:
@@ -806,6 +810,27 @@ __metadata:
806810
languageName: node
807811
linkType: hard
808812

813+
"@emotion/jest@npm:11.9.4":
814+
version: 11.9.4
815+
resolution: "@emotion/jest@npm:11.9.4"
816+
dependencies:
817+
"@babel/runtime": "npm:^7.13.10"
818+
"@emotion/css-prettifier": "npm:^1.0.1"
819+
chalk: "npm:^4.1.0"
820+
specificity: "npm:^0.4.1"
821+
stylis: "npm:4.0.13"
822+
peerDependencies:
823+
"@types/jest": ^26.0.14 || ^27.0.0 || ^28.0.0
824+
enzyme-to-json: ^3.2.1
825+
peerDependenciesMeta:
826+
"@types/jest":
827+
optional: true
828+
enzyme-to-json:
829+
optional: true
830+
checksum: b25afc2d4edd07d42695fe2c1dc87642546cf053e421a9d6334998e6b22bd1947df2034e7f2609b8463304ec3e2cf88435c4ae51ba6e9936d75cd1380019c9a3
831+
languageName: node
832+
linkType: hard
833+
809834
"@emotion/jest@npm:^11.9.1":
810835
version: 11.11.0
811836
resolution: "@emotion/jest@npm:11.11.0"
@@ -1804,6 +1829,22 @@ __metadata:
18041829
languageName: node
18051830
linkType: hard
18061831

1832+
"@testing-library/dom@npm:^9.0.0":
1833+
version: 9.3.3
1834+
resolution: "@testing-library/dom@npm:9.3.3"
1835+
dependencies:
1836+
"@babel/code-frame": "npm:^7.10.4"
1837+
"@babel/runtime": "npm:^7.12.5"
1838+
"@types/aria-query": "npm:^5.0.1"
1839+
aria-query: "npm:5.1.3"
1840+
chalk: "npm:^4.1.0"
1841+
dom-accessibility-api: "npm:^0.5.9"
1842+
lz-string: "npm:^1.5.0"
1843+
pretty-format: "npm:^27.0.2"
1844+
checksum: dbb4ce29730058e7ad2f610a1f1907e1ac28abfd8389d36d11fad7d48ef7bc08b1c87f89a97cc1cd1ac85b38665697fdecae712ca5ed3e7b86ffcdd07ae7b52e
1845+
languageName: node
1846+
linkType: hard
1847+
18071848
"@testing-library/jest-dom@npm:^5.16.1, @testing-library/jest-dom@npm:^5.16.2":
18081849
version: 5.17.0
18091850
resolution: "@testing-library/jest-dom@npm:5.17.0"
@@ -1857,6 +1898,20 @@ __metadata:
18571898
languageName: node
18581899
linkType: hard
18591900

1901+
"@testing-library/react@npm:^14.1.0":
1902+
version: 14.1.0
1903+
resolution: "@testing-library/react@npm:14.1.0"
1904+
dependencies:
1905+
"@babel/runtime": "npm:^7.12.5"
1906+
"@testing-library/dom": "npm:^9.0.0"
1907+
"@types/react-dom": "npm:^18.0.0"
1908+
peerDependencies:
1909+
react: ^18.0.0
1910+
react-dom: ^18.0.0
1911+
checksum: 3369b0818317456725a9ae4c012b50b88e94406d2c7688faddba918add0bcb46957f6bd0d760a1fbfc06986adf7d048e14c767901c7adb6f20d6e175197a77ac
1912+
languageName: node
1913+
linkType: hard
1914+
18601915
"@tootallnate/once@npm:1":
18611916
version: 1.1.2
18621917
resolution: "@tootallnate/once@npm:1.1.2"
@@ -2067,6 +2122,15 @@ __metadata:
20672122
languageName: node
20682123
linkType: hard
20692124

2125+
"@types/react-dom@npm:^18, @types/react-dom@npm:^18.0.0":
2126+
version: 18.2.15
2127+
resolution: "@types/react-dom@npm:18.2.15"
2128+
dependencies:
2129+
"@types/react": "npm:*"
2130+
checksum: e3aa4cbd0edbae1d9d7ced55da2306a2eae966aa6fcf9a2d220ff304676bf40d541ef3dd4c84d64f29002d71699816a2043685a6799d8c9342d210d4019bebeb
2131+
languageName: node
2132+
linkType: hard
2133+
20702134
"@types/react-test-renderer@npm:>=16.9.0":
20712135
version: 18.0.0
20722136
resolution: "@types/react-test-renderer@npm:18.0.0"
@@ -6264,7 +6328,7 @@ __metadata:
62646328
languageName: node
62656329
linkType: hard
62666330

6267-
"react-dom@npm:^18.2.0":
6331+
"react-dom@npm:18.2.0, react-dom@npm:^18.2.0":
62686332
version: 18.2.0
62696333
resolution: "react-dom@npm:18.2.0"
62706334
dependencies:
@@ -6896,6 +6960,13 @@ __metadata:
68966960
languageName: node
68976961
linkType: hard
68986962

6963+
"stylis@npm:4.0.13":
6964+
version: 4.0.13
6965+
resolution: "stylis@npm:4.0.13"
6966+
checksum: 3231e328da331d07673edc39f1bf0e741d0b891473764b116fe4f4eb22c595435f142860f7a54ddff32bf64ecdd3dbe356cc608a029c4f066d5c5b7f1315d996
6967+
languageName: node
6968+
linkType: hard
6969+
68996970
"stylis@npm:4.2.0":
69006971
version: 4.2.0
69016972
resolution: "stylis@npm:4.2.0"

0 commit comments

Comments
 (0)