forked from Automattic/wp-calypso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroot-section.ts
138 lines (116 loc) · 3.29 KB
/
root-section.ts
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
129
130
131
132
133
134
135
136
137
138
/**
* @jest-environment jsdom
*/
import { isEnabled } from '@automattic/calypso-config';
import { waitFor } from '@testing-library/dom';
import pageLibrary from 'page';
import initRootSection from '../root';
function initRouter( { state }: { state: any } ) {
const dispatch = jest.fn();
const getState = jest.fn( () => state );
const page = pageLibrary.create();
page( '*', ( context, next ) => {
context.store = { dispatch, getState };
next();
} );
initRootSection( null, page );
page.start();
return { dispatch, getState, page };
}
describe( 'Logged Out Landing Page', () => {
test( 'logged out goes to devdocs', async () => {
// This is the behaviour only in non-production environments
expect( isEnabled( 'devdocs/redirect-loggedout-homepage' ) ).toBeTruthy();
const state = { currentUser: { id: null } };
const { page } = initRouter( { state } );
page( '/' );
await waitFor( () => expect( page.current ).toBe( '/devdocs/start' ) );
} );
} );
describe( 'Logged In Landing Page', () => {
test( 'user with no sites goes to reader', async () => {
const state = { currentUser: { id: 1 }, sites: { items: {} } };
const { page } = initRouter( { state } );
page( '/' );
await waitFor( () => expect( page.current ).toBe( '/read' ) );
} );
test( 'user with a primary site but no permissions goes to stats', async () => {
const state = {
currentUser: { id: 1, capabilities: { 1: {} }, user: { primary_blog: 1 } },
sites: {
items: {
1: {
ID: 1,
URL: 'https://test.wordpress.com',
},
},
},
};
const { page } = initRouter( { state } );
page( '/' );
await waitFor( () => expect( page.current ).toBe( '/stats/test.wordpress.com' ) );
} );
test( 'user with a primary site and edit permissions goes to My Home', async () => {
const state = {
currentUser: { id: 1, capabilities: { 1: { edit_posts: true } }, user: { primary_blog: 1 } },
sites: {
items: {
1: {
ID: 1,
URL: 'https://test.wordpress.com',
},
},
},
};
const { page } = initRouter( { state } );
page( '/' );
await waitFor( () => expect( page.current ).toBe( '/home/test.wordpress.com' ) );
} );
test( 'user with a Jetpack site set as their primary site goes to stats', async () => {
const state = {
currentUser: { id: 1, capabilities: { 1: { edit_posts: true } }, user: { primary_blog: 1 } },
sites: {
items: {
1: {
ID: 1,
URL: 'https://test.jurassic.ninja',
jetpack: true,
},
},
},
};
const { page } = initRouter( { state } );
page( '/' );
await waitFor( () => expect( page.current ).toBe( '/stats/test.jurassic.ninja' ) );
} );
test( 'user who opts in goes to sites page', async () => {
const state = {
currentUser: {
id: 1,
capabilities: { 1: { edit_posts: true } },
user: { primary_blog: 1, site_count: 2 },
},
preferences: {
localValues: {
'sites-landing-page': { useSitesAsLandingPage: true, updatedAt: 1111 },
},
},
sites: {
items: {
1: {
ID: 1,
URL: 'https://test.wordpress.com',
},
2: {
ID: 2,
URL: 'https://test.jurassic.ninja',
jetpack: true,
},
},
},
};
const { page } = initRouter( { state } );
page( '/' );
await waitFor( () => expect( page.current ).toBe( '/sites' ) );
} );
} );