cozy-harvest-lib 37.0.21 → 37.0.25

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 (27) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/components/AccountField.spec.js +141 -0
  3. package/dist/components/AccountFields.spec.js +39 -0
  4. package/dist/components/AccountForm/__snapshots__/index.spec.jsx.snap +203 -0
  5. package/dist/components/AccountsList/__snapshots__/AccountsList.spec.js.snap +87 -0
  6. package/dist/components/AccountsList/__snapshots__/AccountsListItem.spec.jsx.snap +63 -0
  7. package/dist/components/FlowProvider.spec.js +141 -0
  8. package/dist/components/KonnectorConfiguration/DataTab.spec.js +137 -0
  9. package/dist/components/KonnectorConfiguration/KonnectorAccountTabs.js +208 -0
  10. package/dist/components/KonnectorConfiguration/KonnectorAccountTabs.spec.js +335 -0
  11. package/dist/components/Maintenance/__snapshots__/index.spec.jsx.snap +3 -0
  12. package/dist/components/MountPointContext.js +81 -0
  13. package/dist/components/Routes/RoutesV4.js +83 -0
  14. package/dist/components/Routes/RoutesV6.js +92 -0
  15. package/dist/components/Routes.js +134 -0
  16. package/dist/components/__snapshots__/AccountField.spec.js.snap +365 -0
  17. package/dist/components/__snapshots__/AccountFields.spec.js.snap +39 -0
  18. package/dist/components/__snapshots__/AccountModal.spec.jsx.snap +174 -0
  19. package/dist/components/__snapshots__/KonnectorAccounts.spec.jsx.snap +20 -0
  20. package/dist/components/__snapshots__/KonnectorSuccess.spec.js.snap +26 -0
  21. package/dist/components/__snapshots__/Popup.spec.js.snap +3 -0
  22. package/dist/components/cards/LaunchTriggerCard.spec.js +152 -0
  23. package/dist/components/cards/__snapshots__/LaunchTriggerCard.spec.jsx.snap +5 -0
  24. package/dist/components/hoc/withRouter.js +75 -0
  25. package/dist/components/hoc/withRouter.spec.js +85 -0
  26. package/dist/sentry.js +20 -0
  27. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [37.0.25](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@37.0.24...cozy-harvest-lib@37.0.25) (2026-05-22)
7
+
8
+ **Note:** Version bump only for package cozy-harvest-lib
9
+
10
+ ## [37.0.24](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@37.0.23...cozy-harvest-lib@37.0.24) (2026-05-21)
11
+
12
+ **Note:** Version bump only for package cozy-harvest-lib
13
+
14
+ ## [37.0.23](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@37.0.22...cozy-harvest-lib@37.0.23) (2026-05-21)
15
+
16
+ **Note:** Version bump only for package cozy-harvest-lib
17
+
18
+ ## [37.0.22](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@37.0.21...cozy-harvest-lib@37.0.22) (2026-05-19)
19
+
20
+ **Note:** Version bump only for package cozy-harvest-lib
21
+
6
22
  ## [37.0.21](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@37.0.20...cozy-harvest-lib@37.0.21) (2026-05-18)
7
23
 
8
24
  **Note:** Version bump only for package cozy-harvest-lib
@@ -0,0 +1,141 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
+ import _inherits from "@babel/runtime/helpers/inherits";
5
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
+ import _extends from "@babel/runtime/helpers/extends";
8
+
9
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
10
+
11
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
12
+
13
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
14
+
15
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
16
+
17
+ import { AccountField } from 'components/AccountForm/AccountField';
18
+ import { shallow } from 'enzyme';
19
+ import PropTypes from 'prop-types';
20
+ import React from 'react';
21
+ var fixtures = {
22
+ username: {
23
+ encrypted: false,
24
+ required: true,
25
+ type: 'text'
26
+ },
27
+ passphrase: {
28
+ encrypted: true,
29
+ required: true,
30
+ type: 'password'
31
+ }
32
+ };
33
+ var t = jest.fn();
34
+ describe('AccountField', function () {
35
+ beforeEach(function () {
36
+ t.mockClear();
37
+ t.mockImplementation(function (key) {
38
+ return key;
39
+ });
40
+ });
41
+ it('should render', function () {
42
+ var wrapper = shallow( /*#__PURE__*/React.createElement(AccountField, _extends({}, fixtures.username, {
43
+ name: "username",
44
+ t: t
45
+ })));
46
+ var component = wrapper.dive().getElement();
47
+ expect(component).toMatchSnapshot();
48
+ });
49
+ it('render a date field', function () {
50
+ var wrapper = shallow( /*#__PURE__*/React.createElement(AccountField, {
51
+ required: true,
52
+ type: "date",
53
+ name: "date",
54
+ t: t
55
+ }));
56
+ var component = wrapper.dive().getElement();
57
+ expect(component).toMatchSnapshot();
58
+ });
59
+ it('render a password field', function () {
60
+ var wrapper = shallow( /*#__PURE__*/React.createElement(AccountField, _extends({}, fixtures.passphrase, {
61
+ name: "passphrase",
62
+ t: t
63
+ })));
64
+ var component = wrapper.dive().getElement();
65
+ expect(component).toMatchSnapshot();
66
+ });
67
+ it('hide the password toggle on empty fields', function () {
68
+ var wrapper = shallow( /*#__PURE__*/React.createElement(AccountField, _extends({}, fixtures.passphrase, {
69
+ name: "passphrase",
70
+ t: t,
71
+ value: ""
72
+ })));
73
+ var component = wrapper.dive().dive();
74
+ expect(component.prop('side')).toBe(null);
75
+ });
76
+ it('show the password toggle on non-empty fields', function () {
77
+ var wrapper = shallow( /*#__PURE__*/React.createElement(AccountField, _extends({}, fixtures.passphrase, {
78
+ name: "passphrase",
79
+ value: "123",
80
+ t: t
81
+ })));
82
+ var component = wrapper.dive().dive();
83
+ expect(component.prop('side')).not.toBe(null);
84
+ });
85
+ it('render a dropdown field', function () {
86
+ var options = [{
87
+ label: 'Option 1',
88
+ value: 'option1'
89
+ }, {
90
+ label: 'Option 2',
91
+ value: 'option2'
92
+ }];
93
+ var wrapper = shallow( /*#__PURE__*/React.createElement(AccountField, {
94
+ name: "multiple",
95
+ options: options,
96
+ required: true,
97
+ t: t,
98
+ type: "dropdown"
99
+ }));
100
+ var component = wrapper.dive().getElement();
101
+ expect(component).toMatchSnapshot();
102
+ });
103
+ it('uses predefined label', function () {
104
+ var wrapper = shallow( /*#__PURE__*/React.createElement(AccountField, {
105
+ label: "login",
106
+ name: "username",
107
+ required: true,
108
+ type: "text",
109
+ t: t
110
+ }));
111
+ expect(wrapper.props().label).toBe('fields.login.label');
112
+ });
113
+ it('ignores invalid predefined label', function () {
114
+ // Avoid warning
115
+ var AccountFieldWithPermissiveLabel = /*#__PURE__*/function (_AccountField) {
116
+ _inherits(AccountFieldWithPermissiveLabel, _AccountField);
117
+
118
+ var _super = _createSuper(AccountFieldWithPermissiveLabel);
119
+
120
+ function AccountFieldWithPermissiveLabel() {
121
+ _classCallCheck(this, AccountFieldWithPermissiveLabel);
122
+
123
+ return _super.apply(this, arguments);
124
+ }
125
+
126
+ return _createClass(AccountFieldWithPermissiveLabel);
127
+ }(AccountField);
128
+
129
+ AccountFieldWithPermissiveLabel.propTypes = _objectSpread(_objectSpread({}, AccountField.propTypes), {}, {
130
+ label: PropTypes.string
131
+ });
132
+ var wrapper = shallow( /*#__PURE__*/React.createElement(AccountFieldWithPermissiveLabel, {
133
+ label: "foo",
134
+ name: "username",
135
+ required: true,
136
+ type: "text",
137
+ t: t
138
+ }));
139
+ expect(wrapper.props().label).toBe('fields.username.label');
140
+ });
141
+ });
@@ -0,0 +1,39 @@
1
+ import { AccountFields } from 'components/AccountForm/AccountFields';
2
+ import { shallow } from 'enzyme';
3
+ import React from 'react';
4
+ var fixtures = {
5
+ fields: {
6
+ username: {
7
+ type: 'text'
8
+ },
9
+ passphrase: {
10
+ type: 'password'
11
+ }
12
+ },
13
+ sanitized: {
14
+ username: {
15
+ encrypted: false,
16
+ required: true,
17
+ type: 'text'
18
+ },
19
+ passphrase: {
20
+ encrypted: true,
21
+ required: true,
22
+ type: 'password'
23
+ }
24
+ }
25
+ };
26
+ describe('AccountFields', function () {
27
+ it('should render', function () {
28
+ var component = shallow( /*#__PURE__*/React.createElement(AccountFields, {
29
+ fields: fixtures.fields
30
+ })).getElement();
31
+ expect(component).toMatchSnapshot();
32
+ });
33
+ it('should render encrypted fields with placeholder', function () {
34
+ var component = shallow( /*#__PURE__*/React.createElement(AccountFields, {
35
+ fields: fixtures.sanitized
36
+ })).getElement();
37
+ expect(component).toMatchSnapshot();
38
+ });
39
+ });
@@ -0,0 +1,203 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`AccountForm should not render error 1`] = `
4
+ <div
5
+ onFocusCapture={[Function]}
6
+ onKeyUp={[Function]}
7
+ >
8
+ <React.Fragment>
9
+ <AccountFields
10
+ fields={
11
+ Object {
12
+ "passphrase": Object {
13
+ "encrypted": true,
14
+ "required": true,
15
+ "type": "password",
16
+ },
17
+ "username": Object {
18
+ "encrypted": false,
19
+ "required": true,
20
+ "role": "identifier",
21
+ "type": "text",
22
+ },
23
+ }
24
+ }
25
+ hasError={false}
26
+ initialValues={Object {}}
27
+ inputRefByName={[Function]}
28
+ t={[Function]}
29
+ />
30
+ <ForwardRef
31
+ busy={false}
32
+ className="u-mt-2 u-mb-1-half"
33
+ data-testid="submit-btn"
34
+ disabled={false}
35
+ fullWidth={true}
36
+ height="default"
37
+ label="Connect"
38
+ onClick={[Function]}
39
+ variant="primary"
40
+ />
41
+ </React.Fragment>
42
+ </div>
43
+ `;
44
+
45
+ exports[`AccountForm should render 1`] = `
46
+ <div
47
+ onFocusCapture={[Function]}
48
+ onKeyUp={[Function]}
49
+ >
50
+ <React.Fragment>
51
+ <AccountFields
52
+ fields={
53
+ Object {
54
+ "passphrase": Object {
55
+ "encrypted": true,
56
+ "required": true,
57
+ "type": "password",
58
+ },
59
+ "username": Object {
60
+ "encrypted": false,
61
+ "required": true,
62
+ "role": "identifier",
63
+ "type": "text",
64
+ },
65
+ }
66
+ }
67
+ initialValues={Object {}}
68
+ inputRefByName={[Function]}
69
+ t={[Function]}
70
+ />
71
+ <ForwardRef
72
+ busy={false}
73
+ className="u-mt-2 u-mb-1-half"
74
+ data-testid="submit-btn"
75
+ disabled={true}
76
+ fullWidth={true}
77
+ height="default"
78
+ label="Connect"
79
+ onClick={[Function]}
80
+ variant="primary"
81
+ />
82
+ </React.Fragment>
83
+ </div>
84
+ `;
85
+
86
+ exports[`AccountForm should render error 1`] = `
87
+ <div
88
+ onFocusCapture={[Function]}
89
+ onKeyUp={[Function]}
90
+ >
91
+ <ForwardRef
92
+ className="u-mb-1"
93
+ error={[Error: Test error]}
94
+ konnector={
95
+ Object {
96
+ "fields": Object {
97
+ "passphrase": Object {
98
+ "type": "password",
99
+ },
100
+ "username": Object {
101
+ "type": "text",
102
+ },
103
+ },
104
+ }
105
+ }
106
+ />
107
+ <React.Fragment>
108
+ <AccountFields
109
+ fields={
110
+ Object {
111
+ "passphrase": Object {
112
+ "encrypted": true,
113
+ "required": true,
114
+ "type": "password",
115
+ },
116
+ "username": Object {
117
+ "encrypted": false,
118
+ "required": true,
119
+ "role": "identifier",
120
+ "type": "text",
121
+ },
122
+ }
123
+ }
124
+ hasError={false}
125
+ initialValues={Object {}}
126
+ inputRefByName={[Function]}
127
+ t={[Function]}
128
+ />
129
+ <ForwardRef
130
+ busy={false}
131
+ className="u-mt-2 u-mb-1-half"
132
+ data-testid="submit-btn"
133
+ disabled={false}
134
+ fullWidth={true}
135
+ height="default"
136
+ label="Connect"
137
+ onClick={[Function]}
138
+ variant="primary"
139
+ />
140
+ </React.Fragment>
141
+ </div>
142
+ `;
143
+
144
+ exports[`AccountForm should render normally when client side konnector with launcher 1`] = `
145
+ <div
146
+ onFocusCapture={[Function]}
147
+ onKeyUp={[Function]}
148
+ >
149
+ <React.Fragment>
150
+ <AccountFields
151
+ fields={Object {}}
152
+ initialValues={Object {}}
153
+ inputRefByName={[Function]}
154
+ t={[Function]}
155
+ />
156
+ <ConnectCard
157
+ buttonProps={
158
+ Object {
159
+ "busy": false,
160
+ "data-testid": "submit-btn",
161
+ "disabled": false,
162
+ "label": "Connect",
163
+ "onClick": [Function],
164
+ }
165
+ }
166
+ description="Connect testkonnector to your Twake to synchronize your account and retrieve all your data. "
167
+ title="Connect to your Twake"
168
+ />
169
+ </React.Fragment>
170
+ </div>
171
+ `;
172
+
173
+ exports[`AccountForm should render with specific message when client side konnector without launcher 1`] = `
174
+ <div
175
+ onFocusCapture={[Function]}
176
+ onKeyUp={[Function]}
177
+ >
178
+ <React.Fragment>
179
+ <Media
180
+ align="top"
181
+ >
182
+ <Img
183
+ className="u-m-1"
184
+ >
185
+ <Icon
186
+ icon={[Function]}
187
+ spin={false}
188
+ />
189
+ </Img>
190
+ <Bd
191
+ className="u-m-1"
192
+ >
193
+ <ForwardRef>
194
+ To synchronize your testkonnector data in your Twake you must use the Twake app on your phone or tablet.
195
+ </ForwardRef>
196
+ </Bd>
197
+ </Media>
198
+ <InstallFlagshipButton
199
+ className="u-mt-2 u-mb-1-half"
200
+ />
201
+ </React.Fragment>
202
+ </div>
203
+ `;
@@ -0,0 +1,87 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`AccountsList should render 1`] = `
4
+ <ForwardRef(DialogContent)
5
+ className="u-pb-2 u-pt-0 u-ph-0"
6
+ classes={
7
+ Object {
8
+ "dividers": "MuiDialogContent-dividers",
9
+ "root": "MuiDialogContent-root",
10
+ }
11
+ }
12
+ >
13
+ <ul
14
+ className="u-nolist u-p-0 u-m-0"
15
+ >
16
+ <li
17
+ className="u-mb-half"
18
+ >
19
+ <AccountsListItem
20
+ account={
21
+ Object {
22
+ "_id": "account-1",
23
+ }
24
+ }
25
+ konnector={
26
+ Object {
27
+ "name": "test-konnector",
28
+ "vendor_link": "test konnector link",
29
+ }
30
+ }
31
+ onClick={[Function]}
32
+ trigger={
33
+ Object {
34
+ "_id": "trigger-1",
35
+ }
36
+ }
37
+ />
38
+ </li>
39
+ <li
40
+ className="u-mb-half"
41
+ >
42
+ <AccountsListItem
43
+ account={
44
+ Object {
45
+ "_id": "account-2",
46
+ }
47
+ }
48
+ konnector={
49
+ Object {
50
+ "name": "test-konnector",
51
+ "vendor_link": "test konnector link",
52
+ }
53
+ }
54
+ onClick={[Function]}
55
+ trigger={
56
+ Object {
57
+ "_id": "trigger-2",
58
+ }
59
+ }
60
+ />
61
+ </li>
62
+ <li
63
+ className="u-mb-half"
64
+ >
65
+ <Card
66
+ className="u-p-0"
67
+ tag="div"
68
+ >
69
+ <ForwardRef
70
+ className="u-bdrs-4"
71
+ fullWidth={true}
72
+ height="default"
73
+ icon={
74
+ <Icon
75
+ icon={[Function]}
76
+ spin={false}
77
+ />
78
+ }
79
+ label="modal.addAccount.button"
80
+ onClick={[MockFunction]}
81
+ variant="text"
82
+ />
83
+ </Card>
84
+ </li>
85
+ </ul>
86
+ </ForwardRef(DialogContent)>
87
+ `;
@@ -0,0 +1,63 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`AccountsListItem should not render the caption since accountLogin is undefined 1`] = `
4
+ <div
5
+ className="styles__c-card___YgP7B u-flex u-flex-justify-between u-flex-items-center u-c-pointer u-maw-100"
6
+ onClick={[MockFunction]}
7
+ >
8
+ <div
9
+ className="u-flex-grow-1 u-flex-shrink-1 u-ov-hidden u-mr-1"
10
+ >
11
+ <ForwardRef
12
+ className="u-ellipsis"
13
+ variant="body1"
14
+ >
15
+ account-1
16
+ </ForwardRef>
17
+ </div>
18
+ <ForwardRef
19
+ konnector={
20
+ Object {
21
+ "name": "test-konnector",
22
+ "vendor_link": "test konnector link",
23
+ }
24
+ }
25
+ trigger={Object {}}
26
+ />
27
+ </div>
28
+ `;
29
+
30
+ exports[`AccountsListItem should render the caption since accountName !== login 1`] = `
31
+ <div
32
+ className="styles__c-card___YgP7B u-flex u-flex-justify-between u-flex-items-center u-c-pointer u-maw-100"
33
+ onClick={[MockFunction]}
34
+ >
35
+ <div
36
+ className="u-flex-grow-1 u-flex-shrink-1 u-ov-hidden u-mr-1"
37
+ >
38
+ <ForwardRef
39
+ className="u-ellipsis"
40
+ gutterBottom={true}
41
+ variant="body1"
42
+ >
43
+ myAccountName
44
+ </ForwardRef>
45
+ <ForwardRef
46
+ className="u-ellipsis"
47
+ color="textSecondary"
48
+ variant="caption"
49
+ >
50
+ mylogin
51
+ </ForwardRef>
52
+ </div>
53
+ <ForwardRef
54
+ konnector={
55
+ Object {
56
+ "name": "test-konnector",
57
+ "vendor_link": "test konnector link",
58
+ }
59
+ }
60
+ trigger={Object {}}
61
+ />
62
+ </div>
63
+ `;
@@ -0,0 +1,141 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+
4
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
+
6
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
7
+
8
+ import { FlowProvider } from 'components/FlowProvider';
9
+ import TwoFAModal from 'components/TwoFAModal';
10
+ import { shallow } from 'enzyme';
11
+ import { ERROR_EVENT, SUCCESS_EVENT, LOGIN_SUCCESS_EVENT, TWO_FA_REQUEST_EVENT } from 'models/flowEvents';
12
+ import React from 'react';
13
+ var client = {
14
+ on: jest.fn(),
15
+ stackClient: {
16
+ uri: 'https://cozy.tools:8080'
17
+ },
18
+ plugins: {
19
+ realtime: {
20
+ subscribe: jest.fn(),
21
+ unsubscribe: jest.fn()
22
+ }
23
+ }
24
+ };
25
+ var trigger = {
26
+ _id: 'trigger-id',
27
+ current_state: {
28
+ last_executed_job_id: 'testjobid'
29
+ }
30
+ };
31
+ var triggersMutationsMock = {
32
+ fetchTrigger: jest.fn().mockResolvedValue(trigger),
33
+ createTrigger: jest.fn().mockResolvedValue(trigger),
34
+ createDocument: jest.fn(),
35
+ saveDocument: jest.fn(),
36
+ deleteDocument: jest.fn(),
37
+ createAccount: jest.fn(),
38
+ updateAccount: jest.fn(),
39
+ findAccount: jest.fn(),
40
+ deleteAccount: jest.fn(),
41
+ saveAccount: jest.fn(),
42
+ launchTrigger: jest.fn(),
43
+ watchKonnectorAccount: jest.fn(),
44
+ watchKonnectorJob: jest.fn()
45
+ };
46
+
47
+ var props = _objectSpread({
48
+ client: client,
49
+ initialTrigger: trigger,
50
+ konnector: {
51
+ slug: 'konnectorslug'
52
+ }
53
+ }, triggersMutationsMock);
54
+
55
+ describe('FlowProvider', function () {
56
+ // Chainable mock
57
+ var onMock = jest.fn(function () {
58
+ return {
59
+ on: onMock
60
+ };
61
+ });
62
+ afterEach(function () {
63
+ jest.clearAllMocks();
64
+ onMock.mockClear();
65
+ });
66
+ afterAll(function () {
67
+ jest.resetAllMocks();
68
+ });
69
+ it('should pass the konnector to the flow', function () {
70
+ var children = jest.fn();
71
+ var wrapper = shallow( /*#__PURE__*/React.createElement(FlowProvider, props, children));
72
+ var flow = wrapper.instance().flow;
73
+ expect(flow.konnector).toEqual(props.konnector);
74
+ });
75
+ it('should support a flow with a SUCCESS', function () {
76
+ var children = jest.fn();
77
+ var wrapper = shallow( /*#__PURE__*/React.createElement(FlowProvider, props, children));
78
+ var flow = wrapper.instance().flow;
79
+ expect(children.mock.calls[0][0].flow.getState().status).toEqual('IDLE');
80
+ flow.triggerEvent(TWO_FA_REQUEST_EVENT);
81
+ wrapper.update();
82
+ expect(wrapper.find(TwoFAModal).length).toBe(1);
83
+ flow.triggerEvent(SUCCESS_EVENT);
84
+ wrapper.update();
85
+ expect(wrapper.find(TwoFAModal).length).toBe(0);
86
+ expect(children.mock.calls[2][0].flow.getState().status).toEqual('SUCCESS');
87
+ expect(flow.listeners(SUCCESS_EVENT).length).toEqual(1);
88
+ expect(flow.listeners(ERROR_EVENT).length).toEqual(1);
89
+ });
90
+ it('should support a flow with a LOGIN_SUCCESS', function () {
91
+ var children = jest.fn();
92
+ var wrapper = shallow( /*#__PURE__*/React.createElement(FlowProvider, props, children));
93
+ var flow = wrapper.instance().flow;
94
+ flow.triggerEvent(TWO_FA_REQUEST_EVENT);
95
+ wrapper.update();
96
+ expect(wrapper.find(TwoFAModal).length).toBe(1);
97
+ flow.account = {
98
+ _id: 'fake-account-id'
99
+ };
100
+ flow.triggerEvent(LOGIN_SUCCESS_EVENT);
101
+ wrapper.update();
102
+ expect(wrapper.find(TwoFAModal).length).toBe(0);
103
+ expect(children.mock.calls[2][0].flow.getState().status).toEqual('LOGIN_SUCCESS');
104
+ expect(flow.listeners(SUCCESS_EVENT).length).toEqual(1);
105
+ expect(flow.listeners(ERROR_EVENT).length).toEqual(1);
106
+ });
107
+ it('should call the onLoginSuccess callback', function () {
108
+ var onLoginSuccess = jest.fn();
109
+ var wrapper = shallow( /*#__PURE__*/React.createElement(FlowProvider, _extends({}, props, {
110
+ onLoginSuccess: onLoginSuccess
111
+ }), jest.fn()));
112
+ var flow = wrapper.instance().flow;
113
+ flow.account = {
114
+ _id: 'account-id'
115
+ };
116
+ flow.triggerEvent(LOGIN_SUCCESS_EVENT);
117
+ expect(onLoginSuccess).toHaveBeenCalledWith(expect.objectContaining({
118
+ message: {
119
+ account: 'account-id',
120
+ konnector: 'konnectorslug'
121
+ }
122
+ }));
123
+ expect(flow.listeners(SUCCESS_EVENT).length).toEqual(1);
124
+ expect(flow.listeners(ERROR_EVENT).length).toEqual(1);
125
+ });
126
+ it('should detect an error in the initial trigger', function () {
127
+ var children = jest.fn();
128
+
129
+ var triggerWithExistingError = _objectSpread(_objectSpread({}, trigger), {}, {
130
+ current_state: {
131
+ status: 'errored',
132
+ last_error: 'Login failed'
133
+ }
134
+ });
135
+
136
+ shallow( /*#__PURE__*/React.createElement(FlowProvider, _extends({}, props, {
137
+ initialTrigger: triggerWithExistingError
138
+ }), children));
139
+ expect(children.mock.calls[0][0].flow.getState().error).not.toBe(null);
140
+ });
141
+ });