@elementor/editor-site-navigation 0.18.0 → 0.18.2

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 CHANGED
@@ -3,6 +3,22 @@
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.18.2](https://github.com/elementor/elementor-packages/compare/@elementor/editor-site-navigation@0.18.1...@elementor/editor-site-navigation@0.18.2) (2023-08-16)
7
+
8
+ **Note:** Version bump only for package @elementor/editor-site-navigation
9
+
10
+
11
+
12
+
13
+
14
+ ## [0.18.1](https://github.com/elementor/elementor-packages/compare/@elementor/editor-site-navigation@0.18.0...@elementor/editor-site-navigation@0.18.1) (2023-08-02)
15
+
16
+ **Note:** Version bump only for package @elementor/editor-site-navigation
17
+
18
+
19
+
20
+
21
+
6
22
  # [0.18.0](https://github.com/elementor/elementor-packages/compare/@elementor/editor-site-navigation@0.17.1...@elementor/editor-site-navigation@0.18.0) (2023-08-02)
7
23
 
8
24
 
package/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Editor Site Navigation
2
2
 
3
- > **Warning**
4
- >
3
+ > [!WARNING]
5
4
  > This package is under development and not ready for production use.
6
5
 
7
6
  ## Code examples
package/dist/index.js CHANGED
@@ -128,6 +128,7 @@ function DocTypeChip({ postType, docType, label }) {
128
128
  size: "medium",
129
129
  variant: "standard",
130
130
  label,
131
+ "data-value": docType,
131
132
  color,
132
133
  icon: /* @__PURE__ */ React2.createElement(Icon, null),
133
134
  sx: { ml: 3 }
package/dist/index.mjs CHANGED
@@ -110,6 +110,7 @@ function DocTypeChip({ postType, docType, label }) {
110
110
  size: "medium",
111
111
  variant: "standard",
112
112
  label,
113
+ "data-value": docType,
113
114
  color,
114
115
  icon: /* @__PURE__ */ React2.createElement(Icon, null),
115
116
  sx: { ml: 3 }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elementor/editor-site-navigation",
3
- "version": "0.18.0",
3
+ "version": "0.18.2",
4
4
  "private": false,
5
5
  "author": "Elementor Team",
6
6
  "homepage": "https://elementor.com/",
@@ -32,9 +32,9 @@
32
32
  "dev": "tsup --config=../../tsup.dev.ts"
33
33
  },
34
34
  "dependencies": {
35
- "@elementor/editor-app-bar": "^0.7.0",
35
+ "@elementor/editor-app-bar": "^0.7.1",
36
36
  "@elementor/editor-documents": "^0.8.3",
37
- "@elementor/editor-panels": "^0.2.0",
37
+ "@elementor/editor-panels": "^0.2.1",
38
38
  "@elementor/env": "^0.2.0",
39
39
  "@elementor/icons": "^0.7.0",
40
40
  "@elementor/query": "^0.1.1",
@@ -49,5 +49,5 @@
49
49
  "elementor": {
50
50
  "type": "extension"
51
51
  },
52
- "gitHead": "2509694411a0750d4fb99c253ad21cb9d950686f"
52
+ "gitHead": "2b3966576de0a266d74564706aa011833fccda8f"
53
53
  }
@@ -1,9 +1,20 @@
1
1
  import * as React from 'react';
2
- import { act, screen } from '@testing-library/react';
2
+ import { act, fireEvent, screen, waitFor } from '@testing-library/react';
3
3
  import { Post } from '../../../../types';
4
4
  import PostListItem from '../post-list-item';
5
5
  import { useNavigateToDocument } from '@elementor/editor-documents';
6
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
+ isLoading: false,
15
+ },
16
+ } ),
17
+ } ) );
7
18
 
8
19
  jest.mock( '@elementor/editor-documents', () => ( {
9
20
  useActiveDocument: jest.fn(),
@@ -122,4 +133,59 @@ describe( '@elementor/editor-site-navigation - PostListItem', () => {
122
133
  expect( navigateToDocument ).toHaveBeenCalledTimes( 1 );
123
134
  expect( navigateToDocument ).toHaveBeenCalledWith( id );
124
135
  } );
136
+
137
+ it( 'should put the list item in edit mode, when "Rename" action is clicked', () => {
138
+ // Arrange.
139
+ const post: Post = {
140
+ id: 10,
141
+ title: {
142
+ rendered: 'Test Page',
143
+ },
144
+ status: 'publish',
145
+ type: 'page',
146
+ link: 'https://example.local/test-page',
147
+ };
148
+
149
+ renderWithQuery(
150
+ <PostListContextProvider type={ 'page' }>
151
+ <PostListItem post={ post } />
152
+ </PostListContextProvider>
153
+ );
154
+
155
+ // Act #1 - enter edit mode.
156
+ const buttons = screen.getAllByRole( 'button' );
157
+ fireEvent.click( buttons[ 1 ] ); // Button to open the actions' menu of the post.
158
+
159
+ const renameButton = screen.getByRole( 'button', { name: 'Rename' } );
160
+ fireEvent.click( renameButton );
161
+
162
+ // Assert.
163
+ waitFor( () => {
164
+ expect( renameButton ).not.toBeInTheDocument();
165
+ } ).then();
166
+
167
+ const input = screen.getByRole( 'textbox' );
168
+
169
+ expect( input ).toBeInTheDocument();
170
+ expect( input ).toHaveValue( 'Test Page' );
171
+
172
+ // Act #2 - rename and reset edit mode.
173
+ fireEvent.change( input, { target: { value: 'Renamed Title' } } );
174
+ fireEvent.blur( input );
175
+
176
+ // Assert.
177
+ waitFor( () => {
178
+ expect( input ).toHaveAttribute( 'aria-disabled', 'true' );
179
+ } ).then();
180
+
181
+ expect( mockMutateAsync ).toHaveBeenCalledTimes( 1 );
182
+
183
+ waitFor( () => {
184
+ expect( input ).not.toBeInTheDocument();
185
+ } ).then();
186
+
187
+ waitFor( () => {
188
+ expect( screen.getByText( 'Renamed Title' ) ).toBeInTheDocument();
189
+ } ).then();
190
+ } );
125
191
  } );
@@ -1,7 +1,22 @@
1
1
  import * as React from 'react';
2
- import { screen } from '@testing-library/react';
2
+ import { fireEvent, screen, waitFor } from '@testing-library/react';
3
3
  import PostsCollapsibleList from '../posts-collapsible-list';
4
4
  import { renderWithQuery } from 'test-utils';
5
+ import { PostListContextProvider } from '../../../../contexts/post-list-context';
6
+
7
+ const mockMutateAsync = jest.fn();
8
+ jest.mock( '../../../../hooks/use-posts-actions', () => ( {
9
+ usePostActions: () => ( {
10
+ createPost: {
11
+ mutateAsync: mockMutateAsync,
12
+ isLoading: false,
13
+ },
14
+ duplicatePost: {
15
+ mutateAsync: mockMutateAsync,
16
+ isLoading: false,
17
+ },
18
+ } ),
19
+ } ) );
5
20
 
6
21
  jest.mock( '../../../../hooks/use-posts', () => ( {
7
22
  __esModule: true,
@@ -66,4 +81,69 @@ describe( '@elementor/editor-site-navigation - PostsCollapsibleList', () => {
66
81
  expect( items[ 2 ] ).toHaveTextContent( 'About' );
67
82
  expect( items[ 2 ] ).toHaveTextContent( '(draft)' );
68
83
  } );
84
+
85
+ it( 'should create a new post after clicking "Add New" button', async () => {
86
+ // Arrange.
87
+ renderWithQuery(
88
+ <PostListContextProvider type={ 'page' }>
89
+ <PostsCollapsibleList isOpenByDefault={ true } />
90
+ </PostListContextProvider>
91
+ );
92
+
93
+ // Act.
94
+ const addNewButton = screen.getByRole( 'button', { name: 'Add New' } );
95
+ fireEvent.click( addNewButton );
96
+
97
+ const input = screen.getByRole( 'textbox' );
98
+
99
+ if ( ! input || ! ( input instanceof HTMLInputElement ) ) {
100
+ throw new Error( 'No input field found.' );
101
+ }
102
+
103
+ expect( input ).toHaveValue( 'New Page' );
104
+
105
+ fireEvent.change( input, { target: { value: 'New Page Title' } } );
106
+ fireEvent.blur( input );
107
+
108
+ // Assert.
109
+ waitFor( () => {
110
+ expect( input ).toHaveAttribute( 'aria-disabled', 'true' );
111
+ } ).then();
112
+
113
+ expect( mockMutateAsync ).toHaveBeenCalledTimes( 1 );
114
+
115
+ waitFor( () => {
116
+ expect( input ).not.toBeInTheDocument();
117
+ } ).then();
118
+
119
+ waitFor( () => {
120
+ expect( screen.getByText( 'New Page Title' ) ).toBeInTheDocument();
121
+ } ).then();
122
+ } );
123
+
124
+ it( 'should append a new list item in edit mode, when "Duplicate" action is clicked', () => {
125
+ // Arrange.
126
+ renderWithQuery(
127
+ <PostListContextProvider type={ 'page' }>
128
+ <PostsCollapsibleList isOpenByDefault={ true } />
129
+ </PostListContextProvider>
130
+ );
131
+
132
+ // Act.
133
+ const buttons = screen.getAllByRole( 'button' );
134
+ fireEvent.click( buttons[ 3 ] ); // Button to open the actions' menu of the first post.
135
+
136
+ const duplicateButton = screen.getByRole( 'button', { name: 'Duplicate' } );
137
+ fireEvent.click( duplicateButton );
138
+
139
+ // Assert.
140
+ waitFor( () => {
141
+ expect( duplicateButton ).not.toBeInTheDocument();
142
+ } ).then();
143
+
144
+ const input = screen.getByRole( 'textbox' );
145
+
146
+ expect( input ).toBeInTheDocument();
147
+ expect( input ).toHaveValue( 'Home copy' );
148
+ } );
69
149
  } );
@@ -22,6 +22,7 @@ export default function DocTypeChip( { postType, docType, label }: Props ) {
22
22
  size="medium"
23
23
  variant="standard"
24
24
  label={ label }
25
+ data-value={ docType }
25
26
  color={ color }
26
27
  icon={ <Icon /> }
27
28
  sx={ { ml: 3 } }