cozy-client 51.3.0 → 51.3.1

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.
@@ -3032,7 +3032,7 @@ var CozyClient = /*#__PURE__*/function () {
3032
3032
  CozyClient.hooks = CozyClient.hooks || {};
3033
3033
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
3034
3034
 
3035
- CozyClient.version = "51.3.0";
3035
+ CozyClient.version = "51.3.1";
3036
3036
 
3037
3037
  _microee.default.mixin(CozyClient);
3038
3038
 
@@ -3,7 +3,7 @@ jest.mock('./CozyClient')
3
3
  import React, { Component } from 'react'
4
4
  import PropTypes from 'prop-types'
5
5
  import configureStore from 'redux-mock-store'
6
- import { mount, shallow } from 'enzyme'
6
+ import { fireEvent, render } from '@testing-library/react'
7
7
 
8
8
  import Provider from './Provider'
9
9
  import CozyClient from './CozyClient'
@@ -13,12 +13,12 @@ describe('Provider', () => {
13
13
  const store = configureStore()({})
14
14
 
15
15
  it('should renders children when passed in', () => {
16
- const wrapper = shallow(
16
+ const wrapper = render(
17
17
  <Provider client={client} store={store}>
18
- <div className="unique" />
18
+ <div>Component</div>
19
19
  </Provider>
20
20
  )
21
- expect(wrapper.contains(<div className="unique" />)).toBe(true)
21
+ expect(wrapper.getByText('Component')).toBeTruthy()
22
22
  })
23
23
 
24
24
  it('should provide the client in the context', () => {
@@ -33,12 +33,12 @@ describe('Provider', () => {
33
33
  return <button onClick={this.onClick} />
34
34
  }
35
35
  }
36
- const wrapper = mount(
36
+ const wrapper = render(
37
37
  <Provider client={client} store={store}>
38
38
  <FakeComponent />
39
39
  </Provider>
40
40
  )
41
- wrapper.find('button').simulate('click')
41
+ fireEvent.click(wrapper.getByRole('button'))
42
42
  expect(client.query).toHaveBeenCalledWith('foo')
43
43
  })
44
44
  })
@@ -1,5 +1,5 @@
1
1
  import React from 'react'
2
- import { mount } from 'enzyme'
2
+ import { screen, render } from '@testing-library/react'
3
3
  import CozyProvider from './Provider'
4
4
 
5
5
  import Query from './Query'
@@ -34,17 +34,24 @@ describe('Query', () => {
34
34
 
35
35
  describe('lifecycle', () => {
36
36
  it('should fire a query fetch when mounted', () => {
37
- mount(<Query query={queryDef}>{() => null}</Query>, {
38
- context
39
- })
37
+ render(
38
+ <CozyProvider client={client}>
39
+ <Query query={queryDef}>{() => null}</Query>
40
+ </CozyProvider>,
41
+ {
42
+ context
43
+ }
44
+ )
40
45
  expect(observableQuery.fetch).toHaveBeenCalled()
41
46
  })
42
47
 
43
48
  it('should not fire a query fetch when mounted if enabled is set to false', () => {
44
- mount(
45
- <Query query={queryDef} enabled={false}>
46
- {() => null}
47
- </Query>,
49
+ render(
50
+ <CozyProvider client={client}>
51
+ <Query query={queryDef} enabled={false}>
52
+ {() => null}
53
+ </Query>
54
+ </CozyProvider>,
48
55
  {
49
56
  context
50
57
  }
@@ -56,10 +63,12 @@ describe('Query', () => {
56
63
  const queryState = { lastUpdate: Date.now() }
57
64
  client.getQueryFromState = jest.fn().mockReturnValue(queryState)
58
65
  const fetchPolicy = jest.fn().mockReturnValue(false)
59
- mount(
60
- <Query query={queryDef} as="allTodos" fetchPolicy={fetchPolicy}>
61
- {() => null}
62
- </Query>,
66
+ render(
67
+ <CozyProvider client={client}>
68
+ <Query query={queryDef} as="allTodos" fetchPolicy={fetchPolicy}>
69
+ {() => null}
70
+ </Query>
71
+ </CozyProvider>,
63
72
  { context }
64
73
  )
65
74
  expect(client.getQueryFromState).toHaveBeenCalledWith('allTodos')
@@ -72,7 +81,7 @@ describe('Query', () => {
72
81
  const store = assets.store
73
82
  const client = assets.client
74
83
  const spy = jest.spyOn(store, 'dispatch')
75
- mount(
84
+ render(
76
85
  <CozyProvider client={client}>
77
86
  <Query query={queryDef}>{() => null}</Query>
78
87
  </CozyProvider>
@@ -97,14 +106,14 @@ describe('Query', () => {
97
106
  })
98
107
 
99
108
  describe('data reactions', () => {
100
- let store, client, uut
109
+ let store, client
101
110
  beforeEach(async () => {
102
111
  const assets = createTestAssets()
103
112
  store = assets.store
104
113
  client = assets.client
105
114
  const noFetch = () => false
106
115
  await store.dispatch(initQuery('allTodos', queryDef(client)))
107
- uut = mount(
116
+ render(
108
117
  <CozyProvider client={client}>
109
118
  <Query fetchPolicy={noFetch} query={queryDef}>
110
119
  {({ data }) => (
@@ -120,11 +129,11 @@ describe('Query', () => {
120
129
  })
121
130
 
122
131
  it('should be refreshed when relevant results are updated', async () => {
123
- expect(uut.html()).not.toContain('Build stuff')
132
+ expect(screen.queryByText('Build stuff')).not.toBeInTheDocument()
124
133
  const response = queryResultFromData(TODOS)
125
134
  const action = receiveQueryResult('allTodos', response)
126
135
  await store.dispatch(action)
127
- expect(uut.html()).toContain('Build stuff')
136
+ expect(screen.queryByText('Build stuff')).toBeInTheDocument()
128
137
  })
129
138
 
130
139
  it('should refresh queries concerned by a REMOVE_REFERENCE_TO mutation', async () => {
@@ -166,7 +175,7 @@ describe('Query', () => {
166
175
 
167
176
  const setup = ({ children }) => {
168
177
  const noFetch = () => false
169
- mount(
178
+ render(
170
179
  <CozyProvider client={client}>
171
180
  <Query fetchPolicy={noFetch} query={queryDef}>
172
181
  {children}
@@ -239,7 +248,7 @@ describe('Query', () => {
239
248
 
240
249
  const noFetch = () => false
241
250
 
242
- mount(
251
+ render(
243
252
  <CozyProvider client={client}>
244
253
  <Query fetchPolicy={noFetch} query={queryDef} mutations={mutations}>
245
254
  {(result, mutations) => {
@@ -269,7 +278,7 @@ describe('Query', () => {
269
278
 
270
279
  const noFetch = () => false
271
280
 
272
- mount(
281
+ render(
273
282
  <CozyProvider client={client}>
274
283
  <Query fetchPolicy={noFetch} query={queryDef} mutations={mutations}>
275
284
  {(result, mutations) => {
@@ -2,14 +2,6 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
- var _enzyme = _interopRequireDefault(require("enzyme"));
6
-
7
- var _enzymeAdapterReact = _interopRequireDefault(require("enzyme-adapter-react-16"));
8
-
9
5
  var _whatwgFetch = _interopRequireDefault(require("whatwg-fetch"));
10
6
 
11
- global.fetch = _whatwgFetch.default;
12
-
13
- _enzyme.default.configure({
14
- adapter: new _enzymeAdapterReact.default()
15
- });
7
+ global.fetch = _whatwgFetch.default;
package/dist/hoc.spec.jsx CHANGED
@@ -1,6 +1,6 @@
1
1
  import React, { useState } from 'react'
2
2
  import { Provider as ReduxProvider } from 'react-redux'
3
- import { mount } from 'enzyme'
3
+ import { fireEvent, render, screen } from '@testing-library/react'
4
4
 
5
5
  import { withClient, queryConnect, queryConnectFlat } from './hoc'
6
6
  import { Q } from './queries/dsl'
@@ -12,17 +12,15 @@ import { setupClient } from './testing/utils'
12
12
 
13
13
  beforeEach(() => {
14
14
  jest.spyOn(logger, 'warn').mockImplementation(() => {})
15
+ Component.mockClear()
15
16
  })
16
17
 
17
18
  afterEach(() => {
18
19
  logger.warn.mockRestore()
19
20
  })
20
21
 
21
- class Component extends React.Component {
22
- render() {
23
- return <div />
24
- }
25
- }
22
+ const Component = jest.fn(() => <div>Component</div>)
23
+ Component.displayName = 'Component'
26
24
 
27
25
  describe('with client', () => {
28
26
  it('should give a display name', () => {
@@ -38,12 +36,13 @@ describe('with client', () => {
38
36
  getState: jest.fn()
39
37
  }
40
38
  const WithClientComponent = withClient(Component)
41
- const uut = mount(
39
+ render(
42
40
  <Provider client={client} store={store}>
43
41
  <WithClientComponent />
44
42
  </Provider>
45
43
  )
46
- expect(uut.find(Component).prop('client')).toBe(client)
44
+
45
+ expect(Component).toHaveBeenCalledWith({ client }, {})
47
46
  })
48
47
  })
49
48
 
@@ -75,19 +74,23 @@ describe('queryConnect', () => {
75
74
  const context = {
76
75
  client
77
76
  }
78
- const uut = mount(<WithQueries />, { context })
79
- expect(
80
- uut
81
- .find(Component)
82
- .prop('simpsons')
83
- .data.map(x => x.name)
84
- ).toEqual(['Homer', 'Marge'])
85
- expect(
86
- uut
87
- .find(Component)
88
- .prop('upperSimpsons')
89
- .data.map(x => x.name)
90
- ).toEqual(['HOMER', 'MARGE'])
77
+ render(
78
+ <Provider client={client}>
79
+ <WithQueries />
80
+ </Provider>,
81
+ { context }
82
+ )
83
+
84
+ const propsPassedToComponent = Component.mock.calls[0][0]
85
+
86
+ expect(propsPassedToComponent.simpsons.data.map(x => x.name)).toEqual([
87
+ 'Homer',
88
+ 'Marge'
89
+ ])
90
+ expect(propsPassedToComponent.upperSimpsons.data.map(x => x.name)).toEqual([
91
+ 'HOMER',
92
+ 'MARGE'
93
+ ])
91
94
  })
92
95
 
93
96
  it('should be possible to pass props', () => {
@@ -109,20 +112,23 @@ describe('queryConnect', () => {
109
112
  </Provider>
110
113
  )
111
114
  }
112
- const uut = mount(<Wrapper client={client} />)
113
- const props = uut.find('Query').props()
114
- expect(props.query).toEqual(
115
+
116
+ render(<Wrapper client={client} />)
117
+
118
+ expect(Component).toHaveBeenCalledWith(
115
119
  expect.objectContaining({
116
- id: 'marge'
117
- })
120
+ simpsonId: 'marge'
121
+ }),
122
+ {}
118
123
  )
119
- uut.find('button').simulate('click')
120
- uut.update()
121
- const props2 = uut.find('Query').props()
122
- expect(props2.query).toEqual(
124
+
125
+ fireEvent.click(screen.getByText('change to homer'))
126
+
127
+ expect(Component).toHaveBeenCalledWith(
123
128
  expect.objectContaining({
124
- id: 'homer'
125
- })
129
+ simpsonId: 'homer'
130
+ }),
131
+ {}
126
132
  )
127
133
  })
128
134
  })
@@ -144,38 +150,22 @@ describe('queryConnectFlat', () => {
144
150
 
145
151
  it('should pass result of query definitions as props', () => {
146
152
  const { WithQueries, client } = setup()
147
- const uut = mount(
153
+ render(
148
154
  <ReduxProvider store={client.store}>
149
155
  <Provider client={client}>
150
156
  <WithQueries />
151
157
  </Provider>
152
158
  </ReduxProvider>
153
159
  )
154
- expect(
155
- uut
156
- .find(Component)
157
- .prop('simpsons')
158
- .data.map(x => x.name)
159
- ).toEqual(['Homer', 'Marge'])
160
- expect(
161
- uut
162
- .find(Component)
163
- .prop('upperSimpsons')
164
- .data.map(x => x.name)
165
- ).toEqual(['HOMER', 'MARGE'])
166
- })
160
+ const propsPassedToComponent = Component.mock.calls[0][0]
167
161
 
168
- it('should have Component as direct children of queryConnectFlag', () => {
169
- const { WithQueries, client } = setup()
170
- const uut = mount(
171
- <ReduxProvider store={client.store}>
172
- <Provider client={client}>
173
- <WithQueries />
174
- </Provider>
175
- </ReduxProvider>
176
- )
177
- const queryConnectFlatComponent = uut.find('queryConnectFlat(Component)')
178
- expect(queryConnectFlatComponent.length).toBe(1)
179
- expect(queryConnectFlatComponent.children().is('Component')).toBe(true)
162
+ expect(propsPassedToComponent.simpsons.data.map(x => x.name)).toEqual([
163
+ 'Homer',
164
+ 'Marge'
165
+ ])
166
+ expect(propsPassedToComponent.upperSimpsons.data.map(x => x.name)).toEqual([
167
+ 'HOMER',
168
+ 'MARGE'
169
+ ])
180
170
  })
181
171
  })
@@ -1,7 +1,7 @@
1
1
  import React from 'react'
2
2
  import useClient from './useClient'
3
3
  import Provider from '../Provider'
4
- import { mount } from 'enzyme'
4
+ import { screen, render } from '@testing-library/react'
5
5
 
6
6
  describe('useClient', () => {
7
7
  const Component = () => {
@@ -10,11 +10,12 @@ describe('useClient', () => {
10
10
  }
11
11
  it('should get the client from the nearest Provider', () => {
12
12
  const client = { stackClient: { uri: 'https://test.mycozy.cloud' } }
13
- const root = mount(
13
+ render(
14
14
  <Provider client={client}>
15
15
  <Component />
16
16
  </Provider>
17
17
  )
18
- expect(root.html()).toBe('<div>https://test.mycozy.cloud</div>')
18
+
19
+ screen.getByText('https://test.mycozy.cloud')
19
20
  })
20
21
  })
@@ -1,9 +1,10 @@
1
1
  import React from 'react'
2
- import { shallow } from 'enzyme'
2
+ import { fireEvent, render } from '@testing-library/react'
3
3
 
4
4
  import CozyClient from './CozyClient'
5
5
  import CozyLink from './CozyLink'
6
6
  import withMutation from './withMutation'
7
+ import Provider from './Provider'
7
8
 
8
9
  describe('withMutation', () => {
9
10
  const NEW_TODO = {
@@ -25,11 +26,12 @@ describe('withMutation', () => {
25
26
  )
26
27
  const ConnectedAddButton = withMutation(mutationCreator)(AddButton)
27
28
 
28
- const wrapper = shallow(<ConnectedAddButton />, { context: { client } })
29
- wrapper
30
- .dive()
31
- .find('button')
32
- .simulate('click')
29
+ const wrapper = render(
30
+ <Provider client={client}>
31
+ <ConnectedAddButton />
32
+ </Provider>
33
+ )
34
+ fireEvent.click(wrapper.getByRole('button'))
33
35
 
34
36
  expect(mutationCreator).toHaveBeenCalledWith(NEW_TODO)
35
37
  })
@@ -42,11 +44,12 @@ describe('withMutation', () => {
42
44
  name: 'addTodo'
43
45
  })(AddButton)
44
46
 
45
- const wrapper = shallow(<ConnectedAddButton />, { context: { client } })
46
- wrapper
47
- .dive()
48
- .find('button')
49
- .simulate('click')
47
+ const wrapper = render(
48
+ <Provider client={client}>
49
+ <ConnectedAddButton />
50
+ </Provider>
51
+ )
52
+ fireEvent.click(wrapper.getByRole('button'))
50
53
 
51
54
  expect(mutationCreator).toHaveBeenCalledWith(NEW_TODO)
52
55
  })
@@ -1,7 +1,8 @@
1
1
  import React from 'react'
2
- import { shallow } from 'enzyme'
2
+ import { render } from '@testing-library/react'
3
3
 
4
4
  import withMutations from './withMutations'
5
+ import Provider from './Provider'
5
6
 
6
7
  describe('withMutations', () => {
7
8
  beforeEach(() => {
@@ -49,21 +50,29 @@ describe('withMutations', () => {
49
50
 
50
51
  expect(() => {
51
52
  const ConnectedFoo = withMutations(mutationsMock)(Foo)
52
- shallow(<ConnectedFoo />, {
53
- context: { client: clientMock }
54
- })
53
+ render(
54
+ <Provider client={clientMock}>
55
+ <ConnectedFoo />
56
+ </Provider>
57
+ )
55
58
  }).not.toThrowError()
56
59
  })
57
60
 
58
61
  it('should inject base mutations props into wrapped component', async () => {
59
- const Foo = () => <div />
62
+ const Foo = jest.fn(() => <div>Component</div>)
60
63
  const ConnectedFoo = withMutations()(Foo)
61
64
 
62
- const wrapper = shallow(<ConnectedFoo />, {
63
- context: { client: clientMock }
64
- })
65
+ render(
66
+ <Provider client={clientMock}>
67
+ <ConnectedFoo />
68
+ </Provider>
69
+ )
65
70
 
66
- const { createDocument, saveDocument, deleteDocument } = wrapper.props()
71
+ const {
72
+ createDocument,
73
+ saveDocument,
74
+ deleteDocument
75
+ } = Foo.mock.calls[0][0]
67
76
 
68
77
  expect(typeof createDocument).toBe('function')
69
78
  expect(typeof saveDocument).toBe('function')
@@ -71,17 +80,18 @@ describe('withMutations', () => {
71
80
  })
72
81
 
73
82
  it('should inject mutations props from one source into wrapped component', async () => {
74
- const Foo = () => <div />
75
-
83
+ const Foo = jest.fn(() => <div>Component</div>)
76
84
  const ConnectedFoo = withMutations(client => ({
77
85
  mutate: client => client.mutate()
78
86
  }))(Foo)
79
87
 
80
- const wrapper = shallow(<ConnectedFoo />, {
81
- context: { client: clientMock }
82
- })
88
+ render(
89
+ <Provider client={clientMock}>
90
+ <ConnectedFoo />
91
+ </Provider>
92
+ )
83
93
 
84
- const { mutate } = wrapper.props()
94
+ const { mutate } = Foo.mock.calls[0][0]
85
95
  expect(typeof mutate).toBe('function')
86
96
 
87
97
  mutate(clientMock)
@@ -89,8 +99,7 @@ describe('withMutations', () => {
89
99
  })
90
100
 
91
101
  it('should inject mutations props from several sources into wrapped component', async () => {
92
- const Foo = () => <div />
93
-
102
+ const Foo = jest.fn(() => <div>Component</div>)
94
103
  const mutations = client => ({
95
104
  mutate: client => client.mutate()
96
105
  })
@@ -101,11 +110,13 @@ describe('withMutations', () => {
101
110
 
102
111
  const ConnectedFoo = withMutations(mutations, anotherMutations)(Foo)
103
112
 
104
- const wrapper = shallow(<ConnectedFoo />, {
105
- context: { client: clientMock }
106
- })
113
+ render(
114
+ <Provider client={clientMock}>
115
+ <ConnectedFoo />
116
+ </Provider>
117
+ )
107
118
 
108
- const { mutate, mutateAsWell } = wrapper.props()
119
+ const { mutate, mutateAsWell } = Foo.mock.calls[0][0]
109
120
 
110
121
  expect(typeof mutate).toBe('function')
111
122
  expect(typeof mutateAsWell).toBe('function')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "51.3.0",
3
+ "version": "51.3.1",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.node.js",
6
6
  "browser": "dist/index.js",
@@ -43,8 +43,9 @@
43
43
  "devDependencies": {
44
44
  "@babel/cli": "7.12.8",
45
45
  "@cozy/codemods": "1.14.4",
46
- "@testing-library/react": "10.4.9",
47
- "@testing-library/react-hooks": "3.7.0",
46
+ "@testing-library/jest-dom": "6.6.3",
47
+ "@testing-library/react": "12.1.5",
48
+ "@testing-library/react-hooks": "7.0.2",
48
49
  "babel-plugin-search-and-replace": "1.1.1",
49
50
  "btoa": "1.2.1",
50
51
  "cozy-device-helper": "2.7.0",
@@ -71,5 +72,5 @@
71
72
  "react-native-ios11-devicecheck": "https://github.com/cozy/react-native-devicecheck#app-attest-v0.1"
72
73
  },
73
74
  "sideEffects": false,
74
- "gitHead": "d405ae287ab4514a2d0ff95be712882e28bcfeae"
75
+ "gitHead": "981417637c34a36880eb4d7f1e4c12598e961212"
75
76
  }