@transferwise/components 0.0.0-experimental-c91775b → 0.0.0-experimental-09b5867

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.
@@ -1,190 +0,0 @@
1
- import { Breakpoint } from '@transferwise/neptune-tokens';
2
- import AvatarView from '../avatarView';
3
- import { mockMatchMedia, render, screen } from '../test-utils';
4
-
5
- import FlowNavigation from './FlowNavigation';
6
-
7
- mockMatchMedia();
8
-
9
- jest.mock('./animatedLabel', () => {
10
- return function ({ className, activeLabel }) {
11
- return (
12
- <div className={className} data-testid={`activeLabel-${activeLabel}`}>
13
- AnimatedLabel
14
- </div>
15
- );
16
- };
17
- });
18
-
19
- describe('FlowNavigation', () => {
20
- beforeEach(() => {
21
- window.innerWidth = Breakpoint.LARGE + 1;
22
- });
23
-
24
- const props = {
25
- avatar: <AvatarView profileName="Tim Mike" />,
26
- logo: <img alt="logo" src="logo.svg" width="138" height="24" />,
27
- onClose: jest.fn(),
28
- steps: [
29
- {
30
- label: 'label-0',
31
- },
32
- { label: 'label-1' },
33
- { label: 'label-2' },
34
- ],
35
- activeStep: 0,
36
- };
37
-
38
- it(`renders full Logo`, () => {
39
- render(<FlowNavigation {...props} />);
40
- expect(logoFull()).toBeInTheDocument();
41
- });
42
-
43
- it(`renders separator if avatar and onClose are provided`, () => {
44
- const { container } = render(<FlowNavigation {...props} />);
45
-
46
- expect(container.querySelector('span.m-x-1')).toBeInTheDocument();
47
- });
48
-
49
- it(`doesn't render separator if avatar or onClose are not provided`, () => {
50
- const { container, rerender } = render(<FlowNavigation {...props} onClose={null} />);
51
-
52
- expect(container.querySelector('.separator')).not.toBeInTheDocument();
53
-
54
- rerender(<FlowNavigation {...props} avatar={null} />);
55
-
56
- expect(container.querySelector('.separator')).not.toBeInTheDocument();
57
- });
58
-
59
- it(`doesn't render separator if done is true`, () => {
60
- const { container, rerender } = render(<FlowNavigation {...props} onClose={null} />);
61
-
62
- expect(container.querySelector('.separator')).not.toBeInTheDocument();
63
-
64
- rerender(<FlowNavigation {...props} avatar={null} done />);
65
-
66
- expect(container.querySelector('.separator')).not.toBeInTheDocument();
67
- });
68
-
69
- it(`renders border based on done`, () => {
70
- const { container, rerender } = render(<FlowNavigation {...props} onClose={null} />);
71
-
72
- expect(container.querySelector('.np-flow-navigation--border-bottom')).toBeInTheDocument();
73
-
74
- rerender(<FlowNavigation {...props} avatar={null} done />);
75
-
76
- expect(container.querySelector('.np-flow-navigation--border-bottom')).not.toBeInTheDocument();
77
- });
78
-
79
- it(`hides stepper when done is true`, () => {
80
- const { container, rerender } = render(<FlowNavigation {...props} onClose={null} />);
81
-
82
- expect(container.querySelector('.np-flow-navigation__stepper')).toBeInTheDocument();
83
-
84
- rerender(<FlowNavigation {...props} avatar={null} done />);
85
-
86
- expect(container.querySelector('.np-flow-navigation__stepper')).not.toBeInTheDocument();
87
- });
88
-
89
- it(`does not render stepper when steps is empty`, () => {
90
- const { container } = render(<FlowNavigation {...props} steps={[]} />);
91
-
92
- expect(container.querySelector('.np-flow-navigation__stepper')).not.toBeInTheDocument();
93
- expect(container.querySelector('.tw-stepper')).not.toBeInTheDocument();
94
- });
95
-
96
- it(`hides label when done is true`, () => {
97
- const { rerender } = render(<FlowNavigation {...props} done={false} />);
98
-
99
- expect(screen.getByText('label-0')).toBeInTheDocument();
100
-
101
- rerender(<FlowNavigation {...props} done />);
102
-
103
- expect(screen.queryByText('label-0')).not.toBeInTheDocument();
104
- });
105
-
106
- it(`renders xs-max class`, () => {
107
- window.innerWidth = Breakpoint.SMALL - 1;
108
- const { container } = render(<FlowNavigation {...props} onClose={null} />);
109
-
110
- expect(container.querySelector('.np-flow-navigation--xs-max')).toBeInTheDocument();
111
- });
112
-
113
- it(`renders sm class`, () => {
114
- window.innerWidth = Breakpoint.SMALL;
115
- const { container } = render(<FlowNavigation {...props} onClose={null} />);
116
-
117
- expect(container.querySelector('.np-flow-navigation--sm')).toBeInTheDocument();
118
- });
119
-
120
- it(`renders lg class`, () => {
121
- window.innerWidth = Breakpoint.LARGE;
122
- const { container } = render(<FlowNavigation {...props} onClose={null} />);
123
-
124
- expect(container.querySelector('.np-flow-navigation--lg')).toBeInTheDocument();
125
- });
126
-
127
- describe('on mobile', () => {
128
- beforeEach(() => {
129
- window.innerWidth = Breakpoint.SMALL - 1;
130
- });
131
-
132
- it('renders Logo', () => {
133
- render(<FlowNavigation {...props} />);
134
- expect(screen.getByAltText('logo')).toBeInTheDocument();
135
- });
136
-
137
- it('renders flag if activeStep <= 0 onGoBack or is not provided', () => {
138
- const { rerender } = render(
139
- <FlowNavigation {...props} activeStep={0} onGoBack={undefined} />,
140
- );
141
-
142
- const flag = screen.queryByAltText('logo');
143
-
144
- expect(flag).toBeInTheDocument();
145
-
146
- rerender(<FlowNavigation {...props} activeStep={1} onGoBack={undefined} />);
147
-
148
- expect(flag).toBeInTheDocument();
149
-
150
- rerender(<FlowNavigation {...props} activeStep={0} onGoBack={jest.fn()} />);
151
-
152
- expect(flag).toBeInTheDocument();
153
-
154
- rerender(<FlowNavigation {...props} activeStep={1} onGoBack={jest.fn()} />);
155
-
156
- expect(flag).not.toBeInTheDocument();
157
- });
158
-
159
- it('renders BackButton with AnimatedLabel if onGoBack is provided and activeStep > 0', () => {
160
- const { rerender } = render(<FlowNavigation {...props} onGoBack={jest.fn()} />);
161
-
162
- expect(
163
- screen.queryByRole('button', { name: /back to previous step/i }),
164
- ).not.toBeInTheDocument();
165
-
166
- rerender(<FlowNavigation {...props} activeStep={1} />);
167
- expect(
168
- screen.queryByRole('button', { name: /back to previous step/i }),
169
- ).not.toBeInTheDocument();
170
-
171
- rerender(<FlowNavigation {...props} activeStep={1} onGoBack={jest.fn()} />);
172
-
173
- expect(screen.getByRole('button', { name: /back to previous step/i })).toBeInTheDocument();
174
- expect(screen.getByText('AnimatedLabel')).toBeInTheDocument();
175
- });
176
-
177
- it('renders correct AnimatedLabel', () => {
178
- const { rerender } = render(
179
- <FlowNavigation {...props} activeStep={1} onGoBack={jest.fn()} />,
180
- );
181
-
182
- expect(screen.getByTestId('activeLabel-1')).toBeInTheDocument();
183
-
184
- rerender(<FlowNavigation {...props} activeStep={2} onGoBack={jest.fn()} />);
185
-
186
- expect(screen.getByTestId('activeLabel-2')).toBeInTheDocument();
187
- });
188
- });
189
- const logoFull = () => screen.getByAltText(`logo`);
190
- });