@transferwise/components 0.0.0-experimental-ae7c18d → 0.0.0-experimental-c29561b
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/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { render, screen, userEvent } from '../test-utils';
|
|
2
|
+
import * as mockedDeviceDetection from './deviceDetection';
|
|
2
3
|
|
|
3
4
|
import Stepper from './Stepper';
|
|
4
5
|
|
|
@@ -6,30 +7,28 @@ jest.mock('./deviceDetection', () => ({
|
|
|
6
7
|
isTouchDevice: jest.fn(() => false),
|
|
7
8
|
}));
|
|
8
9
|
|
|
9
|
-
const generateSteps = (stepsCount) =>
|
|
10
|
-
Array.from({ length: stepsCount }, () => ({
|
|
11
|
-
label: Math.random().toString(),
|
|
12
|
-
onClick: jest.fn(),
|
|
13
|
-
}));
|
|
14
|
-
|
|
15
10
|
describe('Stepper', () => {
|
|
16
|
-
const defaultProps = {
|
|
17
|
-
activeStep: 0,
|
|
18
|
-
steps: generateSteps(3),
|
|
19
|
-
};
|
|
20
|
-
let fakeDeviceDetection;
|
|
21
|
-
|
|
22
11
|
beforeEach(() => {
|
|
23
|
-
fakeDeviceDetection = require('./deviceDetection');
|
|
24
12
|
jest.clearAllMocks();
|
|
25
13
|
});
|
|
26
14
|
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
const generateSteps = (stepsCount: number) =>
|
|
16
|
+
Array.from({ length: stepsCount }, () => ({
|
|
17
|
+
label: Math.random().toString(),
|
|
18
|
+
onClick: jest.fn(),
|
|
19
|
+
}));
|
|
30
20
|
|
|
31
21
|
const getSteps = () => screen.getAllByRole('listitem');
|
|
32
22
|
|
|
23
|
+
const initialProps = {
|
|
24
|
+
activeStep: 0,
|
|
25
|
+
steps: generateSteps(3),
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const customRender = (overrides = {}) => {
|
|
29
|
+
return render(<Stepper {...initialProps} {...overrides} />);
|
|
30
|
+
};
|
|
31
|
+
|
|
33
32
|
describe('progress bar', () => {
|
|
34
33
|
it('renders nothing when no steps are passed in', () => {
|
|
35
34
|
customRender({ steps: [] });
|
|
@@ -48,7 +47,7 @@ describe('Stepper', () => {
|
|
|
48
47
|
});
|
|
49
48
|
|
|
50
49
|
describe('step interactive style', () => {
|
|
51
|
-
const expectStepIsVisuallyInteractive = (stepIndex) => {
|
|
50
|
+
const expectStepIsVisuallyInteractive = (stepIndex: number) => {
|
|
52
51
|
// eslint-disable-next-line jest/valid-expect
|
|
53
52
|
return expect(getSteps()[stepIndex].classList.contains('tw-stepper__step--clickable'));
|
|
54
53
|
};
|
|
@@ -88,7 +87,7 @@ describe('Stepper', () => {
|
|
|
88
87
|
});
|
|
89
88
|
|
|
90
89
|
describe('step interactivity', () => {
|
|
91
|
-
const getStepChild = (stepIndex) => getSteps()[stepIndex].
|
|
90
|
+
const getStepChild = (stepIndex: number) => getSteps()[stepIndex].children[0];
|
|
92
91
|
|
|
93
92
|
it('is not interactive if it is the active step', async () => {
|
|
94
93
|
const steps = [
|
|
@@ -138,10 +137,10 @@ describe('Stepper', () => {
|
|
|
138
137
|
};
|
|
139
138
|
const { rerender } = customRender(initialProps);
|
|
140
139
|
|
|
141
|
-
const clickOnStep = async (stepIndex) => {
|
|
140
|
+
const clickOnStep = async (stepIndex: number) => {
|
|
142
141
|
const step = screen.getByText(initialProps.steps[stepIndex].label).parentElement;
|
|
143
142
|
if (step) {
|
|
144
|
-
return
|
|
143
|
+
return userEvent.click(step);
|
|
145
144
|
}
|
|
146
145
|
};
|
|
147
146
|
|
|
@@ -159,12 +158,12 @@ describe('Stepper', () => {
|
|
|
159
158
|
it('are active when they are the currently active step', () => {
|
|
160
159
|
const { rerender } = customRender({
|
|
161
160
|
steps: Array(4)
|
|
162
|
-
.fill()
|
|
161
|
+
.fill('')
|
|
163
162
|
.map((_, i) => ({ label: i.toString() })),
|
|
164
163
|
activeStep: 1,
|
|
165
164
|
});
|
|
166
165
|
|
|
167
|
-
const stepActive = (index) =>
|
|
166
|
+
const stepActive = (index: number) =>
|
|
168
167
|
getSteps()[index].classList.contains('tw-stepper__step--active');
|
|
169
168
|
|
|
170
169
|
expect(stepActive(0)).toBe(false);
|
|
@@ -172,7 +171,7 @@ describe('Stepper', () => {
|
|
|
172
171
|
expect(stepActive(2)).toBe(false);
|
|
173
172
|
expect(stepActive(3)).toBe(false);
|
|
174
173
|
|
|
175
|
-
rerender(<Stepper {...
|
|
174
|
+
rerender(<Stepper {...initialProps} activeStep={2} />);
|
|
176
175
|
|
|
177
176
|
expect(stepActive(1)).toBe(false);
|
|
178
177
|
expect(stepActive(2)).toBe(true);
|
|
@@ -181,14 +180,15 @@ describe('Stepper', () => {
|
|
|
181
180
|
it('are aria-current=step when active', () => {
|
|
182
181
|
const { rerender } = customRender({ steps: Array(4).fill({ label: '' }), activeStep: 1 });
|
|
183
182
|
|
|
184
|
-
const stepCurrent = (index) =>
|
|
183
|
+
const stepCurrent = (index: number) =>
|
|
184
|
+
getSteps()[index].getAttribute('aria-current') === 'step';
|
|
185
185
|
|
|
186
186
|
expect(stepCurrent(0)).toBe(false);
|
|
187
187
|
expect(stepCurrent(1)).toBe(true);
|
|
188
188
|
expect(stepCurrent(2)).toBe(false);
|
|
189
189
|
expect(stepCurrent(3)).toBe(false);
|
|
190
190
|
|
|
191
|
-
rerender(<Stepper {...
|
|
191
|
+
rerender(<Stepper {...initialProps} activeStep={2} />);
|
|
192
192
|
|
|
193
193
|
expect(stepCurrent(1)).toBe(false);
|
|
194
194
|
expect(stepCurrent(2)).toBe(true);
|
|
@@ -224,7 +224,7 @@ describe('Stepper', () => {
|
|
|
224
224
|
});
|
|
225
225
|
|
|
226
226
|
it('will not be rendered if the user is on a touch device', () => {
|
|
227
|
-
jest.spyOn(
|
|
227
|
+
jest.spyOn(mockedDeviceDetection, 'isTouchDevice').mockImplementation(() => true);
|
|
228
228
|
|
|
229
229
|
customRender({
|
|
230
230
|
steps: [{ hoverLabel: 'hover label', label: 'label' }, { label: 'label 2' }],
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { isTouchDevice } from './deviceDetection';
|
|
2
2
|
|
|
3
3
|
describe('Device detection', () => {
|
|
4
|
-
function fakeUserAgent(userAgent) {
|
|
4
|
+
function fakeUserAgent(userAgent: string) {
|
|
5
5
|
Object.defineProperty(navigator, 'userAgent', {
|
|
6
6
|
value: userAgent,
|
|
7
7
|
configurable: true,
|
|
8
8
|
});
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
function fakeMaxTouchPoints(maxTouchPoints) {
|
|
11
|
+
function fakeMaxTouchPoints(maxTouchPoints: number | undefined) {
|
|
12
12
|
Object.defineProperty(navigator, 'maxTouchPoints', {
|
|
13
13
|
value: maxTouchPoints,
|
|
14
14
|
configurable: true,
|
|
@@ -24,7 +24,10 @@ describe('Device detection', () => {
|
|
|
24
24
|
|
|
25
25
|
it('recognizes touch devices via window events', () => {
|
|
26
26
|
expect(isTouchDevice()).toBe(false);
|
|
27
|
-
window
|
|
27
|
+
Object.defineProperty(window, 'ontouchstart', {
|
|
28
|
+
value: () => {},
|
|
29
|
+
writable: true,
|
|
30
|
+
});
|
|
28
31
|
expect(isTouchDevice()).toBe(true);
|
|
29
32
|
});
|
|
30
33
|
|