@elementor/editor-site-navigation 0.22.7 → 0.23.0
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/CHANGELOG.md +15 -0
- package/package.json +18 -11
- package/src/__tests__/icons-map.test.tsx +0 -33
- package/src/components/panel/actions-menu/actions/__tests__/delete.test.tsx +0 -90
- package/src/components/panel/actions-menu/actions/__tests__/set-home.test.tsx +0 -122
- package/src/components/panel/actions-menu/actions/__tests__/view.test.tsx +0 -40
- package/src/components/panel/posts-list/__tests__/post-list-item.test.tsx +0 -211
- package/src/components/panel/posts-list/__tests__/posts-collapsible-list.test.tsx +0 -248
- package/src/components/top-bar/__tests__/add-new-page.test.tsx +0 -129
- package/src/components/top-bar/__tests__/recently-edited.test.tsx +0 -380
- package/src/hooks/__tests__/use-create-page.test.ts +0 -39
- package/src/hooks/__tests__/use-homepage-actions.test.ts +0 -43
- package/src/hooks/__tests__/use-homepage.test.ts +0 -42
- package/src/hooks/__tests__/use-post-actions.test.ts +0 -89
- package/src/hooks/__tests__/use-posts.test.ts +0 -93
- package/src/hooks/__tests__/use-recent-posts.test.ts +0 -40
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { fireEvent, screen, waitFor } from '@testing-library/react';
|
|
3
|
-
import PostsCollapsibleList from '../posts-collapsible-list';
|
|
4
|
-
import { createMockDocument, renderWithQuery } from 'test-utils';
|
|
5
|
-
import { PostListContextProvider } from '../../../../contexts/post-list-context';
|
|
6
|
-
import { __useActiveDocument as useActiveDocument } from '@elementor/editor-documents';
|
|
7
|
-
import { usePosts } from '../../../../hooks/use-posts';
|
|
8
|
-
|
|
9
|
-
const mockMutateAsync = jest.fn();
|
|
10
|
-
jest.mock( '../../../../hooks/use-posts-actions', () => ( {
|
|
11
|
-
usePostActions: () => ( {
|
|
12
|
-
createPost: {
|
|
13
|
-
mutateAsync: mockMutateAsync,
|
|
14
|
-
isPending: false,
|
|
15
|
-
},
|
|
16
|
-
duplicatePost: {
|
|
17
|
-
mutateAsync: mockMutateAsync,
|
|
18
|
-
isPending: false,
|
|
19
|
-
},
|
|
20
|
-
} ),
|
|
21
|
-
} ) );
|
|
22
|
-
|
|
23
|
-
jest.mock( '../../../../hooks/use-posts', () => ( {
|
|
24
|
-
__esModule: true,
|
|
25
|
-
usePosts: jest.fn( () => ( {
|
|
26
|
-
isLoading: false,
|
|
27
|
-
data: {
|
|
28
|
-
posts: [
|
|
29
|
-
{
|
|
30
|
-
id: 1,
|
|
31
|
-
type: 'page',
|
|
32
|
-
title: { rendered: 'Home' },
|
|
33
|
-
status: 'publish',
|
|
34
|
-
link: 'www.test.demo',
|
|
35
|
-
user_can: { edit: true, delete: true },
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
id: 2,
|
|
39
|
-
type: 'page',
|
|
40
|
-
title: { rendered: 'About' },
|
|
41
|
-
status: 'draft',
|
|
42
|
-
link: 'www.test.demo',
|
|
43
|
-
user_can: { edit: true, delete: true },
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
total: 2,
|
|
47
|
-
},
|
|
48
|
-
} ) ),
|
|
49
|
-
} ) );
|
|
50
|
-
|
|
51
|
-
jest.mock( '../../../../hooks/use-homepage', () => ( {
|
|
52
|
-
__esModule: true,
|
|
53
|
-
useHomepage: jest.fn( () => ( {
|
|
54
|
-
isLoading: false,
|
|
55
|
-
data: 1,
|
|
56
|
-
} ) ),
|
|
57
|
-
} ) );
|
|
58
|
-
|
|
59
|
-
jest.mock( '@elementor/editor-documents', () => ( {
|
|
60
|
-
__useActiveDocument: jest.fn(),
|
|
61
|
-
__useNavigateToDocument: jest.fn(),
|
|
62
|
-
} ) );
|
|
63
|
-
|
|
64
|
-
jest.mock( '../../../../hooks/use-user', () => ( {
|
|
65
|
-
default: jest.fn( () => ( {
|
|
66
|
-
isLoading: false,
|
|
67
|
-
data: {
|
|
68
|
-
capabilities: {
|
|
69
|
-
edit_pages: true,
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
} ) ),
|
|
73
|
-
__esModule: true,
|
|
74
|
-
} ) );
|
|
75
|
-
|
|
76
|
-
describe( '@elementor/editor-site-navigation - PostsCollapsibleList', () => {
|
|
77
|
-
beforeEach( () => {
|
|
78
|
-
jest.mocked( useActiveDocument ).mockReturnValue(
|
|
79
|
-
createMockDocument( {
|
|
80
|
-
id: 3,
|
|
81
|
-
} )
|
|
82
|
-
);
|
|
83
|
-
} );
|
|
84
|
-
|
|
85
|
-
afterEach( () => {
|
|
86
|
-
jest.clearAllMocks();
|
|
87
|
-
} );
|
|
88
|
-
|
|
89
|
-
it( 'should render closed list', () => {
|
|
90
|
-
// Act.
|
|
91
|
-
renderWithQuery( <PostsCollapsibleList isOpenByDefault={ false } /> );
|
|
92
|
-
|
|
93
|
-
// Assert.
|
|
94
|
-
const label = screen.getByText( `Pages (2)` );
|
|
95
|
-
expect( label ).toBeInTheDocument();
|
|
96
|
-
|
|
97
|
-
const postInList = screen.queryByText( 'Home' );
|
|
98
|
-
expect( postInList ).not.toBeInTheDocument();
|
|
99
|
-
} );
|
|
100
|
-
|
|
101
|
-
it( 'should render open list with home icon and page status', () => {
|
|
102
|
-
// Act.
|
|
103
|
-
renderWithQuery( <PostsCollapsibleList isOpenByDefault={ true } /> );
|
|
104
|
-
|
|
105
|
-
// Assert.
|
|
106
|
-
const items = screen.getAllByRole( 'listitem' );
|
|
107
|
-
|
|
108
|
-
expect( items.length ).toBe( 3 );
|
|
109
|
-
|
|
110
|
-
// First item is the list title.
|
|
111
|
-
expect( items[ 0 ] ).toHaveTextContent( `Pages (2)` );
|
|
112
|
-
expect( items[ 1 ] ).toHaveTextContent( 'Home' );
|
|
113
|
-
expect( items[ 1 ] ).toHaveTextContent( 'Homepage' ); // Home icon.
|
|
114
|
-
expect( items[ 2 ] ).toHaveTextContent( 'About' );
|
|
115
|
-
expect( items[ 2 ] ).toHaveTextContent( '(draft)' );
|
|
116
|
-
} );
|
|
117
|
-
|
|
118
|
-
it( 'should create a new post after clicking "Add New" button', async () => {
|
|
119
|
-
// Arrange.
|
|
120
|
-
renderWithQuery(
|
|
121
|
-
<PostListContextProvider type={ 'page' } setError={ () => {} }>
|
|
122
|
-
<PostsCollapsibleList isOpenByDefault={ true } />
|
|
123
|
-
</PostListContextProvider>
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
// Act.
|
|
127
|
-
const addNewButton = screen.getByRole( 'button', { name: 'Add New' } );
|
|
128
|
-
fireEvent.click( addNewButton );
|
|
129
|
-
|
|
130
|
-
const input = screen.getByRole( 'textbox' );
|
|
131
|
-
|
|
132
|
-
if ( ! input || ! ( input instanceof HTMLInputElement ) ) {
|
|
133
|
-
throw new Error( 'No input field found.' );
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
expect( input ).toHaveValue( 'New Page' );
|
|
137
|
-
|
|
138
|
-
fireEvent.change( input, { target: { value: 'New Page Title' } } );
|
|
139
|
-
fireEvent.blur( input );
|
|
140
|
-
|
|
141
|
-
// Assert.
|
|
142
|
-
waitFor( () => {
|
|
143
|
-
expect( input ).toHaveAttribute( 'aria-disabled', 'true' );
|
|
144
|
-
} ).then();
|
|
145
|
-
|
|
146
|
-
expect( mockMutateAsync ).toHaveBeenCalledTimes( 1 );
|
|
147
|
-
|
|
148
|
-
waitFor( () => {
|
|
149
|
-
expect( input ).not.toBeInTheDocument();
|
|
150
|
-
} ).then();
|
|
151
|
-
|
|
152
|
-
waitFor( () => {
|
|
153
|
-
expect( screen.getByText( 'New Page Title' ) ).toBeInTheDocument();
|
|
154
|
-
} ).then();
|
|
155
|
-
} );
|
|
156
|
-
|
|
157
|
-
it( 'should append a new list item in edit mode, when "Duplicate" action is clicked', () => {
|
|
158
|
-
// Arrange.
|
|
159
|
-
renderWithQuery(
|
|
160
|
-
<PostListContextProvider type={ 'page' } setError={ () => {} }>
|
|
161
|
-
<PostsCollapsibleList isOpenByDefault={ true } />
|
|
162
|
-
</PostListContextProvider>
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
// Act.
|
|
166
|
-
const buttons = screen.getAllByRole( 'button' );
|
|
167
|
-
fireEvent.click( buttons[ 3 ] ); // Button to open the actions' menu of the first post.
|
|
168
|
-
|
|
169
|
-
const duplicateButton = screen.getByRole( 'menuitem', { name: 'Duplicate' } );
|
|
170
|
-
fireEvent.click( duplicateButton );
|
|
171
|
-
|
|
172
|
-
// Assert.
|
|
173
|
-
waitFor( () => {
|
|
174
|
-
expect( duplicateButton ).not.toBeInTheDocument();
|
|
175
|
-
} ).then();
|
|
176
|
-
|
|
177
|
-
const input = screen.getByRole( 'textbox' );
|
|
178
|
-
|
|
179
|
-
expect( input ).toBeInTheDocument();
|
|
180
|
-
expect( input ).toHaveValue( 'Home copy' );
|
|
181
|
-
} );
|
|
182
|
-
|
|
183
|
-
it( 'Should not render load button when there is no next page', () => {
|
|
184
|
-
// Arrange.
|
|
185
|
-
jest.mocked( usePosts ).mockReturnValue( {
|
|
186
|
-
hasNextPage: false,
|
|
187
|
-
isLoading: false,
|
|
188
|
-
data: {
|
|
189
|
-
posts: [
|
|
190
|
-
{
|
|
191
|
-
id: 1,
|
|
192
|
-
type: 'page',
|
|
193
|
-
title: { rendered: 'Home' },
|
|
194
|
-
status: 'publish',
|
|
195
|
-
link: 'www.test.demo',
|
|
196
|
-
user_can: { edit: true, delete: true },
|
|
197
|
-
},
|
|
198
|
-
{
|
|
199
|
-
id: 2,
|
|
200
|
-
type: 'page',
|
|
201
|
-
title: { rendered: 'About' },
|
|
202
|
-
status: 'draft',
|
|
203
|
-
link: 'www.test.demo',
|
|
204
|
-
user_can: { edit: true, delete: true },
|
|
205
|
-
},
|
|
206
|
-
],
|
|
207
|
-
total: 2,
|
|
208
|
-
},
|
|
209
|
-
} as ReturnType< typeof usePosts > );
|
|
210
|
-
renderWithQuery( <PostsCollapsibleList isOpenByDefault={ true } /> );
|
|
211
|
-
|
|
212
|
-
// Assert.
|
|
213
|
-
expect( screen.queryByRole( 'button', { name: 'Load More' } ) ).not.toBeInTheDocument();
|
|
214
|
-
} );
|
|
215
|
-
|
|
216
|
-
it( 'Should render load button when there is next page', () => {
|
|
217
|
-
// Arrange.
|
|
218
|
-
jest.mocked( usePosts ).mockReturnValue( {
|
|
219
|
-
hasNextPage: true,
|
|
220
|
-
isLoading: false,
|
|
221
|
-
data: {
|
|
222
|
-
posts: [
|
|
223
|
-
{
|
|
224
|
-
id: 1,
|
|
225
|
-
type: 'page',
|
|
226
|
-
title: { rendered: 'Home' },
|
|
227
|
-
status: 'publish',
|
|
228
|
-
link: 'www.test.demo',
|
|
229
|
-
user_can: { edit: true, delete: true },
|
|
230
|
-
},
|
|
231
|
-
{
|
|
232
|
-
id: 2,
|
|
233
|
-
type: 'page',
|
|
234
|
-
title: { rendered: 'About' },
|
|
235
|
-
status: 'draft',
|
|
236
|
-
link: 'www.test.demo',
|
|
237
|
-
user_can: { edit: true, delete: true },
|
|
238
|
-
},
|
|
239
|
-
],
|
|
240
|
-
total: 2,
|
|
241
|
-
},
|
|
242
|
-
} as ReturnType< typeof usePosts > );
|
|
243
|
-
renderWithQuery( <PostsCollapsibleList isOpenByDefault={ true } /> );
|
|
244
|
-
|
|
245
|
-
// Assert.
|
|
246
|
-
expect( screen.getByRole( 'button', { name: 'Load More' } ) ).toBeInTheDocument();
|
|
247
|
-
} );
|
|
248
|
-
} );
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
3
|
-
import {
|
|
4
|
-
__useActiveDocument as useActiveDocument,
|
|
5
|
-
__useNavigateToDocument as useNavigateToDocument,
|
|
6
|
-
} from '@elementor/editor-documents';
|
|
7
|
-
import RecentlyEdited from '../recently-edited';
|
|
8
|
-
import { createMockDocument } from 'test-utils';
|
|
9
|
-
import useRecentPosts from '../../../hooks/use-recent-posts';
|
|
10
|
-
import useCreatePage from '../../../hooks/use-create-page';
|
|
11
|
-
import { RecentPost } from '../../../types';
|
|
12
|
-
import useUser from '../../../hooks/use-user';
|
|
13
|
-
|
|
14
|
-
jest.mock( '@elementor/editor-documents', () => ( {
|
|
15
|
-
__useActiveDocument: jest.fn(),
|
|
16
|
-
__useHostDocument: jest.fn(),
|
|
17
|
-
__useNavigateToDocument: jest.fn(),
|
|
18
|
-
} ) );
|
|
19
|
-
|
|
20
|
-
jest.mock( '../../../hooks/use-recent-posts', () => ( {
|
|
21
|
-
__esModule: true,
|
|
22
|
-
default: jest.fn( () => ( { isLoading: false, recentPosts: [] } ) ),
|
|
23
|
-
} ) );
|
|
24
|
-
|
|
25
|
-
jest.mock( '../../../hooks/use-create-page', () => ( {
|
|
26
|
-
__esModule: true,
|
|
27
|
-
default: jest.fn( () => ( { create: jest.fn(), isLoading: false } ) ),
|
|
28
|
-
} ) );
|
|
29
|
-
|
|
30
|
-
jest.mock( '../../../hooks/use-user', () => ( {
|
|
31
|
-
default: jest.fn( () => ( {
|
|
32
|
-
isLoading: false,
|
|
33
|
-
data: {
|
|
34
|
-
capabilities: {
|
|
35
|
-
edit_pages: true,
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
} ) ),
|
|
39
|
-
__esModule: true,
|
|
40
|
-
} ) );
|
|
41
|
-
|
|
42
|
-
describe( '@elementor/recently-edited - Top bar add new page', () => {
|
|
43
|
-
beforeEach( () => {
|
|
44
|
-
jest.mocked( useActiveDocument ).mockReturnValue( createMockDocument() );
|
|
45
|
-
} );
|
|
46
|
-
|
|
47
|
-
afterEach( () => {
|
|
48
|
-
jest.clearAllMocks();
|
|
49
|
-
} );
|
|
50
|
-
|
|
51
|
-
it( 'should render add new page button', () => {
|
|
52
|
-
// Arrange.
|
|
53
|
-
const isLoading = false;
|
|
54
|
-
const recentPosts: RecentPost[] = [];
|
|
55
|
-
|
|
56
|
-
jest.mocked( useRecentPosts ).mockReturnValue( { isLoading, data: recentPosts } as ReturnType<
|
|
57
|
-
typeof useRecentPosts
|
|
58
|
-
> );
|
|
59
|
-
|
|
60
|
-
render( <RecentlyEdited /> );
|
|
61
|
-
|
|
62
|
-
// Act.
|
|
63
|
-
const buttons = screen.getAllByRole( 'button' );
|
|
64
|
-
fireEvent.click( buttons[ 0 ] ); // Opens the recently edited menu
|
|
65
|
-
|
|
66
|
-
// Assert.
|
|
67
|
-
const label = screen.getByText( 'Add new page', { exact: false } );
|
|
68
|
-
expect( label ).toBeInTheDocument();
|
|
69
|
-
} );
|
|
70
|
-
|
|
71
|
-
it( 'should trigger create page hook on click', async () => {
|
|
72
|
-
// Arrange.
|
|
73
|
-
const isLoading = false;
|
|
74
|
-
const recentPosts: RecentPost[] = [];
|
|
75
|
-
const create = jest.fn().mockReturnValue( Promise.resolve( { id: 123 } ) );
|
|
76
|
-
const navigateToDocument = jest.fn();
|
|
77
|
-
|
|
78
|
-
jest.mocked( useRecentPosts ).mockReturnValue( { isLoading, data: recentPosts } as ReturnType<
|
|
79
|
-
typeof useRecentPosts
|
|
80
|
-
> );
|
|
81
|
-
jest.mocked( useCreatePage ).mockReturnValue( { isLoading, create } );
|
|
82
|
-
jest.mocked( useNavigateToDocument ).mockReturnValue( navigateToDocument );
|
|
83
|
-
|
|
84
|
-
render( <RecentlyEdited /> );
|
|
85
|
-
|
|
86
|
-
// Act.
|
|
87
|
-
const buttons = screen.getAllByRole( 'button' );
|
|
88
|
-
fireEvent.click( buttons[ 0 ] ); // Opens the recently edited menu
|
|
89
|
-
|
|
90
|
-
const addNewPage = screen.getByText( 'Add new page', { exact: false } );
|
|
91
|
-
fireEvent.click( addNewPage );
|
|
92
|
-
|
|
93
|
-
// Assert.
|
|
94
|
-
expect( create ).toHaveBeenCalledTimes( 1 );
|
|
95
|
-
|
|
96
|
-
await waitFor( () => expect( navigateToDocument ).toHaveBeenCalledTimes( 1 ) );
|
|
97
|
-
|
|
98
|
-
expect( navigateToDocument ).toHaveBeenCalledWith( 123 );
|
|
99
|
-
} );
|
|
100
|
-
|
|
101
|
-
it( 'should be disabled if user does not have edit_posts capability', () => {
|
|
102
|
-
// Arrange.
|
|
103
|
-
jest.mocked( useUser ).mockReturnValue( {
|
|
104
|
-
isLoading: false,
|
|
105
|
-
data: {
|
|
106
|
-
capabilities: {
|
|
107
|
-
edit_pages: false,
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
} as unknown as ReturnType< typeof useUser > );
|
|
111
|
-
|
|
112
|
-
const isLoading = false;
|
|
113
|
-
const recentPosts: RecentPost[] = [];
|
|
114
|
-
|
|
115
|
-
jest.mocked( useRecentPosts ).mockReturnValue( { isLoading, data: recentPosts } as ReturnType<
|
|
116
|
-
typeof useRecentPosts
|
|
117
|
-
> );
|
|
118
|
-
|
|
119
|
-
render( <RecentlyEdited /> );
|
|
120
|
-
|
|
121
|
-
// Act.
|
|
122
|
-
const buttons = screen.getAllByRole( 'button' );
|
|
123
|
-
fireEvent.click( buttons[ 0 ] ); // Opens the recently edited menu
|
|
124
|
-
|
|
125
|
-
// Assert.
|
|
126
|
-
const addNewPage = screen.getByRole( 'menuitem', { name: /Add new page/i } );
|
|
127
|
-
expect( addNewPage ).toHaveAttribute( 'aria-disabled', 'true' );
|
|
128
|
-
} );
|
|
129
|
-
} );
|