cozy-ui 113.8.0 → 114.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/jest.config.js +1 -2
  3. package/package.json +6 -12
  4. package/react/AppSections/components/AppsSection.spec.jsx +10 -19
  5. package/react/AppSections/index.spec.jsx +98 -77
  6. package/react/ContactsList/ContactRow.spec.js +28 -53
  7. package/react/DateMonthPicker/index.spec.jsx +17 -45
  8. package/react/Field/index.spec.js +28 -5
  9. package/react/Figure/Figure.spec.jsx +9 -4
  10. package/react/Figure/__snapshots__/Figure.spec.jsx.snap +289 -225
  11. package/react/FileInput/index.jsx +1 -0
  12. package/react/FileInput/index.spec.jsx +16 -38
  13. package/react/Paywall/Paywall.spec.jsx +3 -5
  14. package/react/Popup/index.spec.jsx +90 -41
  15. package/react/QualificationIconStack/Readme.md +4 -1
  16. package/react/QualificationIconStack/index.jsx +28 -7
  17. package/react/QualificationModal/Readme.md +28 -0
  18. package/react/QualificationModal/index.jsx +94 -0
  19. package/react/QualificationModal/locales/en.json +5 -0
  20. package/react/QualificationModal/locales/fr.json +5 -0
  21. package/react/QualificationModal/locales/index.jsx +7 -0
  22. package/react/deprecated/ViewStack/example.jsx +1 -1
  23. package/react/hooks/useClientErrors.spec.jsx +16 -24
  24. package/react/index.js +2 -0
  25. package/react/providers/I18n/index.spec.jsx +13 -5
  26. package/react/providers/I18n/withLocales.spec.jsx +4 -4
  27. package/transpiled/react/FileInput/index.js +2 -1
  28. package/transpiled/react/QualificationIconStack/index.js +26 -6
  29. package/transpiled/react/QualificationModal/index.js +126 -0
  30. package/transpiled/react/QualificationModal/locales/index.js +14 -0
  31. package/transpiled/react/deprecated/ViewStack/example.js +1 -1
  32. package/transpiled/react/index.js +2 -0
  33. package/react/AppSections/__snapshots__/index.spec.jsx.snap +0 -1843
  34. package/react/AppSections/components/__snapshots__/AppsSection.spec.jsx.snap +0 -41
  35. package/react/ContactsList/__snapshots__/ContactRow.spec.js.snap +0 -69
  36. package/react/FileInput/__snapshots__/index.spec.jsx.snap +0 -86
  37. package/react/Input/__snapshots__/index.spec.jsx.snap +0 -11
  38. package/react/Input/index.spec.jsx +0 -12
  39. package/react/__snapshots__/examples.spec.jsx.snap +0 -3720
  40. package/react/deprecated/ActionMenu/__snapshots__/index.spec.jsx.snap +0 -157
  41. package/react/deprecated/ActionMenu/index.spec.jsx +0 -115
  42. package/react/deprecated/Alerter/__snapshots__/alerter.spec.js.snap +0 -88
  43. package/react/deprecated/Alerter/alerter.spec.js +0 -78
  44. package/react/deprecated/InfosCarrousel/index.spec.jsx +0 -71
  45. package/react/deprecated/Modal/index.spec.jsx +0 -70
  46. package/react/deprecated/ViewStack/index.spec.jsx +0 -64
  47. package/react/examples.spec.jsx +0 -67
package/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ # [114.0.0](https://github.com/cozy/cozy-ui/compare/v113.9.0...v114.0.0) (2024-12-12)
2
+
3
+
4
+ ### Features
5
+
6
+ * Add QualificationModal component ([e2ebcc0](https://github.com/cozy/cozy-ui/commit/e2ebcc0))
7
+ * Upgrade packages ([4ca7867](https://github.com/cozy/cozy-ui/commit/4ca7867))
8
+
9
+
10
+ ### BREAKING CHANGES
11
+
12
+ * You must have `cozy-client >= 51.6.0` and `cozy-intent >= 2.29.1`
13
+
14
+ # [113.9.0](https://github.com/cozy/cozy-ui/compare/v113.8.0...v113.9.0) (2024-12-10)
15
+
16
+
17
+ ### Features
18
+
19
+ * **QualificationIconStack:** Add `theme` props ([61081a1](https://github.com/cozy/cozy-ui/commit/61081a1))
20
+
1
21
  # [113.8.0](https://github.com/cozy/cozy-ui/compare/v113.7.1...v113.8.0) (2024-12-04)
2
22
 
3
23
 
package/jest.config.js CHANGED
@@ -21,6 +21,5 @@ module.exports = {
21
21
  globals: {
22
22
  __ALLOW_HTTP__: false,
23
23
  cozy: {}
24
- },
25
- snapshotSerializers: ['enzyme-to-json/serializer']
24
+ }
26
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "113.8.0",
3
+ "version": "114.0.0",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -48,8 +48,6 @@
48
48
  "sprite": "scripts/make-icon-sprite.sh",
49
49
  "screenshots": "node scripts/screenshots.js --screenshot-dir ./screenshots --styleguide-url file://$(pwd)/build/react --kss-dir ./build/styleguide",
50
50
  "test": "jest",
51
- "test:noSnapshots": "jest --testPathIgnorePatterns 'react/examples.spec.jsx'",
52
- "test:snapshots": "jest react/examples.spec.jsx",
53
51
  "screenshots:server": "nodemon ./scripts/pixelmatch-server/server.js -e js,hbs",
54
52
  "postbuild": "postcss transpiled/react/stylesheet.css --replace",
55
53
  "travis-deploy-once": "travis-deploy-once",
@@ -94,18 +92,15 @@
94
92
  "browserslist-config-cozy": "0.4.0",
95
93
  "bundlemon": "3.1.0",
96
94
  "copyfiles": "2.4.1",
97
- "cozy-client": "^48.8.0",
95
+ "cozy-client": "^51.6.0",
98
96
  "cozy-device-helper": "2.0.0",
99
97
  "cozy-flags": "^2.10.1",
100
- "cozy-intent": "1.16.1",
98
+ "cozy-intent": "^2.29.1",
101
99
  "cozy-logger": "^1.9.0",
102
- "cozy-stack-client": "^47.4.0",
100
+ "cozy-stack-client": "^51.6.0",
103
101
  "css-loader": "0.28.11",
104
102
  "cssnano": "4.1.11",
105
103
  "cssnano-preset-advanced": "4.0.8",
106
- "enzyme": "3.11.0",
107
- "enzyme-adapter-react-16": "1.15.6",
108
- "enzyme-to-json": "3.6.2",
109
104
  "eslint": "8.11.0",
110
105
  "eslint-config-cozy-app": "^6.1.0",
111
106
  "eslint-config-prettier": "8.6.0",
@@ -134,7 +129,6 @@
134
129
  "postcss-cli": "6.1.3",
135
130
  "postcss-loader": "2.1.6",
136
131
  "prettier": "2.6.0",
137
- "pretty": "2.0.0",
138
132
  "prop-types": "15.7.2",
139
133
  "react": "16.12.0",
140
134
  "react-dom": "16.12.0",
@@ -187,9 +181,9 @@
187
181
  "rooks": "^5.11.2"
188
182
  },
189
183
  "peerDependencies": {
190
- "cozy-client": ">=48.8.0",
184
+ "cozy-client": ">=51.6.0",
191
185
  "cozy-device-helper": "^2.0.0",
192
- "cozy-intent": ">=1.3.0",
186
+ "cozy-intent": ">=2.29.1",
193
187
  "react": "^16.8.6",
194
188
  "react-dom": "^16.8.6"
195
189
  },
@@ -2,13 +2,12 @@
2
2
 
3
3
  /* eslint-env jest */
4
4
 
5
- import { mount } from 'enzyme'
5
+ import { fireEvent, render, screen } from '@testing-library/react'
6
6
  import React from 'react'
7
7
 
8
8
  import { CozyProvider } from 'cozy-client'
9
9
 
10
10
  import { AppsSection } from './AppsSection'
11
- import Tile, { TileTitle, TileSubtitle, TileFooter } from '../../Tile'
12
11
  import { I18nContext } from '../../jestLib/I18n'
13
12
  import mockApps from '../../mocks/apps'
14
13
  import { BreakpointsProvider } from '../../providers/Breakpoints'
@@ -19,10 +18,9 @@ const i18nContext = I18nContext({ locale: en })
19
18
  const tMock = i18nContext.t
20
19
 
21
20
  describe('AppsSection component', () => {
22
- let component
23
21
  const client = {}
24
22
  const setup = ({ onAppClick }) => {
25
- component = mount(
23
+ render(
26
24
  <CozyProvider client={client}>
27
25
  <BreakpointsProvider>
28
26
  <I18n lang="en" dictRequire={() => en}>
@@ -36,31 +34,24 @@ describe('AppsSection component', () => {
36
34
  </I18n>
37
35
  </BreakpointsProvider>
38
36
  </CozyProvider>
39
- ).find(AppsSection)
37
+ )
40
38
  }
41
39
 
42
40
  it('should be rendered correctly with apps list, subtitle', () => {
43
41
  const mockOnAppClick = jest.fn()
44
42
  setup({ onAppClick: mockOnAppClick })
45
- expect(
46
- component.find(Tile).map(x => {
47
- const developer = x.find(TileSubtitle)
48
- const status = x.find(TileFooter)
49
- return {
50
- title: x.find(TileTitle).text(),
51
- developer: developer.length ? developer.text() : null,
52
- status: status.length ? status.text() : null
53
- }
54
- })
55
- ).toMatchSnapshot()
43
+
44
+ mockApps.forEach(app => {
45
+ expect(screen.getByText(app.name, { exact: false })).toBeInTheDocument()
46
+ })
56
47
  })
57
48
 
58
49
  it('should run provided onAppClick on AppTile click event', () => {
59
50
  const mockOnAppClick = jest.fn()
60
51
  setup({ onAppClick: mockOnAppClick })
61
- expect(component.find(Tile).length).toBe(mockApps.length)
62
- const appItem = component.find(Tile).at(0)
63
- appItem.simulate('click')
52
+
53
+ const bouilligue = screen.getByText('Bouilligue', { exact: false })
54
+ fireEvent.click(bouilligue)
64
55
  expect(mockOnAppClick.mock.calls.length).toBe(1)
65
56
  expect(mockOnAppClick.mock.calls[0][0]).toBe('konnector-bouilligue')
66
57
  })
@@ -2,13 +2,14 @@
2
2
 
3
3
  /* eslint-env jest */
4
4
 
5
- import { shallow } from 'enzyme'
5
+ import { render, screen } from '@testing-library/react'
6
6
  import React from 'react'
7
7
 
8
8
  import { Sections } from './Sections'
9
9
  import en from './locales/en.json'
10
10
  import { I18nContext } from '../jestLib/I18n'
11
11
  import mockApps from '../mocks/apps'
12
+ import DemoProvider from '../providers/DemoProvider'
12
13
 
13
14
  const i18nContext = I18nContext({ locale: en })
14
15
  const tMock = i18nContext.t
@@ -16,101 +17,121 @@ const tMock = i18nContext.t
16
17
  describe('AppsSection component', () => {
17
18
  it('should be rendered correctly with apps list, subtitle and onAppClick', () => {
18
19
  const mockOnAppClick = jest.fn()
19
- const component = shallow(
20
- <Sections
21
- t={tMock}
22
- lang="en"
23
- subtitle="Test Apps"
24
- apps={mockApps}
25
- allApps={mockApps}
26
- onAppClick={mockOnAppClick}
27
- error={null}
28
- location={{ search: '' }}
29
- />
30
- ).getElement()
31
- expect(component).toMatchSnapshot()
20
+ render(
21
+ <DemoProvider>
22
+ <Sections
23
+ t={tMock}
24
+ lang="en"
25
+ subtitle="Test Apps"
26
+ apps={mockApps}
27
+ allApps={mockApps}
28
+ onAppClick={mockOnAppClick}
29
+ error={null}
30
+ location={{ search: '' }}
31
+ />
32
+ </DemoProvider>
33
+ )
34
+
35
+ expect(screen.queryByText('Cozy Collect')).toBeInTheDocument()
36
+ expect(screen.queryByText('Cozy Drive')).toBeInTheDocument()
37
+ expect(screen.queryByText('DevOnly')).toBeInTheDocument()
32
38
  })
33
39
 
34
40
  it('should render correctly render message if error provided', () => {
35
41
  const mockOnAppClick = jest.fn()
36
- const component = shallow(
37
- <Sections
38
- t={tMock}
39
- lang="en"
40
- subtitle="Test Apps"
41
- apps={mockApps}
42
- allApps={mockApps}
43
- onAppClick={mockOnAppClick}
44
- error={new Error('This is a test error')}
45
- location={{ search: '' }}
46
- />
47
- ).getElement()
48
- expect(component).toMatchSnapshot()
42
+ render(
43
+ <DemoProvider>
44
+ <Sections
45
+ t={tMock}
46
+ lang="en"
47
+ subtitle="Test Apps"
48
+ apps={mockApps}
49
+ allApps={mockApps}
50
+ onAppClick={mockOnAppClick}
51
+ error={new Error('This is a test error')}
52
+ location={{ search: '' }}
53
+ />
54
+ </DemoProvider>
55
+ )
56
+
57
+ expect(screen.queryByText('This is a test error')).toBeInTheDocument()
49
58
  })
50
59
 
51
60
  it('should not render dropdown filter on mobile if nav=false flag provided', () => {
52
61
  const mockOnAppClick = jest.fn()
53
- const component = shallow(
54
- <Sections
55
- t={tMock}
56
- lang="en"
57
- subtitle="Test Apps"
58
- apps={mockApps}
59
- allApps={mockApps}
60
- onAppClick={mockOnAppClick}
61
- breakpoints={{ isMobile: true }}
62
- hasNav={false}
63
- />
64
- ).getElement()
65
- expect(component).toMatchSnapshot()
62
+ render(
63
+ <DemoProvider>
64
+ <Sections
65
+ t={tMock}
66
+ lang="en"
67
+ subtitle="Test Apps"
68
+ apps={mockApps}
69
+ allApps={mockApps}
70
+ onAppClick={mockOnAppClick}
71
+ breakpoints={{ isMobile: true }}
72
+ hasNav={false}
73
+ />
74
+ </DemoProvider>
75
+ )
76
+
77
+ expect(screen.queryByText('All categories')).not.toBeInTheDocument()
66
78
  })
67
79
 
68
80
  it('should not render dropdown filter on tablet if nav=false flag provided', () => {
69
81
  const mockOnAppClick = jest.fn()
70
- const component = shallow(
71
- <Sections
72
- t={tMock}
73
- lang="en"
74
- subtitle="Test Apps"
75
- apps={mockApps}
76
- allApps={mockApps}
77
- onAppClick={mockOnAppClick}
78
- breakpoints={{ isTablet: true }}
79
- hasNav={false}
80
- />
81
- ).getElement()
82
- expect(component).toMatchSnapshot()
82
+ render(
83
+ <DemoProvider>
84
+ <Sections
85
+ t={tMock}
86
+ lang="en"
87
+ subtitle="Test Apps"
88
+ apps={mockApps}
89
+ allApps={mockApps}
90
+ onAppClick={mockOnAppClick}
91
+ breakpoints={{ isTablet: true }}
92
+ hasNav={false}
93
+ />
94
+ </DemoProvider>
95
+ )
96
+
97
+ expect(screen.queryByText('All categories')).not.toBeInTheDocument()
83
98
  })
84
99
 
85
100
  it('should render dropdown filter on mobile if no nav=false flag provided', () => {
86
101
  const mockOnAppClick = jest.fn()
87
- const component = shallow(
88
- <Sections
89
- t={tMock}
90
- lang="en"
91
- subtitle="Test Apps"
92
- apps={mockApps}
93
- allApps={mockApps}
94
- onAppClick={mockOnAppClick}
95
- breakpoints={{ isMobile: true }}
96
- />
97
- ).getElement()
98
- expect(component).toMatchSnapshot()
102
+ render(
103
+ <DemoProvider>
104
+ <Sections
105
+ t={tMock}
106
+ lang="en"
107
+ subtitle="Test Apps"
108
+ apps={mockApps}
109
+ allApps={mockApps}
110
+ onAppClick={mockOnAppClick}
111
+ breakpoints={{ isMobile: true }}
112
+ />
113
+ </DemoProvider>
114
+ )
115
+
116
+ expect(screen.queryByText('All categories')).toBeInTheDocument()
99
117
  })
100
118
 
101
119
  it('should render dropdown filter on tablet if no nav=false flag provided', () => {
102
120
  const mockOnAppClick = jest.fn()
103
- const component = shallow(
104
- <Sections
105
- t={tMock}
106
- lang="en"
107
- subtitle="Test Apps"
108
- apps={mockApps}
109
- allApps={mockApps}
110
- onAppClick={mockOnAppClick}
111
- breakpoints={{ isTablet: true }}
112
- />
113
- ).getElement()
114
- expect(component).toMatchSnapshot()
121
+ render(
122
+ <DemoProvider>
123
+ <Sections
124
+ t={tMock}
125
+ lang="en"
126
+ subtitle="Test Apps"
127
+ apps={mockApps}
128
+ allApps={mockApps}
129
+ onAppClick={mockOnAppClick}
130
+ breakpoints={{ isTablet: true }}
131
+ />
132
+ </DemoProvider>
133
+ )
134
+
135
+ expect(screen.queryByText('All categories')).toBeInTheDocument()
115
136
  })
116
137
  })
@@ -1,6 +1,5 @@
1
- import { mount } from 'enzyme'
1
+ import { render, screen } from '@testing-library/react'
2
2
  import React from 'react'
3
- import renderer from 'react-test-renderer'
4
3
 
5
4
  import logger from 'cozy-logger'
6
5
 
@@ -16,20 +15,22 @@ const makeContact = attrs => ({
16
15
  })
17
16
 
18
17
  const setup = ({ contact }) => {
19
- const root = mount(
18
+ render(
20
19
  <BreakpointsProvider>
21
20
  <ContactRow contact={contact} />
22
21
  </BreakpointsProvider>
23
22
  )
24
- return { root }
25
23
  }
26
24
 
27
25
  describe('ContactRow', () => {
28
26
  it('should accept the strict minimum', () => {
29
27
  const contact = makeContact({ email: [{ address: 'johndoe@localhost' }] })
30
- const { root } = setup({ contact })
31
- const contactrowemail = root.find('ContactEmail')
32
- expect(contactrowemail.text()).toBe(contact.email[0].address)
28
+ setup({ contact })
29
+
30
+ // With a minimal contact, email is displayed twice
31
+ // - one as display name
32
+ // - one as email
33
+ expect(screen.getAllByText('johndoe@localhost').length).toBe(2)
33
34
  })
34
35
 
35
36
  it('should display data', () => {
@@ -39,62 +40,36 @@ describe('ContactRow', () => {
39
40
  email: [{ address: 'johndoe@localhost' }],
40
41
  cozy: [{ url: 'http://johndoe.mycozy.cloud' }]
41
42
  })
42
- const { root } = setup({ contact })
43
- const contactrowname = root.find('ContactName')
44
- expect(contactrowname).toBeDefined()
45
- expect(contactrowname.text()).toEqual(
46
- expect.stringContaining(contact.name.givenName)
47
- )
48
- expect(contactrowname.text()).toEqual(
49
- expect.stringContaining(contact.name.familyName)
50
- )
51
- const contactrowphone = root.find('ContactPhone')
52
- expect(contactrowphone).toBeDefined()
53
- expect(contactrowphone.text()).toBe(contact.phone[0].number)
43
+ setup({ contact })
54
44
 
55
- const contactrowcozyurl = root.find('ContactCozy')
56
- expect(contactrowcozyurl).toBeDefined()
57
- expect(contactrowcozyurl.text()).toBe(contact.cozy[0].url)
45
+ // We need to check first and last name separatly because they are in two different span
46
+ expect(screen.getByText('John')).toBeInTheDocument()
47
+ expect(screen.getByText('Doe')).toBeInTheDocument()
48
+ expect(screen.getByText('0123456789')).toBeInTheDocument()
49
+ expect(screen.getByText('johndoe@localhost')).toBeInTheDocument()
50
+ expect(screen.getByText('http://johndoe.mycozy.cloud')).toBeInTheDocument()
58
51
  })
59
52
 
60
53
  it('should display email for missing information', () => {
61
54
  const contact = makeContact({
62
55
  email: [{ address: 'johndoe@localhost' }]
63
56
  })
64
- const { root } = setup({ contact })
65
- const contactrowname = root.find('ContactName')
66
- expect(contactrowname).toBeDefined()
67
- expect(contactrowname.text().trim()).toBe('johndoe@localhost')
68
- const contactrowphone = root.find('ContactPhone')
69
- expect(contactrowphone).toBeDefined()
70
- expect(contactrowphone.text().trim()).toBe('—')
71
- const contactrowcozyurl = root.find('ContactCozy')
72
- expect(contactrowcozyurl).toBeDefined()
73
- expect(contactrowcozyurl.text().trim()).toBe('—')
57
+ setup({ contact })
58
+
59
+ const emailColumn = screen.getByTestId('ContactEmail')
60
+ expect(emailColumn.textContent).toBe('johndoe@localhost')
61
+
62
+ const phoneColumn = screen.getByTestId('ContactPhone')
63
+ expect(phoneColumn.textContent).toBe('—')
64
+
65
+ const cozyColumn = screen.getByTestId('ContactCozy')
66
+ expect(cozyColumn.textContent).toBe('—')
74
67
  })
75
68
 
76
69
  it('should accept empty array', () => {
77
70
  const contact = makeContact({ email: [] })
78
- const { root } = setup({ contact })
79
- const contactrowemail = root.find('ContactEmail')
80
- expect(contactrowemail).toBeDefined()
81
- expect(contactrowemail.text()).toBe('—')
82
- })
83
-
84
- it('should match the contact snapshot', () => {
85
- const contact = makeContact({
86
- name: { familyName: 'Doe', givenName: 'John' },
87
- phone: [{ number: '0123456789' }],
88
- email: [{ address: 'johndoe@localhost' }],
89
- cozy: [{ url: 'http://johndoe.mycozy.cloud' }]
90
- })
91
- const tree = renderer
92
- .create(
93
- <BreakpointsProvider>
94
- <ContactRow contact={contact} />
95
- </BreakpointsProvider>
96
- )
97
- .toJSON()
98
- expect(tree).toMatchSnapshot()
71
+ setup({ contact })
72
+ const emailColumn = screen.getByTestId('ContactEmail')
73
+ expect(emailColumn.textContent).toBe('—')
99
74
  })
100
75
  })
@@ -1,36 +1,13 @@
1
- import { mount } from 'enzyme'
1
+ import { fireEvent, render, screen } from '@testing-library/react'
2
2
  import React from 'react'
3
- import { act } from 'react-dom/test-utils'
4
3
 
5
4
  import DateMonthPicker from '.'
6
- import LeftIcon from '../Icons/Left'
7
- import RightIcon from '../Icons/Right'
8
5
  import I18n from '../providers/I18n'
9
6
 
10
- const findButtonWithLabel = (root, label) =>
11
- root.findWhere(n => n.type() == 'button' && n.props().children === label)
12
-
13
- const findButtonWithIcon = (root, iconName) =>
14
- root.findWhere(n => {
15
- const props = n.props()
16
- if (n.type() !== 'button') {
17
- return
18
- }
19
- if (!props.children || !props.children.length > 1) {
20
- return
21
- }
22
-
23
- return (
24
- props.children.props &&
25
- props.children.props.icon &&
26
- props.children.props.icon == iconName
27
- )
28
- })
29
-
30
7
  describe('DateMonthPicker', () => {
31
8
  const setup = ({ initialValue }) => {
32
9
  const handleSelect = jest.fn()
33
- const root = mount(
10
+ const root = render(
34
11
  <I18n lang="en" dictRequire={() => {}}>
35
12
  <DateMonthPicker initialValue={initialValue} onSelect={handleSelect} />
36
13
  </I18n>
@@ -39,36 +16,31 @@ describe('DateMonthPicker', () => {
39
16
  }
40
17
 
41
18
  it('should be able to select a month', async () => {
42
- const { root, handleSelect } = setup({ initialValue: '2015-08' })
43
- const februaryButton = findButtonWithLabel(root, 'Feb')
44
- expect(februaryButton.length).toBe(1)
45
- februaryButton.props().onClick()
19
+ const { handleSelect } = setup({ initialValue: '2015-08' })
20
+ const februaryButton = screen.getByText('Feb')
21
+ fireEvent.click(februaryButton)
46
22
  expect(handleSelect).toHaveBeenCalledTimes(1)
47
23
  expect(handleSelect).toHaveBeenCalledWith('2015-02-01')
48
24
  })
49
25
 
50
26
  it('should be able to go to previous year', async () => {
51
- const { root, handleSelect } = setup({ initialValue: '2015-08' })
52
- const prevYearButton = findButtonWithIcon(root, LeftIcon)
53
- act(() => {
54
- prevYearButton.props().onClick()
55
- })
56
- root.update()
57
- const februaryButton = findButtonWithLabel(root, 'Feb')
58
- februaryButton.props().onClick()
27
+ const { handleSelect } = setup({ initialValue: '2015-08' })
28
+ // Left arrow to go to previous year is first button
29
+ const previousYearButton = screen.getAllByRole('button')[0]
30
+ fireEvent.click(previousYearButton)
31
+ const februaryButton = screen.getByText('Feb')
32
+ fireEvent.click(februaryButton)
59
33
  expect(handleSelect).toHaveBeenCalledTimes(1)
60
34
  expect(handleSelect).toHaveBeenCalledWith('2014-02-01')
61
35
  })
62
36
 
63
37
  it('should be able to go to next year', async () => {
64
- const { root, handleSelect } = setup({ initialValue: '2015-08' })
65
- const nextYearButton = findButtonWithIcon(root, RightIcon)
66
- act(() => {
67
- nextYearButton.props().onClick()
68
- })
69
- root.update()
70
- const februaryButton = findButtonWithLabel(root, 'Feb')
71
- februaryButton.props().onClick()
38
+ const { handleSelect } = setup({ initialValue: '2015-08' })
39
+ // Right arrow to go to next year is first button
40
+ const nextYearButton = screen.getAllByRole('button')[1]
41
+ fireEvent.click(nextYearButton)
42
+ const februaryButton = screen.getByText('Feb')
43
+ fireEvent.click(februaryButton)
72
44
  expect(handleSelect).toHaveBeenCalledTimes(1)
73
45
  expect(handleSelect).toHaveBeenCalledWith('2016-02-01')
74
46
  })
@@ -1,4 +1,4 @@
1
- import { shallow } from 'enzyme'
1
+ import { render } from '@testing-library/react'
2
2
  import React from 'react'
3
3
 
4
4
  import Field from '.'
@@ -18,19 +18,42 @@ describe('Field component', () => {
18
18
 
19
19
  it('should expect object type value for type=select', () => {
20
20
  expect(() =>
21
- shallow(<Field label="mock field" type="select" value={{}} />)
21
+ render(
22
+ <Field
23
+ label="mock field"
24
+ type="select"
25
+ value={{}}
26
+ onChange={() => {}}
27
+ />
28
+ )
22
29
  ).not.toThrowError()
23
30
  expect(() =>
24
- shallow(<Field label="mock field" type="select" value="wrong" />)
31
+ render(
32
+ <Field
33
+ label="mock field"
34
+ type="select"
35
+ value="wrong"
36
+ onChange={() => {}}
37
+ />
38
+ )
25
39
  ).toThrowError()
26
40
  })
27
41
 
28
42
  it('should expect string type value for all types but select', () => {
29
43
  expect(() =>
30
- shallow(<Field label="mock field" type="text" value="good" />)
44
+ render(
45
+ <Field
46
+ label="mock field"
47
+ type="text"
48
+ value="good"
49
+ onChange={() => {}}
50
+ />
51
+ )
31
52
  ).not.toThrowError()
32
53
  expect(() =>
33
- shallow(<Field label="mock field" type="text" value={{}} />)
54
+ render(
55
+ <Field label="mock field" type="text" value={{}} onChange={() => {}} />
56
+ )
34
57
  ).toThrowError()
35
58
  })
36
59
  })
@@ -1,4 +1,4 @@
1
- import { shallow } from 'enzyme'
1
+ import { render } from '@testing-library/react'
2
2
  import { flatten, merge } from 'lodash'
3
3
  import React from 'react'
4
4
 
@@ -39,13 +39,18 @@ describe('Figure', () => {
39
39
  return merge.apply(null, [{}, ...attrs])
40
40
  })
41
41
 
42
+ // We check for different king of amounts if
43
+ // - its red if it is negative if coloredNegative is set
44
+ // - its green if it is positive if coloredPositive is set
45
+ // - its yellow if it is above the warning limit if coloredWarning is set
46
+
42
47
  for (let amount of amounts) {
43
48
  for (let attrs of combinations) {
44
49
  it(`should render correctly ${amount} ${formatAttrs(attrs)}`, () => {
45
- const el = shallow(
50
+ const { container } = render(
46
51
  <Figure warningLimit={110} total={amount} {...attrs} />
47
- ).getElement()
48
- expect(el).toMatchSnapshot()
52
+ )
53
+ expect(container).toMatchSnapshot()
49
54
  })
50
55
  }
51
56
  }