@elementor/editor-site-navigation 0.22.8 → 0.23.1
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 +17 -10
- 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
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,21 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.23.1](https://github.com/elementor/elementor-packages/compare/@elementor/editor-site-navigation@0.23.0...@elementor/editor-site-navigation@0.23.1) (2024-08-06)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @elementor/editor-site-navigation
|
|
9
|
+
|
|
10
|
+
# [0.23.0](https://github.com/elementor/elementor-packages/compare/@elementor/editor-site-navigation@0.22.8...@elementor/editor-site-navigation@0.23.0) (2024-08-05)
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
- publish only necessary files to npm ([#226](https://github.com/elementor/elementor-packages/issues/226)) ([d808e2f](https://github.com/elementor/elementor-packages/commit/d808e2f60eb7ca2d7b8560d0b79c0e62c2f969a8))
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
- **editor-editing-panel:** change textarea component [EDS-311] ([#221](https://github.com/elementor/elementor-packages/issues/221)) ([a9ab0d5](https://github.com/elementor/elementor-packages/commit/a9ab0d53e87086e323c4f024dca0eae93005e1a1))
|
|
19
|
+
- **editor-editing-panel:** settings and style tabs [EDS-277] ([#217](https://github.com/elementor/elementor-packages/issues/217)) ([c623797](https://github.com/elementor/elementor-packages/commit/c6237974d9940a2b58bdd1df3d835dc828e323f4))
|
|
20
|
+
|
|
6
21
|
## [0.22.8](https://github.com/elementor/elementor-packages/compare/@elementor/editor-site-navigation@0.22.7...@elementor/editor-site-navigation@0.22.8) (2024-07-23)
|
|
7
22
|
|
|
8
23
|
**Note:** Version bump only for package @elementor/editor-site-navigation
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-site-navigation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Elementor Team",
|
|
6
6
|
"homepage": "https://elementor.com/",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
21
|
-
"url": "https://github.com/elementor/elementor-packages.git",
|
|
21
|
+
"url": "git+https://github.com/elementor/elementor-packages.git",
|
|
22
22
|
"directory": "packages/core/editor-site-navigation"
|
|
23
23
|
},
|
|
24
24
|
"bugs": {
|
|
@@ -27,19 +27,26 @@
|
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
|
+
"files": [
|
|
31
|
+
"README.md",
|
|
32
|
+
"CHANGELOG.md",
|
|
33
|
+
"/dist",
|
|
34
|
+
"/src",
|
|
35
|
+
"!**/__tests__"
|
|
36
|
+
],
|
|
30
37
|
"scripts": {
|
|
31
38
|
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
32
39
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
33
40
|
},
|
|
34
41
|
"dependencies": {
|
|
35
|
-
"@elementor/editor-app-bar": "^0.
|
|
36
|
-
"@elementor/editor-documents": "^0.11.
|
|
37
|
-
"@elementor/editor-panels": "^0.
|
|
38
|
-
"@elementor/editor-v1-adapters": "^0.8.
|
|
39
|
-
"@elementor/env": "^0.3.
|
|
42
|
+
"@elementor/editor-app-bar": "^0.16.1",
|
|
43
|
+
"@elementor/editor-documents": "^0.11.6",
|
|
44
|
+
"@elementor/editor-panels": "^0.5.0",
|
|
45
|
+
"@elementor/editor-v1-adapters": "^0.8.1",
|
|
46
|
+
"@elementor/env": "^0.3.4",
|
|
40
47
|
"@elementor/icons": "^1.1.4",
|
|
41
|
-
"@elementor/query": "^0.2.
|
|
42
|
-
"@elementor/ui": "^1.
|
|
48
|
+
"@elementor/query": "^0.2.2",
|
|
49
|
+
"@elementor/ui": "^1.14.2",
|
|
43
50
|
"@wordpress/api-fetch": "^6.42.0",
|
|
44
51
|
"@wordpress/i18n": "^4.45.0",
|
|
45
52
|
"@wordpress/url": "^3.46.0"
|
|
@@ -47,5 +54,5 @@
|
|
|
47
54
|
"peerDependencies": {
|
|
48
55
|
"react": "^18.3.1"
|
|
49
56
|
},
|
|
50
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "9bb2a2ab74c81e97ba6a060ab2867efb15b9e5c4"
|
|
51
58
|
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { getIconsMap, extendIconsMap, resetIconsMap } from '../icons-map';
|
|
3
|
-
|
|
4
|
-
describe( '@elementor/site-navigation - iconsMap', () => {
|
|
5
|
-
afterEach( () => {
|
|
6
|
-
resetIconsMap();
|
|
7
|
-
} );
|
|
8
|
-
|
|
9
|
-
it( 'should override existing icons', async () => {
|
|
10
|
-
// Arrange.
|
|
11
|
-
const initialIcons = getIconsMap();
|
|
12
|
-
const addedIcons = {
|
|
13
|
-
'added-icon': () => <div>added-icon</div>,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
// Act - add icons.
|
|
17
|
-
extendIconsMap( addedIcons );
|
|
18
|
-
|
|
19
|
-
// Assert - should be initial and added.
|
|
20
|
-
expect( getIconsMap() ).toEqual( { ...initialIcons, ...addedIcons } );
|
|
21
|
-
|
|
22
|
-
// Arrange.
|
|
23
|
-
const overrideIcons = {
|
|
24
|
-
'added-icon': () => <div>override-icon</div>,
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// Act - override exits icons.
|
|
28
|
-
extendIconsMap( overrideIcons );
|
|
29
|
-
|
|
30
|
-
// Assert - should override exits icons.
|
|
31
|
-
expect( getIconsMap() ).toEqual( { ...initialIcons, ...overrideIcons } );
|
|
32
|
-
} );
|
|
33
|
-
} );
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { fireEvent, render, screen } from '@testing-library/react';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { Post } from '../../../../../types';
|
|
4
|
-
import Delete from '../delete';
|
|
5
|
-
|
|
6
|
-
const mockMutateAsync = jest.fn();
|
|
7
|
-
jest.mock( '../../../../../hooks/use-posts-actions', () => ( {
|
|
8
|
-
usePostActions: () => ( {
|
|
9
|
-
deletePost: {
|
|
10
|
-
mutateAsync: mockMutateAsync,
|
|
11
|
-
isPending: false,
|
|
12
|
-
},
|
|
13
|
-
} ),
|
|
14
|
-
} ) );
|
|
15
|
-
|
|
16
|
-
jest.mock( '@elementor/editor-documents', () => ( {
|
|
17
|
-
__useActiveDocument: jest.fn(),
|
|
18
|
-
} ) );
|
|
19
|
-
|
|
20
|
-
describe( '@elementor/editor-site-navigation/pages-panel-actions - Delete', () => {
|
|
21
|
-
afterAll( () => {
|
|
22
|
-
jest.clearAllMocks();
|
|
23
|
-
} );
|
|
24
|
-
|
|
25
|
-
it( 'should render Delete, display the modal and run the delete action', () => {
|
|
26
|
-
// Arrange.
|
|
27
|
-
const post: Post = {
|
|
28
|
-
id: 1,
|
|
29
|
-
title: {
|
|
30
|
-
rendered: 'Test Page',
|
|
31
|
-
},
|
|
32
|
-
status: 'publish',
|
|
33
|
-
type: 'page',
|
|
34
|
-
link: 'https://example.local/test-page',
|
|
35
|
-
isHome: false,
|
|
36
|
-
user_can: {
|
|
37
|
-
edit: true,
|
|
38
|
-
delete: true,
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
// Act.
|
|
43
|
-
render( <Delete post={ post } /> );
|
|
44
|
-
|
|
45
|
-
// Assert.
|
|
46
|
-
const button = screen.getByRole( 'menuitem' );
|
|
47
|
-
expect( button ).not.toHaveAttribute( 'aria-disabled' );
|
|
48
|
-
|
|
49
|
-
// Open the modal.
|
|
50
|
-
fireEvent.click( button );
|
|
51
|
-
|
|
52
|
-
const modal = screen.getByText( 'Delete "Test Page"?' );
|
|
53
|
-
expect( modal ).toBeInTheDocument();
|
|
54
|
-
|
|
55
|
-
const modalButtons = screen.getAllByRole( 'button' );
|
|
56
|
-
expect( modalButtons[ 0 ] ).toHaveTextContent( 'Cancel' );
|
|
57
|
-
expect( modalButtons[ 1 ] ).toHaveTextContent( 'Delete' );
|
|
58
|
-
|
|
59
|
-
// Click the delete button.
|
|
60
|
-
fireEvent.click( modalButtons[ 1 ] );
|
|
61
|
-
|
|
62
|
-
expect( mockMutateAsync ).toHaveBeenCalledTimes( 1 );
|
|
63
|
-
expect( mockMutateAsync ).toHaveBeenCalledWith( post.id );
|
|
64
|
-
} );
|
|
65
|
-
|
|
66
|
-
it( 'should render Delete disabled when post is homepage', () => {
|
|
67
|
-
// Arrange.
|
|
68
|
-
const post: Post = {
|
|
69
|
-
id: 1,
|
|
70
|
-
title: {
|
|
71
|
-
rendered: 'Test Page',
|
|
72
|
-
},
|
|
73
|
-
status: 'draft',
|
|
74
|
-
type: 'page',
|
|
75
|
-
link: 'https://example.local/test-page',
|
|
76
|
-
isHome: true,
|
|
77
|
-
user_can: {
|
|
78
|
-
edit: true,
|
|
79
|
-
delete: true,
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
// Act.
|
|
84
|
-
render( <Delete post={ post } /> );
|
|
85
|
-
|
|
86
|
-
// Assert.
|
|
87
|
-
const button = screen.getByRole( 'menuitem' );
|
|
88
|
-
expect( button ).toHaveAttribute( 'aria-disabled', 'true' );
|
|
89
|
-
} );
|
|
90
|
-
} );
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { fireEvent, render, screen } from '@testing-library/react';
|
|
2
|
-
import SetHome from '../set-home';
|
|
3
|
-
import * as React from 'react';
|
|
4
|
-
import { Post } from '../../../../../types';
|
|
5
|
-
import useUser from '../../../../../hooks/use-user';
|
|
6
|
-
|
|
7
|
-
const mockMutateAsync = jest.fn();
|
|
8
|
-
jest.mock( '../../../../../hooks/use-homepage-actions', () => ( {
|
|
9
|
-
__esModule: true,
|
|
10
|
-
useHomepageActions: jest.fn( () => ( {
|
|
11
|
-
updateSettingsMutation: {
|
|
12
|
-
mutateAsync: mockMutateAsync,
|
|
13
|
-
isPending: false,
|
|
14
|
-
},
|
|
15
|
-
} ) ),
|
|
16
|
-
} ) );
|
|
17
|
-
|
|
18
|
-
jest.mock( '../../../../../hooks/use-user', () => ( {
|
|
19
|
-
default: jest.fn( () => ( {
|
|
20
|
-
isLoading: false,
|
|
21
|
-
data: {
|
|
22
|
-
capabilities: {
|
|
23
|
-
manage_options: true,
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
} ) ),
|
|
27
|
-
__esModule: true,
|
|
28
|
-
} ) );
|
|
29
|
-
|
|
30
|
-
describe( '@elementor/editor-site-navigation - SetHome', () => {
|
|
31
|
-
afterAll( () => {
|
|
32
|
-
jest.clearAllMocks();
|
|
33
|
-
} );
|
|
34
|
-
|
|
35
|
-
it( 'should render Set as homepage', () => {
|
|
36
|
-
// Arrange.
|
|
37
|
-
const post: Post = {
|
|
38
|
-
id: 1,
|
|
39
|
-
title: {
|
|
40
|
-
rendered: 'Test Page',
|
|
41
|
-
},
|
|
42
|
-
status: 'publish',
|
|
43
|
-
type: 'page',
|
|
44
|
-
link: 'https://example.local/test-page',
|
|
45
|
-
isHome: false,
|
|
46
|
-
user_can: {
|
|
47
|
-
edit: true,
|
|
48
|
-
delete: true,
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
// Act.
|
|
53
|
-
render( <SetHome post={ post } closeMenu={ () => {} } /> );
|
|
54
|
-
|
|
55
|
-
// Assert.
|
|
56
|
-
const button = screen.getByRole( 'menuitem' );
|
|
57
|
-
expect( button ).not.toHaveAttribute( 'aria-disabled' );
|
|
58
|
-
|
|
59
|
-
fireEvent.click( button );
|
|
60
|
-
|
|
61
|
-
expect( mockMutateAsync ).toHaveBeenCalledTimes( 1 );
|
|
62
|
-
} );
|
|
63
|
-
|
|
64
|
-
it( 'should render Set as homepage disabled when the page status is draft', () => {
|
|
65
|
-
// Arrange.
|
|
66
|
-
const post: Post = {
|
|
67
|
-
id: 1,
|
|
68
|
-
title: {
|
|
69
|
-
rendered: 'Test Page',
|
|
70
|
-
},
|
|
71
|
-
status: 'draft',
|
|
72
|
-
type: 'page',
|
|
73
|
-
link: 'https://example.local/test-page',
|
|
74
|
-
isHome: false,
|
|
75
|
-
user_can: {
|
|
76
|
-
edit: true,
|
|
77
|
-
delete: true,
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
// Act.
|
|
82
|
-
render( <SetHome post={ post } closeMenu={ () => {} } /> );
|
|
83
|
-
|
|
84
|
-
// Assert.
|
|
85
|
-
const button = screen.getByRole( 'menuitem' );
|
|
86
|
-
expect( button ).toHaveAttribute( 'aria-disabled', 'true' );
|
|
87
|
-
} );
|
|
88
|
-
|
|
89
|
-
it( 'should render Set as homepage disabled when the user cant manage options', () => {
|
|
90
|
-
// Arrange.
|
|
91
|
-
jest.mocked( useUser ).mockReturnValue( {
|
|
92
|
-
isLoading: false,
|
|
93
|
-
data: {
|
|
94
|
-
capabilities: {
|
|
95
|
-
manage_options: false,
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
} as unknown as ReturnType< typeof useUser > );
|
|
99
|
-
|
|
100
|
-
const post: Post = {
|
|
101
|
-
id: 1,
|
|
102
|
-
title: {
|
|
103
|
-
rendered: 'Test Page',
|
|
104
|
-
},
|
|
105
|
-
status: 'publish',
|
|
106
|
-
type: 'page',
|
|
107
|
-
link: 'https://example.local/test-page',
|
|
108
|
-
isHome: false,
|
|
109
|
-
user_can: {
|
|
110
|
-
edit: true,
|
|
111
|
-
delete: true,
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
// Act.
|
|
116
|
-
render( <SetHome post={ post } closeMenu={ () => {} } /> );
|
|
117
|
-
|
|
118
|
-
// Assert.
|
|
119
|
-
const button = screen.getByRole( 'menuitem' );
|
|
120
|
-
expect( button ).toHaveAttribute( 'aria-disabled', 'true' );
|
|
121
|
-
} );
|
|
122
|
-
} );
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { act, render, screen } from '@testing-library/react';
|
|
3
|
-
import View from '../view';
|
|
4
|
-
import { Post } from '../../../../../types';
|
|
5
|
-
|
|
6
|
-
describe( '@elementor/editor-site-navigation - View', () => {
|
|
7
|
-
afterAll( () => {
|
|
8
|
-
jest.clearAllMocks();
|
|
9
|
-
} );
|
|
10
|
-
|
|
11
|
-
it( 'should open page in a different tab', () => {
|
|
12
|
-
// Arrange.
|
|
13
|
-
const spy = jest.spyOn( window, 'open' );
|
|
14
|
-
spy.mockImplementation( () => null );
|
|
15
|
-
const page: Post = {
|
|
16
|
-
id: 1,
|
|
17
|
-
title: { rendered: 'Page Title' },
|
|
18
|
-
link: 'mocklink',
|
|
19
|
-
status: 'publish',
|
|
20
|
-
type: 'page',
|
|
21
|
-
user_can: {
|
|
22
|
-
edit: true,
|
|
23
|
-
delete: true,
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// Act.
|
|
28
|
-
render( <View post={ page } /> );
|
|
29
|
-
const button = screen.getByRole( 'menuitem' );
|
|
30
|
-
|
|
31
|
-
act( () => {
|
|
32
|
-
// Open menu
|
|
33
|
-
button.click();
|
|
34
|
-
} );
|
|
35
|
-
|
|
36
|
-
// Assert.
|
|
37
|
-
expect( spy ).toHaveBeenCalledTimes( 1 );
|
|
38
|
-
expect( spy ).toHaveBeenCalledWith( 'mocklink', '_blank' );
|
|
39
|
-
} );
|
|
40
|
-
} );
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { act, fireEvent, screen, waitFor } from '@testing-library/react';
|
|
3
|
-
import { Post } from '../../../../types';
|
|
4
|
-
import PostListItem from '../post-list-item';
|
|
5
|
-
import { __useNavigateToDocument as useNavigateToDocument } from '@elementor/editor-documents';
|
|
6
|
-
import { renderWithQuery } from 'test-utils';
|
|
7
|
-
import { PostListContextProvider } from '../../../../contexts/post-list-context';
|
|
8
|
-
|
|
9
|
-
const mockMutateAsync = jest.fn();
|
|
10
|
-
jest.mock( '../../../../hooks/use-posts-actions', () => ( {
|
|
11
|
-
usePostActions: () => ( {
|
|
12
|
-
updatePost: {
|
|
13
|
-
mutateAsync: mockMutateAsync,
|
|
14
|
-
isPending: false,
|
|
15
|
-
},
|
|
16
|
-
} ),
|
|
17
|
-
} ) );
|
|
18
|
-
|
|
19
|
-
jest.mock( '@elementor/editor-documents', () => ( {
|
|
20
|
-
__useActiveDocument: jest.fn(),
|
|
21
|
-
__useNavigateToDocument: jest.fn(),
|
|
22
|
-
} ) );
|
|
23
|
-
|
|
24
|
-
describe( '@elementor/editor-site-navigation - PostListItem', () => {
|
|
25
|
-
afterAll( () => {
|
|
26
|
-
jest.clearAllMocks();
|
|
27
|
-
} );
|
|
28
|
-
|
|
29
|
-
it( 'should render a published page', () => {
|
|
30
|
-
// Arrange.
|
|
31
|
-
const post: Post = {
|
|
32
|
-
id: 1,
|
|
33
|
-
title: {
|
|
34
|
-
rendered: 'Test Page',
|
|
35
|
-
},
|
|
36
|
-
status: 'publish',
|
|
37
|
-
type: 'page',
|
|
38
|
-
link: 'https://example.local/test-page',
|
|
39
|
-
user_can: {
|
|
40
|
-
edit: true,
|
|
41
|
-
delete: true,
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// Act.
|
|
46
|
-
renderWithQuery( <PostListItem post={ post } /> );
|
|
47
|
-
|
|
48
|
-
// Assert.
|
|
49
|
-
const label = screen.getByText( 'Test Page' );
|
|
50
|
-
const publishedLabel = screen.queryByText( 'publish', { exact: false } );
|
|
51
|
-
|
|
52
|
-
expect( label ).toBeInTheDocument();
|
|
53
|
-
expect( publishedLabel ).not.toBeInTheDocument();
|
|
54
|
-
} );
|
|
55
|
-
|
|
56
|
-
it( 'should show the page status for non-published pages', () => {
|
|
57
|
-
// Arrange.
|
|
58
|
-
const post: Post = {
|
|
59
|
-
id: 1,
|
|
60
|
-
title: {
|
|
61
|
-
rendered: 'Test Page',
|
|
62
|
-
},
|
|
63
|
-
status: 'draft',
|
|
64
|
-
type: 'page',
|
|
65
|
-
link: 'https://example.local/test-page',
|
|
66
|
-
user_can: {
|
|
67
|
-
edit: true,
|
|
68
|
-
delete: true,
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
// Act.
|
|
73
|
-
renderWithQuery( <PostListItem post={ post } /> );
|
|
74
|
-
|
|
75
|
-
// Assert.
|
|
76
|
-
const label = screen.getByText( 'draft', { exact: false } );
|
|
77
|
-
expect( label ).toBeInTheDocument();
|
|
78
|
-
} );
|
|
79
|
-
|
|
80
|
-
it( 'should render actions menu', () => {
|
|
81
|
-
// Arrange.
|
|
82
|
-
const post: Post = {
|
|
83
|
-
id: 1,
|
|
84
|
-
title: {
|
|
85
|
-
rendered: 'Test Page',
|
|
86
|
-
},
|
|
87
|
-
status: 'publish',
|
|
88
|
-
type: 'page',
|
|
89
|
-
link: 'https://example.local/test-Page',
|
|
90
|
-
user_can: {
|
|
91
|
-
edit: true,
|
|
92
|
-
delete: true,
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const actions = [ 'View Page', 'Rename', 'Duplicate', 'Delete', 'Set as homepage' ];
|
|
97
|
-
|
|
98
|
-
// Act.
|
|
99
|
-
renderWithQuery( <PostListItem post={ post } /> );
|
|
100
|
-
|
|
101
|
-
const buttons = screen.getAllByRole( 'button' );
|
|
102
|
-
// Button to open menu
|
|
103
|
-
const button = buttons[ 1 ];
|
|
104
|
-
|
|
105
|
-
act( () => {
|
|
106
|
-
// Open menu
|
|
107
|
-
button.click();
|
|
108
|
-
} );
|
|
109
|
-
|
|
110
|
-
// Assert.
|
|
111
|
-
actions.forEach( ( action ) => {
|
|
112
|
-
const label = screen.getByText( action );
|
|
113
|
-
expect( label ).toBeInTheDocument();
|
|
114
|
-
} );
|
|
115
|
-
} );
|
|
116
|
-
|
|
117
|
-
it( 'should navigate to document on click', () => {
|
|
118
|
-
// Arrange.
|
|
119
|
-
const navigateToDocument = jest.fn();
|
|
120
|
-
jest.mocked( useNavigateToDocument ).mockReturnValue( navigateToDocument );
|
|
121
|
-
|
|
122
|
-
const id = 10;
|
|
123
|
-
|
|
124
|
-
const post: Post = {
|
|
125
|
-
id,
|
|
126
|
-
title: {
|
|
127
|
-
rendered: 'Test Page',
|
|
128
|
-
},
|
|
129
|
-
status: 'publish',
|
|
130
|
-
type: 'page',
|
|
131
|
-
link: 'https://example.local/test-page',
|
|
132
|
-
user_can: {
|
|
133
|
-
edit: true,
|
|
134
|
-
delete: true,
|
|
135
|
-
},
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
// Act.
|
|
139
|
-
renderWithQuery( <PostListItem post={ post } /> );
|
|
140
|
-
|
|
141
|
-
const buttons = screen.getAllByRole( 'button' );
|
|
142
|
-
const button = buttons[ 0 ];
|
|
143
|
-
|
|
144
|
-
act( () => {
|
|
145
|
-
button.click();
|
|
146
|
-
} );
|
|
147
|
-
|
|
148
|
-
// Assert.
|
|
149
|
-
expect( navigateToDocument ).toHaveBeenCalledTimes( 1 );
|
|
150
|
-
expect( navigateToDocument ).toHaveBeenCalledWith( id );
|
|
151
|
-
} );
|
|
152
|
-
|
|
153
|
-
it( 'should put the list item in edit mode, when "Rename" action is clicked', () => {
|
|
154
|
-
// Arrange.
|
|
155
|
-
const post: Post = {
|
|
156
|
-
id: 10,
|
|
157
|
-
title: {
|
|
158
|
-
rendered: 'Test Page',
|
|
159
|
-
},
|
|
160
|
-
status: 'publish',
|
|
161
|
-
type: 'page',
|
|
162
|
-
link: 'https://example.local/test-page',
|
|
163
|
-
user_can: {
|
|
164
|
-
edit: true,
|
|
165
|
-
delete: true,
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
renderWithQuery(
|
|
170
|
-
<PostListContextProvider type={ 'page' } setError={ () => {} }>
|
|
171
|
-
<PostListItem post={ post } />
|
|
172
|
-
</PostListContextProvider>
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
// Act #1 - enter edit mode.
|
|
176
|
-
const buttons = screen.getAllByRole( 'button' );
|
|
177
|
-
fireEvent.click( buttons[ 1 ] ); // Button to open the actions' menu of the post.
|
|
178
|
-
|
|
179
|
-
const renameButton = screen.getByRole( 'menuitem', { name: 'Rename' } );
|
|
180
|
-
fireEvent.click( renameButton );
|
|
181
|
-
|
|
182
|
-
// Assert.
|
|
183
|
-
waitFor( () => {
|
|
184
|
-
expect( renameButton ).not.toBeInTheDocument();
|
|
185
|
-
} ).then();
|
|
186
|
-
|
|
187
|
-
const input = screen.getByRole( 'textbox' );
|
|
188
|
-
|
|
189
|
-
expect( input ).toBeInTheDocument();
|
|
190
|
-
expect( input ).toHaveValue( 'Test Page' );
|
|
191
|
-
|
|
192
|
-
// Act #2 - rename and reset edit mode.
|
|
193
|
-
fireEvent.change( input, { target: { value: 'Renamed Title' } } );
|
|
194
|
-
fireEvent.blur( input );
|
|
195
|
-
|
|
196
|
-
// Assert.
|
|
197
|
-
waitFor( () => {
|
|
198
|
-
expect( input ).toHaveAttribute( 'aria-disabled', 'true' );
|
|
199
|
-
} ).then();
|
|
200
|
-
|
|
201
|
-
expect( mockMutateAsync ).toHaveBeenCalledTimes( 1 );
|
|
202
|
-
|
|
203
|
-
waitFor( () => {
|
|
204
|
-
expect( input ).not.toBeInTheDocument();
|
|
205
|
-
} ).then();
|
|
206
|
-
|
|
207
|
-
waitFor( () => {
|
|
208
|
-
expect( screen.getByText( 'Renamed Title' ) ).toBeInTheDocument();
|
|
209
|
-
} ).then();
|
|
210
|
-
} );
|
|
211
|
-
} );
|