@shopgate/pwa-common 7.31.5 → 7.31.6
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.
- package/helpers/mocks/mockRenderOptions.js +21 -0
- package/package.json +3 -3
- package/action-creators/app/spec.js +0 -96
- package/action-creators/client/spec.js +0 -44
- package/action-creators/menu/spec.js +0 -37
- package/action-creators/modal/spec.js +0 -26
- package/action-creators/page/spec.js +0 -38
- package/action-creators/url/spec.js +0 -45
- package/action-creators/user/spec.js +0 -186
- package/components/Backdrop/spec.js +0 -24
- package/components/Button/spec.js +0 -42
- package/components/Checkbox/spec.js +0 -111
- package/components/CountdownTimer/spec.js +0 -141
- package/components/Drawer/spec.js +0 -79
- package/components/Ellipsis/spec.js +0 -15
- package/components/EmbeddedMedia/spec.js +0 -61
- package/components/Grid/components/Item/spec.js +0 -24
- package/components/Grid/spec.js +0 -24
- package/components/HtmlSanitizer/spec.js +0 -229
- package/components/I18n/components/FormatDate/spec.js +0 -54
- package/components/I18n/components/FormatNumber/spec.js +0 -51
- package/components/I18n/components/FormatPrice/spec.js +0 -54
- package/components/I18n/components/FormatTime/spec.js +0 -51
- package/components/I18n/components/I18nProvider/spec.js +0 -40
- package/components/I18n/components/Placeholder/spec.js +0 -37
- package/components/I18n/components/Translate/spec.js +0 -33
- package/components/InfiniteContainer/spec.js +0 -204
- package/components/Input/spec.js +0 -123
- package/components/Link/spec.js +0 -60
- package/components/List/spec.js +0 -26
- package/components/ModalContainer/spec.js +0 -115
- package/components/Select/spec.js +0 -122
- package/components/SelectBox/spec.js +0 -68
- package/components/Swiper/components/SwiperItem/spec.js +0 -26
- package/components/Widgets/components/Widget/spec.js +0 -75
- package/components/Widgets/components/WidgetGrid/spec.js +0 -53
- package/components/Widgets/spec.js +0 -234
- package/helpers/data/spec.js +0 -194
- package/helpers/date/spec.js +0 -92
- package/helpers/style/spec.js +0 -108
- package/helpers/validation/spec.js +0 -10
- package/providers/toast/spec.js +0 -105
- package/tsconfig.build.json +0 -16
- package/tsconfig.json +0 -3
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import { i18n } from '@shopgate/engage/core';
|
|
4
|
-
import I18n from "../../index";
|
|
5
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
|
-
jest.unmock('@shopgate/engage/core/helpers/i18n');
|
|
7
|
-
describe('<FormatDate />', () => {
|
|
8
|
-
const locales = {
|
|
9
|
-
greeting: 'Hello {date}'
|
|
10
|
-
};
|
|
11
|
-
const lang = 'en-US';
|
|
12
|
-
const timestamp = 123456789000;
|
|
13
|
-
const formattedDate = 'Nov 29, 1973';
|
|
14
|
-
const format = 'medium';
|
|
15
|
-
i18n.init({
|
|
16
|
-
locales,
|
|
17
|
-
lang
|
|
18
|
-
});
|
|
19
|
-
describe('Given the component was mounted to the DOM', () => {
|
|
20
|
-
let renderedElement;
|
|
21
|
-
it('should match snapshot', () => {
|
|
22
|
-
renderedElement = mount(/*#__PURE__*/_jsx(I18n.Provider, {
|
|
23
|
-
children: /*#__PURE__*/_jsxs("div", {
|
|
24
|
-
children: [/*#__PURE__*/_jsx("span", {
|
|
25
|
-
className: "only-date",
|
|
26
|
-
children: /*#__PURE__*/_jsx(I18n.Date, {
|
|
27
|
-
timestamp: timestamp,
|
|
28
|
-
format: format
|
|
29
|
-
})
|
|
30
|
-
}), /*#__PURE__*/_jsx("span", {
|
|
31
|
-
className: "text-with-date",
|
|
32
|
-
children: /*#__PURE__*/_jsx(I18n.Text, {
|
|
33
|
-
string: "greeting",
|
|
34
|
-
children: /*#__PURE__*/_jsx(I18n.Date, {
|
|
35
|
-
forKey: "date",
|
|
36
|
-
timestamp: timestamp,
|
|
37
|
-
format: format
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
})]
|
|
41
|
-
})
|
|
42
|
-
}));
|
|
43
|
-
expect(renderedElement).toMatchSnapshot();
|
|
44
|
-
});
|
|
45
|
-
it('should render formatted date', () => {
|
|
46
|
-
const text = renderedElement.find('.only-date').text();
|
|
47
|
-
expect(text).toBe(formattedDate);
|
|
48
|
-
});
|
|
49
|
-
it('should render within translated text', () => {
|
|
50
|
-
const text = renderedElement.find('.text-with-date').text();
|
|
51
|
-
expect(text).toBe(`Hello ${formattedDate}`);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
});
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import "core-js/modules/es.array.includes.js";
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { mount } from 'enzyme';
|
|
4
|
-
import { i18n } from '@shopgate/engage/core';
|
|
5
|
-
import I18n from "../../index";
|
|
6
|
-
import FormatNumber from "./index";
|
|
7
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
-
jest.unmock('@shopgate/engage/core/helpers/i18n');
|
|
9
|
-
describe('<FormatNumber>', () => {
|
|
10
|
-
describe('i18n not ready', () => {
|
|
11
|
-
it('should return same number and className when i18n is not ready', () => {
|
|
12
|
-
const component = mount(/*#__PURE__*/_jsx(FormatNumber, {
|
|
13
|
-
number: 1,
|
|
14
|
-
fractions: 2,
|
|
15
|
-
className: "some-class"
|
|
16
|
-
}));
|
|
17
|
-
expect(component.html().includes('some-class')).toBe(true);
|
|
18
|
-
expect(component.text().includes('1')).toBe(true);
|
|
19
|
-
expect(component).toMatchSnapshot();
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
describe('i18n ready', () => {
|
|
23
|
-
i18n.init({
|
|
24
|
-
locales: {},
|
|
25
|
-
lang: 'en-US'
|
|
26
|
-
});
|
|
27
|
-
const pairs = [[1, '1.00', 2], [0.1, '0.10', 2], [1, '1.000', 3], [1, '1', 0]];
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Makes a component.
|
|
31
|
-
* @param {number} number Number
|
|
32
|
-
* @param {number} fractions Decimal points.
|
|
33
|
-
* @returns {Object}
|
|
34
|
-
*/
|
|
35
|
-
const makeComponent = (number, fractions) => mount(/*#__PURE__*/_jsx(I18n.Provider, {
|
|
36
|
-
children: /*#__PURE__*/_jsx("div", {
|
|
37
|
-
children: /*#__PURE__*/_jsx(FormatNumber, {
|
|
38
|
-
number: number,
|
|
39
|
-
fractions: fractions
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
}));
|
|
43
|
-
pairs.forEach(([input, expexted, fractions]) => {
|
|
44
|
-
it(`should format ${input} into ${expexted}`, () => {
|
|
45
|
-
const component = makeComponent(input, fractions);
|
|
46
|
-
expect(component.text().includes(`${expexted}`)).toBe(true);
|
|
47
|
-
expect(component).toMatchSnapshot();
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import { i18n } from '@shopgate/engage/core';
|
|
4
|
-
import I18n from "../../index";
|
|
5
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
|
-
jest.unmock('@shopgate/engage/core/helpers/i18n');
|
|
7
|
-
describe('<FormatPrice />', () => {
|
|
8
|
-
const locales = {
|
|
9
|
-
greeting: 'Hello {price}'
|
|
10
|
-
};
|
|
11
|
-
const price = 1234.56;
|
|
12
|
-
const formattedPrice = '€1,234.56';
|
|
13
|
-
const currency = 'EUR';
|
|
14
|
-
const lang = 'en-US';
|
|
15
|
-
i18n.init({
|
|
16
|
-
locales,
|
|
17
|
-
lang
|
|
18
|
-
});
|
|
19
|
-
describe('Given the component was mounted to the DOM', () => {
|
|
20
|
-
let renderedElement;
|
|
21
|
-
it('should match snapshot', () => {
|
|
22
|
-
renderedElement = mount(/*#__PURE__*/_jsx(I18n.Provider, {
|
|
23
|
-
children: /*#__PURE__*/_jsxs("div", {
|
|
24
|
-
children: [/*#__PURE__*/_jsx("span", {
|
|
25
|
-
className: "only-price",
|
|
26
|
-
children: /*#__PURE__*/_jsx(I18n.Price, {
|
|
27
|
-
price: price,
|
|
28
|
-
currency: currency
|
|
29
|
-
})
|
|
30
|
-
}), /*#__PURE__*/_jsx("span", {
|
|
31
|
-
className: "text-with-price",
|
|
32
|
-
children: /*#__PURE__*/_jsx(I18n.Text, {
|
|
33
|
-
string: "greeting",
|
|
34
|
-
children: /*#__PURE__*/_jsx(I18n.Price, {
|
|
35
|
-
forKey: "price",
|
|
36
|
-
price: price,
|
|
37
|
-
currency: currency
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
})]
|
|
41
|
-
})
|
|
42
|
-
}));
|
|
43
|
-
expect(renderedElement).toMatchSnapshot();
|
|
44
|
-
});
|
|
45
|
-
it('should render formatted price', () => {
|
|
46
|
-
const text = renderedElement.find('.only-price').text();
|
|
47
|
-
expect(text).toBe(formattedPrice);
|
|
48
|
-
});
|
|
49
|
-
it('should render within translated text', () => {
|
|
50
|
-
const text = renderedElement.find('.text-with-price').text();
|
|
51
|
-
expect(text).toBe(`Hello ${formattedPrice}`);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
});
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import { i18n } from '@shopgate/engage/core';
|
|
4
|
-
import I18n from "../../index";
|
|
5
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
|
-
jest.unmock('@shopgate/engage/core/helpers/i18n');
|
|
7
|
-
describe('<FormatTime />', () => {
|
|
8
|
-
const locales = {
|
|
9
|
-
greeting: 'Hello {time}'
|
|
10
|
-
};
|
|
11
|
-
const timestamp = new Date('Dec 25, 1999 04:25:45').getTime();
|
|
12
|
-
const formattedTime = '4:25:45 AM';
|
|
13
|
-
const format = 'medium';
|
|
14
|
-
const lang = 'en-US';
|
|
15
|
-
i18n.init({
|
|
16
|
-
locales,
|
|
17
|
-
lang
|
|
18
|
-
});
|
|
19
|
-
describe('Given the component was mounted to the DOM', () => {
|
|
20
|
-
// TODO: Handle snapshot test.
|
|
21
|
-
const renderedElement = mount(/*#__PURE__*/_jsx(I18n.Provider, {
|
|
22
|
-
children: /*#__PURE__*/_jsxs("div", {
|
|
23
|
-
children: [/*#__PURE__*/_jsx("span", {
|
|
24
|
-
className: "only-time",
|
|
25
|
-
children: /*#__PURE__*/_jsx(I18n.Time, {
|
|
26
|
-
timestamp: timestamp,
|
|
27
|
-
format: format
|
|
28
|
-
})
|
|
29
|
-
}), /*#__PURE__*/_jsx("span", {
|
|
30
|
-
className: "text-with-time",
|
|
31
|
-
children: /*#__PURE__*/_jsx(I18n.Text, {
|
|
32
|
-
string: "greeting",
|
|
33
|
-
children: /*#__PURE__*/_jsx(I18n.Time, {
|
|
34
|
-
forKey: "time",
|
|
35
|
-
timestamp: timestamp,
|
|
36
|
-
format: format
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
})]
|
|
40
|
-
})
|
|
41
|
-
}));
|
|
42
|
-
it('should render formatted time', () => {
|
|
43
|
-
const text = renderedElement.find('.only-time').text();
|
|
44
|
-
expect(text).toBe(formattedTime);
|
|
45
|
-
});
|
|
46
|
-
it('should render within translated text', () => {
|
|
47
|
-
const text = renderedElement.find('.text-with-time').text();
|
|
48
|
-
expect(text).toBe(`Hello ${formattedTime}`);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { shallow } from 'enzyme';
|
|
3
|
-
import { i18n as i18nHelper } from '@shopgate/engage/core';
|
|
4
|
-
import I18nProvider from "./index";
|
|
5
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
-
jest.unmock('@shopgate/engage/core/helpers/i18n');
|
|
7
|
-
describe('<I18nProvider />', () => {
|
|
8
|
-
const locales = {
|
|
9
|
-
greeting: 'Guten Tag {name}'
|
|
10
|
-
};
|
|
11
|
-
const lang = 'de-DE';
|
|
12
|
-
i18nHelper.init({
|
|
13
|
-
locales,
|
|
14
|
-
lang
|
|
15
|
-
});
|
|
16
|
-
describe('Given the component was mounted to the DOM', () => {
|
|
17
|
-
let renderedElement;
|
|
18
|
-
let renderedInstance;
|
|
19
|
-
it('should match snapshot', () => {
|
|
20
|
-
renderedElement = shallow(/*#__PURE__*/_jsx(I18nProvider, {}));
|
|
21
|
-
renderedInstance = renderedElement.instance();
|
|
22
|
-
expect(renderedElement).toMatchSnapshot();
|
|
23
|
-
});
|
|
24
|
-
it('should provide access to i18n via context', () => {
|
|
25
|
-
const {
|
|
26
|
-
i18n
|
|
27
|
-
} = renderedInstance.getChildContext();
|
|
28
|
-
expect(i18n).toEqual(renderedInstance.getI18nInstance);
|
|
29
|
-
});
|
|
30
|
-
it('should translate when calling an instance method', () => {
|
|
31
|
-
const {
|
|
32
|
-
__
|
|
33
|
-
} = renderedInstance.getI18nInstance();
|
|
34
|
-
const translated = __('greeting', {
|
|
35
|
-
name: 'Test'
|
|
36
|
-
});
|
|
37
|
-
expect(translated).toBe('Guten Tag Test');
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import { i18n } from '@shopgate/engage/core';
|
|
4
|
-
import I18n from "../../index";
|
|
5
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
|
-
jest.unmock('@shopgate/engage/core/helpers/i18n');
|
|
7
|
-
describe('<Placeholder />', () => {
|
|
8
|
-
const locales = {
|
|
9
|
-
greeting: 'Hello {world}'
|
|
10
|
-
};
|
|
11
|
-
const lang = 'en-US';
|
|
12
|
-
i18n.init({
|
|
13
|
-
locales,
|
|
14
|
-
lang
|
|
15
|
-
});
|
|
16
|
-
describe('Given the component was mounted to the DOM', () => {
|
|
17
|
-
let renderedElement;
|
|
18
|
-
it('should render', () => {
|
|
19
|
-
renderedElement = mount(/*#__PURE__*/_jsx(I18n.Provider, {
|
|
20
|
-
children: /*#__PURE__*/_jsxs(I18n.Text, {
|
|
21
|
-
string: "greeting",
|
|
22
|
-
children: [/*#__PURE__*/_jsx(I18n.Placeholder, {
|
|
23
|
-
forKey: "world",
|
|
24
|
-
children: /*#__PURE__*/_jsx("strong", {
|
|
25
|
-
children: "WORLD"
|
|
26
|
-
})
|
|
27
|
-
}), "/"]
|
|
28
|
-
})
|
|
29
|
-
}));
|
|
30
|
-
expect(renderedElement).toMatchSnapshot();
|
|
31
|
-
});
|
|
32
|
-
it('should render with a placeholder text', () => {
|
|
33
|
-
const text = renderedElement.find('strong').text();
|
|
34
|
-
expect(text).toBe('WORLD');
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount } from 'enzyme';
|
|
3
|
-
import { i18n } from '@shopgate/engage/core';
|
|
4
|
-
import I18n from "../../index";
|
|
5
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
-
jest.unmock('@shopgate/engage/core/helpers/i18n');
|
|
7
|
-
describe('<Translate />', () => {
|
|
8
|
-
const locales = {
|
|
9
|
-
greeting: 'Hello {name}'
|
|
10
|
-
};
|
|
11
|
-
i18n.init({
|
|
12
|
-
locales,
|
|
13
|
-
lang: 'en-US'
|
|
14
|
-
});
|
|
15
|
-
describe('Given the component was mounted to the DOM', () => {
|
|
16
|
-
let renderedElement;
|
|
17
|
-
it('should match snapshot', () => {
|
|
18
|
-
renderedElement = mount(/*#__PURE__*/_jsx(I18n.Provider, {
|
|
19
|
-
children: /*#__PURE__*/_jsx(I18n.Text, {
|
|
20
|
-
string: "greeting",
|
|
21
|
-
params: {
|
|
22
|
-
name: 'Test'
|
|
23
|
-
}
|
|
24
|
-
})
|
|
25
|
-
}));
|
|
26
|
-
expect(renderedElement).toMatchSnapshot();
|
|
27
|
-
});
|
|
28
|
-
it('should render translated text', () => {
|
|
29
|
-
const text = renderedElement.find(I18n.Text).text();
|
|
30
|
-
expect(text).toBe('Hello Test');
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
});
|
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import range from 'lodash/range';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { shallow, mount } from 'enzyme';
|
|
4
|
-
import { ITEMS_PER_LOAD } from "../../constants/DisplayOptions";
|
|
5
|
-
import InfiniteContainer from "./index";
|
|
6
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
-
global.console.error = jest.fn();
|
|
8
|
-
const context = {
|
|
9
|
-
state: {}
|
|
10
|
-
};
|
|
11
|
-
describe('<InfiniteContainer />', () => {
|
|
12
|
-
let renderedElement;
|
|
13
|
-
let renderedInstance;
|
|
14
|
-
let mockLoader;
|
|
15
|
-
let MockIterator;
|
|
16
|
-
let mockItems;
|
|
17
|
-
const mockData = range(100).map(id => ({
|
|
18
|
-
id,
|
|
19
|
-
title: `Item ${id}`
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* The view component
|
|
24
|
-
* @param {Object} props The component props.
|
|
25
|
-
*/
|
|
26
|
-
const renderComponent = props => {
|
|
27
|
-
renderedElement = shallow(/*#__PURE__*/_jsx(InfiniteContainer, {
|
|
28
|
-
...props
|
|
29
|
-
}), {
|
|
30
|
-
context
|
|
31
|
-
});
|
|
32
|
-
renderedInstance = renderedElement.instance();
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Mocks the mapStateToProps connector.
|
|
37
|
-
* @param {number} amount The new product amount.
|
|
38
|
-
*/
|
|
39
|
-
const receiveItemsByProp = amount => {
|
|
40
|
-
mockItems = mockData.slice(0, amount);
|
|
41
|
-
const nextProps = {
|
|
42
|
-
...renderedInstance.props,
|
|
43
|
-
items: mockItems,
|
|
44
|
-
totalItems: mockData.length
|
|
45
|
-
};
|
|
46
|
-
renderedElement.setProps(nextProps);
|
|
47
|
-
};
|
|
48
|
-
beforeEach(() => {
|
|
49
|
-
mockLoader = jest.fn();
|
|
50
|
-
MockIterator = data => /*#__PURE__*/_jsx("li", {
|
|
51
|
-
children: data.title
|
|
52
|
-
}, data.id);
|
|
53
|
-
});
|
|
54
|
-
describe('Given the component was mounted to the DOM', () => {
|
|
55
|
-
beforeEach(() => {
|
|
56
|
-
renderComponent({
|
|
57
|
-
items: [],
|
|
58
|
-
loader: mockLoader,
|
|
59
|
-
iterator: MockIterator,
|
|
60
|
-
totalItems: null
|
|
61
|
-
});
|
|
62
|
-
renderedInstance.componentDidMount();
|
|
63
|
-
});
|
|
64
|
-
it('should match snapshot', () => {
|
|
65
|
-
expect(renderedElement).toMatchSnapshot();
|
|
66
|
-
});
|
|
67
|
-
it('should call the loader function', () => {
|
|
68
|
-
const [offset] = renderedInstance.state.offset;
|
|
69
|
-
expect(mockLoader).toBeCalledWith(offset);
|
|
70
|
-
});
|
|
71
|
-
describe('Given the loader requested new items', () => {
|
|
72
|
-
const mockItemsLength = 10;
|
|
73
|
-
beforeEach(() => {
|
|
74
|
-
receiveItemsByProp(mockItemsLength);
|
|
75
|
-
});
|
|
76
|
-
it('should render the loaded items', () => {
|
|
77
|
-
expect(renderedElement.find(MockIterator)).toHaveLength(mockItemsLength);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
describe('Given the component was mounted within a scroll container', () => {
|
|
81
|
-
const mockItemsLength = 11;
|
|
82
|
-
beforeEach(() => {
|
|
83
|
-
// Receive items from initial mounting before proceeding...
|
|
84
|
-
receiveItemsByProp(mockItemsLength);
|
|
85
|
-
|
|
86
|
-
// Reset any previous calls (e.g. from componentDidMount())
|
|
87
|
-
mockLoader.mock.calls = [];
|
|
88
|
-
renderedInstance.componentDidUpdate();
|
|
89
|
-
});
|
|
90
|
-
it('should call the loader function if scrolled to the bottom', () => {
|
|
91
|
-
renderedInstance.domScrollContainer = {
|
|
92
|
-
scrollTop: 900,
|
|
93
|
-
scrollHeight: 1000,
|
|
94
|
-
clientHeight: 100
|
|
95
|
-
};
|
|
96
|
-
renderedInstance.handleLoading();
|
|
97
|
-
expect(mockLoader).toBeCalled();
|
|
98
|
-
});
|
|
99
|
-
it('should not call the loader function if the scroll position did not change', () => {
|
|
100
|
-
renderedInstance.domScrollContainer = {
|
|
101
|
-
scrollTop: 0,
|
|
102
|
-
scrollHeight: 1000,
|
|
103
|
-
clientHeight: 100
|
|
104
|
-
};
|
|
105
|
-
renderedInstance.handleLoading();
|
|
106
|
-
expect(mockLoader.mock.calls.length).toBe(0);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
describe('Given all items have been received', () => {
|
|
110
|
-
const mockItemsLength = mockData.length;
|
|
111
|
-
beforeEach(() => {
|
|
112
|
-
receiveItemsByProp(mockItemsLength);
|
|
113
|
-
});
|
|
114
|
-
it('should expect no more items to be received', () => {
|
|
115
|
-
expect(renderedInstance.needsToReceiveItems()).toBe(false);
|
|
116
|
-
});
|
|
117
|
-
it('should keep state.awaitingItems as true if not all items are rendered', () => {
|
|
118
|
-
expect(renderedInstance.allItemsAreRendered()).toBe(false);
|
|
119
|
-
expect(renderedInstance.state.awaitingItems).toBe(true);
|
|
120
|
-
expect(renderedElement.find(MockIterator).length).toBeLessThan(mockItemsLength);
|
|
121
|
-
});
|
|
122
|
-
it('should set state.awaitingItems to false if all items are rendered', () => {
|
|
123
|
-
renderedElement.setState({
|
|
124
|
-
offset: [0, mockItemsLength]
|
|
125
|
-
});
|
|
126
|
-
renderedInstance.handleLoading();
|
|
127
|
-
expect(renderedInstance.allItemsAreRendered()).toBe(true);
|
|
128
|
-
expect(renderedInstance.state.awaitingItems).toBe(false);
|
|
129
|
-
expect(renderedElement.find(MockIterator).length).toBe(mockItemsLength);
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
describe('Given that the initialLimit is used in the correct ways', () => {
|
|
134
|
-
describe('Given that the initialLimit is used', () => {
|
|
135
|
-
it('should render with the initialLimit', () => {
|
|
136
|
-
renderComponent({
|
|
137
|
-
items: mockData,
|
|
138
|
-
loader: mockLoader,
|
|
139
|
-
iterator: MockIterator,
|
|
140
|
-
totalItems: mockData.length
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
// Check if the iniLimit was used
|
|
144
|
-
expect(renderedElement.find(MockIterator).length).toBe(renderedInstance.props.initialLimit);
|
|
145
|
-
|
|
146
|
-
// Reset the limit from props.initialLimit back to props.limit
|
|
147
|
-
renderedInstance.componentDidMount();
|
|
148
|
-
renderedInstance.handleLoading();
|
|
149
|
-
|
|
150
|
-
// Re-render with the new limit
|
|
151
|
-
renderedElement.update();
|
|
152
|
-
|
|
153
|
-
// Check if the correct limit was used for the second render
|
|
154
|
-
const newLimit = renderedInstance.props.initialLimit + renderedInstance.props.limit;
|
|
155
|
-
expect(renderedElement.find(MockIterator).length).toBe(newLimit);
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
describe('Given that the initialLimit is NOT used', () => {
|
|
159
|
-
it('should render without the initialLimit', () => {
|
|
160
|
-
renderComponent({
|
|
161
|
-
items: [],
|
|
162
|
-
loader: mockLoader,
|
|
163
|
-
iterator: MockIterator,
|
|
164
|
-
totalItems: null
|
|
165
|
-
});
|
|
166
|
-
renderedInstance.componentDidMount();
|
|
167
|
-
receiveItemsByProp(ITEMS_PER_LOAD);
|
|
168
|
-
|
|
169
|
-
// Check if the iniLimit wasn't used
|
|
170
|
-
expect(renderedElement).toMatchSnapshot();
|
|
171
|
-
expect(renderedElement.find(MockIterator).length).toBe(renderedInstance.props.limit);
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
describe('Given that the requestHash changes', () => {
|
|
176
|
-
it('should reset the component', () => {
|
|
177
|
-
const props = {
|
|
178
|
-
items: mockData,
|
|
179
|
-
loader: mockLoader,
|
|
180
|
-
iterator: MockIterator,
|
|
181
|
-
totalItems: mockData.length,
|
|
182
|
-
requestHash: 'default'
|
|
183
|
-
};
|
|
184
|
-
const wrapper = mount(/*#__PURE__*/_jsx(InfiniteContainer, {
|
|
185
|
-
...props
|
|
186
|
-
}));
|
|
187
|
-
const instance = wrapper.instance();
|
|
188
|
-
instance.componentDidMount();
|
|
189
|
-
instance.domScrollContainer = document.createElement('div');
|
|
190
|
-
wrapper.setState({
|
|
191
|
-
awaitingItems: false,
|
|
192
|
-
offset: [10, 10]
|
|
193
|
-
});
|
|
194
|
-
wrapper.setProps({
|
|
195
|
-
requestHash: 'price_desc'
|
|
196
|
-
});
|
|
197
|
-
expect(wrapper.state()).toEqual({
|
|
198
|
-
offset: [0, 32],
|
|
199
|
-
awaitingItems: true,
|
|
200
|
-
itemCount: 0
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
});
|
package/components/Input/spec.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { mount, shallow } from 'enzyme';
|
|
3
|
-
import Input from "./index";
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
describe('<Input />', () => {
|
|
6
|
-
it('should render a simple input field', () => {
|
|
7
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Input, {}));
|
|
8
|
-
expect(wrapper).toMatchSnapshot();
|
|
9
|
-
expect(wrapper.find('input').length).toBe(1);
|
|
10
|
-
});
|
|
11
|
-
it('should render the input as password', () => {
|
|
12
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Input, {
|
|
13
|
-
password: true
|
|
14
|
-
}));
|
|
15
|
-
expect(wrapper).toMatchSnapshot();
|
|
16
|
-
expect(wrapper.find('input[type="password"]').length).toBe(1);
|
|
17
|
-
});
|
|
18
|
-
it('should render the input with a default value', () => {
|
|
19
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Input, {
|
|
20
|
-
value: "FooBar"
|
|
21
|
-
}));
|
|
22
|
-
expect(wrapper).toMatchSnapshot();
|
|
23
|
-
expect(wrapper.find('input[value="FooBar"]').length).toBe(1);
|
|
24
|
-
});
|
|
25
|
-
it('should trigger the onChange callback', () => {
|
|
26
|
-
const onChangeMock = jest.fn();
|
|
27
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Input, {
|
|
28
|
-
onChange: onChangeMock
|
|
29
|
-
}));
|
|
30
|
-
wrapper.find('input').simulate('change', {
|
|
31
|
-
target: {
|
|
32
|
-
value: 'a'
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
expect(onChangeMock).toHaveBeenCalledTimes(2);
|
|
36
|
-
expect(wrapper.find('input').props().value).toEqual('a');
|
|
37
|
-
});
|
|
38
|
-
it('should receive the correct value while typing', () => {
|
|
39
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Input, {}));
|
|
40
|
-
const input = wrapper.find('input');
|
|
41
|
-
input.simulate('change', {
|
|
42
|
-
target: {
|
|
43
|
-
value: 'foobar'
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
expect(wrapper).toMatchSnapshot();
|
|
47
|
-
expect(wrapper.find('SimpleInput').instance().value).toBe('foobar');
|
|
48
|
-
});
|
|
49
|
-
it('should sanitize the input', () => {
|
|
50
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Input, {
|
|
51
|
-
onSanitize: value => value.toUpperCase()
|
|
52
|
-
}));
|
|
53
|
-
const input = wrapper.find('input');
|
|
54
|
-
input.simulate('change', {
|
|
55
|
-
target: {
|
|
56
|
-
value: 'foobar'
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
expect(wrapper).toMatchSnapshot();
|
|
60
|
-
expect(wrapper.find('SimpleInput').instance().value).toBe('FOOBAR');
|
|
61
|
-
});
|
|
62
|
-
it('should validate the input', () => {
|
|
63
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Input, {
|
|
64
|
-
onValidate: () => false
|
|
65
|
-
}));
|
|
66
|
-
expect(wrapper).toMatchSnapshot();
|
|
67
|
-
expect(wrapper.find('SimpleInput').instance().isValid).toBe(false);
|
|
68
|
-
});
|
|
69
|
-
it('should focus the input', () => {
|
|
70
|
-
const onFocusMock = jest.fn();
|
|
71
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Input, {
|
|
72
|
-
onFocusChange: onFocusMock
|
|
73
|
-
}));
|
|
74
|
-
const input = wrapper.find('input');
|
|
75
|
-
expect(wrapper).toMatchSnapshot();
|
|
76
|
-
expect(wrapper.find('SimpleInput').instance().isFocused).toBe(false);
|
|
77
|
-
input.simulate('focus');
|
|
78
|
-
expect(wrapper.find('SimpleInput').instance().isFocused).toBe(true);
|
|
79
|
-
input.simulate('blur');
|
|
80
|
-
expect(wrapper.find('SimpleInput').instance().isFocused).toBe(false);
|
|
81
|
-
});
|
|
82
|
-
it('should change the value on user input', () => {
|
|
83
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Input, {
|
|
84
|
-
value: "My initial value"
|
|
85
|
-
}));
|
|
86
|
-
expect(wrapper).toMatchSnapshot();
|
|
87
|
-
expect(wrapper.find('SimpleInput').instance().value).toBe('My initial value');
|
|
88
|
-
const input = wrapper.find('input');
|
|
89
|
-
input.simulate('change', {
|
|
90
|
-
target: {
|
|
91
|
-
value: 'foobar'
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
expect(wrapper.find('SimpleInput').instance().value).toBe('foobar');
|
|
95
|
-
});
|
|
96
|
-
it('should render a multiline input with empty content and react on change', () => {
|
|
97
|
-
const multiLineValue = `dfsdsdf
|
|
98
|
-
sdfdsff
|
|
99
|
-
dsf`;
|
|
100
|
-
const wrapper = mount(/*#__PURE__*/_jsx(Input, {
|
|
101
|
-
value: "",
|
|
102
|
-
multiLine: true
|
|
103
|
-
}));
|
|
104
|
-
expect(wrapper).toMatchSnapshot();
|
|
105
|
-
expect(wrapper.find('MultiLineInput').instance().value).toEqual('');
|
|
106
|
-
wrapper.setProps({
|
|
107
|
-
value: multiLineValue
|
|
108
|
-
});
|
|
109
|
-
expect(wrapper.find('textarea').getDOMNode().innerHTML).toEqual(multiLineValue);
|
|
110
|
-
});
|
|
111
|
-
it('should render additional html attributes', () => {
|
|
112
|
-
const wrapper = shallow(/*#__PURE__*/_jsx(Input, {
|
|
113
|
-
type: "date",
|
|
114
|
-
attributes: {
|
|
115
|
-
min: '1970-01-01',
|
|
116
|
-
max: '2010-01-01'
|
|
117
|
-
}
|
|
118
|
-
})).dive();
|
|
119
|
-
expect(wrapper).toMatchSnapshot();
|
|
120
|
-
expect(wrapper.prop('min')).toEqual('1970-01-01');
|
|
121
|
-
expect(wrapper.prop('max')).toEqual('2010-01-01');
|
|
122
|
-
});
|
|
123
|
-
});
|