-
Notifications
You must be signed in to change notification settings - Fork 10.7k
/
index.test.tsx
128 lines (107 loc) · 2.63 KB
/
index.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* eslint-disable @typescript-eslint/ban-ts-comment */
/**
* External dependencies
*/
import { render, screen } from '@testing-library/react';
import { recordEvent } from '@woocommerce/tracks';
/**
* Internal dependencies
*/
import { Transitional } from '../index';
jest.mock( '../../assembler-hub/site-hub', () => ( {
__esModule: true,
SiteHub: () => {
return <div />;
},
} ) );
jest.mock(
'@wordpress/edit-site/build-module/components/layout/hooks',
() => ( {
__esModule: true,
useIsSiteEditorLoading: jest.fn().mockReturnValue( false ),
} )
);
jest.mock( '@woocommerce/tracks', () => ( { recordEvent: jest.fn() } ) );
describe( 'Transitional', () => {
let props: {
sendEvent: jest.Mock;
};
beforeEach( () => {
props = {
sendEvent: jest.fn(),
};
} );
it( 'should render Transitional page', () => {
// @ts-ignore
render( <Transitional { ...props } /> );
expect(
screen.getByText( /Your store looks great!/i )
).toBeInTheDocument();
expect(
screen.getByRole( 'button', {
name: /View store/i,
} )
).toBeInTheDocument();
expect(
screen.getByRole( 'button', {
name: /Go to Products/i,
} )
).toBeInTheDocument();
expect(
screen.getByRole( 'button', {
name: /Go to the Editor/i,
} )
).toBeInTheDocument();
expect(
screen.getByRole( 'button', {
name: /Back to Home/i,
} )
).toBeInTheDocument();
} );
it( 'should record an event when clicking on "View store" button', () => {
window.open = jest.fn();
// @ts-ignore
render( <Transitional { ...props } /> );
screen
.getByRole( 'button', {
name: /View store/i,
} )
.click();
expect( recordEvent ).toHaveBeenCalledWith(
'customize_your_store_transitional_preview_store_click'
);
} );
it( 'should record an event when clicking on "Go to the Editor" button', () => {
// @ts-ignore Mocking window location
delete window.location;
window.location = {
// @ts-ignore Mocking window location href
href: jest.fn(),
};
// @ts-ignore
render( <Transitional { ...props } /> );
screen
.getByRole( 'button', {
name: /Go to the Editor/i,
} )
.click();
expect( recordEvent ).toHaveBeenCalledWith(
'customize_your_store_transitional_editor_click'
);
} );
it( 'should send GO_BACK_TO_HOME event when clicking on "Back to Home" button', () => {
// @ts-ignore
render( <Transitional { ...props } /> );
screen
.getByRole( 'button', {
name: /Back to Home/i,
} )
.click();
expect( props.sendEvent ).toHaveBeenCalledWith( {
type: 'GO_BACK_TO_HOME',
} );
expect( recordEvent ).toHaveBeenCalledWith(
'customize_your_store_transitional_home_click'
);
} );
} );