@wordpress/editor 12.17.0 → 12.17.1-next.4d3b314fd5.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/editor",
|
|
3
|
-
"version": "12.17.0",
|
|
3
|
+
"version": "12.17.1-next.4d3b314fd5.0",
|
|
4
4
|
"description": "Enhanced block editor for WordPress posts.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -31,32 +31,32 @@
|
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@babel/runtime": "^7.16.0",
|
|
34
|
-
"@wordpress/a11y": "^3.18.0",
|
|
35
|
-
"@wordpress/api-fetch": "^6.15.0",
|
|
36
|
-
"@wordpress/blob": "^3.18.0",
|
|
37
|
-
"@wordpress/block-editor": "^10.1.0",
|
|
38
|
-
"@wordpress/blocks": "^11.
|
|
39
|
-
"@wordpress/components": "^21.1.0",
|
|
40
|
-
"@wordpress/compose": "^5.16.0",
|
|
41
|
-
"@wordpress/core-data": "^5.1.0",
|
|
42
|
-
"@wordpress/data": "^7.2.0",
|
|
43
|
-
"@wordpress/date": "^4.18.0",
|
|
44
|
-
"@wordpress/deprecated": "^3.18.0",
|
|
45
|
-
"@wordpress/element": "^4.16.0",
|
|
46
|
-
"@wordpress/hooks": "^3.18.0",
|
|
47
|
-
"@wordpress/html-entities": "^3.18.0",
|
|
48
|
-
"@wordpress/i18n": "^4.18.0",
|
|
49
|
-
"@wordpress/icons": "^9.9.0",
|
|
50
|
-
"@wordpress/keyboard-shortcuts": "^3.16.0",
|
|
51
|
-
"@wordpress/keycodes": "^3.18.0",
|
|
52
|
-
"@wordpress/media-utils": "^4.9.0",
|
|
53
|
-
"@wordpress/notices": "^3.18.0",
|
|
54
|
-
"@wordpress/preferences": "^2.10.0",
|
|
55
|
-
"@wordpress/reusable-blocks": "^3.16.0",
|
|
56
|
-
"@wordpress/rich-text": "^5.16.0",
|
|
57
|
-
"@wordpress/server-side-render": "^3.16.0",
|
|
58
|
-
"@wordpress/url": "^3.19.0",
|
|
59
|
-
"@wordpress/wordcount": "^3.18.0",
|
|
34
|
+
"@wordpress/a11y": "^3.18.1-next.4d3b314fd5.0",
|
|
35
|
+
"@wordpress/api-fetch": "^6.15.1-next.4d3b314fd5.0",
|
|
36
|
+
"@wordpress/blob": "^3.18.1-next.4d3b314fd5.0",
|
|
37
|
+
"@wordpress/block-editor": "^10.1.1-next.4d3b314fd5.0",
|
|
38
|
+
"@wordpress/blocks": "^11.18.1-next.4d3b314fd5.0",
|
|
39
|
+
"@wordpress/components": "^21.1.2-next.4d3b314fd5.0",
|
|
40
|
+
"@wordpress/compose": "^5.16.1-next.4d3b314fd5.0",
|
|
41
|
+
"@wordpress/core-data": "^5.1.1-next.4d3b314fd5.0",
|
|
42
|
+
"@wordpress/data": "^7.2.1-next.4d3b314fd5.0",
|
|
43
|
+
"@wordpress/date": "^4.18.1-next.4d3b314fd5.0",
|
|
44
|
+
"@wordpress/deprecated": "^3.18.1-next.4d3b314fd5.0",
|
|
45
|
+
"@wordpress/element": "^4.16.1-next.4d3b314fd5.0",
|
|
46
|
+
"@wordpress/hooks": "^3.18.1-next.4d3b314fd5.0",
|
|
47
|
+
"@wordpress/html-entities": "^3.18.1-next.4d3b314fd5.0",
|
|
48
|
+
"@wordpress/i18n": "^4.18.1-next.4d3b314fd5.0",
|
|
49
|
+
"@wordpress/icons": "^9.9.1-next.4d3b314fd5.0",
|
|
50
|
+
"@wordpress/keyboard-shortcuts": "^3.16.1-next.4d3b314fd5.0",
|
|
51
|
+
"@wordpress/keycodes": "^3.18.1-next.4d3b314fd5.0",
|
|
52
|
+
"@wordpress/media-utils": "^4.9.1-next.4d3b314fd5.0",
|
|
53
|
+
"@wordpress/notices": "^3.18.1-next.4d3b314fd5.0",
|
|
54
|
+
"@wordpress/preferences": "^2.10.1-next.4d3b314fd5.0",
|
|
55
|
+
"@wordpress/reusable-blocks": "^3.16.1-next.4d3b314fd5.0",
|
|
56
|
+
"@wordpress/rich-text": "^5.16.1-next.4d3b314fd5.0",
|
|
57
|
+
"@wordpress/server-side-render": "^3.16.1-next.4d3b314fd5.0",
|
|
58
|
+
"@wordpress/url": "^3.19.1-next.4d3b314fd5.0",
|
|
59
|
+
"@wordpress/wordcount": "^3.18.1-next.4d3b314fd5.0",
|
|
60
60
|
"classnames": "^2.3.1",
|
|
61
61
|
"lodash": "^4.17.21",
|
|
62
62
|
"memize": "^1.1.0",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"publishConfig": {
|
|
72
72
|
"access": "public"
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "25054766423cb49d959eb656c2533530073ff5c2"
|
|
75
75
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { render, screen, within } from '@testing-library/react';
|
|
5
|
+
import userEvent from '@testing-library/user-event';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Internal dependencies
|
|
@@ -9,180 +10,310 @@ import { shallow } from 'enzyme';
|
|
|
9
10
|
import { PostPreviewButton } from '../';
|
|
10
11
|
|
|
11
12
|
describe( 'PostPreviewButton', () => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const wrapper = shallow( <PostPreviewButton /> );
|
|
13
|
+
const documentWrite = jest.fn();
|
|
14
|
+
const documentTitle = jest.fn();
|
|
15
|
+
const documentClose = jest.fn();
|
|
16
|
+
const setLocation = jest.fn();
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
beforeEach( () => {
|
|
19
|
+
global.open = jest.fn( () => ( {
|
|
20
|
+
focus: jest.fn(),
|
|
21
|
+
document: {
|
|
22
|
+
write: documentWrite,
|
|
23
|
+
close: documentClose,
|
|
24
|
+
get title() {},
|
|
25
|
+
set title( value ) {
|
|
26
|
+
documentTitle( value );
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
get location() {},
|
|
30
|
+
set location( value ) {
|
|
31
|
+
setLocation( value );
|
|
32
|
+
},
|
|
33
|
+
} ) );
|
|
34
|
+
} );
|
|
19
35
|
|
|
20
|
-
|
|
21
|
-
|
|
36
|
+
afterEach( () => {
|
|
37
|
+
global.open.mockRestore();
|
|
38
|
+
documentWrite.mockReset();
|
|
39
|
+
documentTitle.mockReset();
|
|
40
|
+
documentClose.mockReset();
|
|
41
|
+
setLocation.mockReset();
|
|
42
|
+
} );
|
|
22
43
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const setter = jest.fn();
|
|
26
|
-
const wrapper = shallow( <PostPreviewButton /> );
|
|
27
|
-
wrapper.instance().previewWindow = {
|
|
28
|
-
get location() {
|
|
29
|
-
return {
|
|
30
|
-
href: 'about:blank',
|
|
31
|
-
};
|
|
32
|
-
},
|
|
33
|
-
set location( value ) {
|
|
34
|
-
setter( value );
|
|
35
|
-
},
|
|
36
|
-
};
|
|
44
|
+
it( 'should render with `editor-post-preview` class if no `className` is specified.', () => {
|
|
45
|
+
render( <PostPreviewButton /> );
|
|
37
46
|
|
|
38
|
-
|
|
47
|
+
expect( screen.getByRole( 'button' ) ).toHaveClass(
|
|
48
|
+
'editor-post-preview'
|
|
49
|
+
);
|
|
50
|
+
} );
|
|
39
51
|
|
|
40
|
-
|
|
41
|
-
|
|
52
|
+
it( 'should render with a custom class and not `editor-post-preview` if `className` is specified.', () => {
|
|
53
|
+
render( <PostPreviewButton className="foo-bar" /> );
|
|
54
|
+
|
|
55
|
+
const button = screen.getByRole( 'button' );
|
|
56
|
+
|
|
57
|
+
expect( button ).toHaveClass( 'foo-bar' );
|
|
58
|
+
expect( button ).not.toHaveClass( 'editor-post-preview' );
|
|
42
59
|
} );
|
|
43
60
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const instance = new PostPreviewButton( {
|
|
47
|
-
postId: 1,
|
|
48
|
-
} );
|
|
61
|
+
it( 'should render a tertiary button if no classname is specified.', () => {
|
|
62
|
+
render( <PostPreviewButton /> );
|
|
49
63
|
|
|
50
|
-
|
|
51
|
-
} );
|
|
64
|
+
expect( screen.getByRole( 'button' ) ).toHaveClass( 'is-tertiary' );
|
|
52
65
|
} );
|
|
53
66
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
postId={ 1 }
|
|
59
|
-
currentPostLink="https://wordpress.org/?p=1"
|
|
60
|
-
isSaveable
|
|
61
|
-
modified="2017-08-03T15:05:50"
|
|
62
|
-
/>
|
|
63
|
-
);
|
|
67
|
+
it( 'should render the button in its default variant if a custom classname is specified.', () => {
|
|
68
|
+
render( <PostPreviewButton className="foo-bar" /> );
|
|
69
|
+
|
|
70
|
+
const button = screen.getByRole( 'button' );
|
|
64
71
|
|
|
65
|
-
|
|
72
|
+
expect( button ).not.toHaveClass( 'is-primary' );
|
|
73
|
+
expect( button ).not.toHaveClass( 'is-secondary' );
|
|
74
|
+
expect( button ).not.toHaveClass( 'is-tertiary' );
|
|
75
|
+
expect( button ).not.toHaveClass( 'is-link' );
|
|
76
|
+
} );
|
|
66
77
|
|
|
67
|
-
|
|
78
|
+
it( 'should render `textContent` if specified.', () => {
|
|
79
|
+
const textContent = 'Foo bar';
|
|
68
80
|
|
|
69
|
-
|
|
81
|
+
render( <PostPreviewButton textContent={ textContent } /> );
|
|
70
82
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
83
|
+
const button = screen.getByRole( 'button' );
|
|
84
|
+
|
|
85
|
+
expect( button ).toHaveTextContent( textContent );
|
|
86
|
+
expect(
|
|
87
|
+
within( button ).queryByText( 'Preview' )
|
|
88
|
+
).not.toBeInTheDocument();
|
|
89
|
+
expect(
|
|
90
|
+
within( button ).queryByText( '(opens in a new tab)' )
|
|
91
|
+
).not.toBeInTheDocument();
|
|
75
92
|
} );
|
|
76
93
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
beforeEach( () => {
|
|
80
|
-
windowOpen = window.open;
|
|
81
|
-
} );
|
|
82
|
-
afterEach( () => {
|
|
83
|
-
window.open = windowOpen;
|
|
84
|
-
} );
|
|
94
|
+
it( 'should render `Preview` with accessibility text if `textContent` not specified.', () => {
|
|
95
|
+
render( <PostPreviewButton /> );
|
|
85
96
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
setLocation( url );
|
|
94
|
-
},
|
|
95
|
-
} ) );
|
|
96
|
-
|
|
97
|
-
const wrapper = shallow(
|
|
98
|
-
<PostPreviewButton postId={ 1 } autosave={ autosave } />
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
wrapper.simulate( 'click', {
|
|
102
|
-
preventDefault,
|
|
103
|
-
target: { href: 'https://wordpress.org/?p=1' },
|
|
104
|
-
} );
|
|
105
|
-
|
|
106
|
-
expect( preventDefault ).toHaveBeenCalled();
|
|
107
|
-
expect( window.open ).toHaveBeenCalledWith( '', 'wp-preview-1' );
|
|
108
|
-
expect( wrapper.instance().previewWindow.focus ).toHaveBeenCalled();
|
|
109
|
-
expect( autosave ).not.toHaveBeenCalled();
|
|
110
|
-
expect( setLocation ).toHaveBeenCalledWith(
|
|
111
|
-
'https://wordpress.org/?p=1'
|
|
112
|
-
);
|
|
113
|
-
} );
|
|
97
|
+
const button = screen.getByRole( 'button' );
|
|
98
|
+
|
|
99
|
+
expect( within( button ).getByText( 'Preview' ) ).toBeVisible();
|
|
100
|
+
expect(
|
|
101
|
+
within( button ).getByText( '(opens in a new tab)' )
|
|
102
|
+
).toBeInTheDocument();
|
|
103
|
+
} );
|
|
114
104
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const autosave = jest.fn();
|
|
105
|
+
it( 'should be disabled if post is not saveable.', async () => {
|
|
106
|
+
render( <PostPreviewButton isSaveable={ false } postId={ 123 } /> );
|
|
118
107
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
108
|
+
expect( screen.getByRole( 'button' ) ).toBeDisabled();
|
|
109
|
+
} );
|
|
110
|
+
|
|
111
|
+
it( 'should not be disabled if post is saveable.', async () => {
|
|
112
|
+
render( <PostPreviewButton isSaveable postId={ 123 } /> );
|
|
113
|
+
|
|
114
|
+
expect( screen.getByRole( 'button' ) ).not.toBeDisabled();
|
|
115
|
+
} );
|
|
116
|
+
|
|
117
|
+
it( 'should set `href` to `previewLink` if `previewLink` is specified.', async () => {
|
|
118
|
+
const url = 'https://wordpress.org';
|
|
119
|
+
|
|
120
|
+
render(
|
|
121
|
+
<PostPreviewButton isSaveable postId={ 123 } previewLink={ url } />
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
expect( screen.getByRole( 'link' ) ).toHaveAttribute( 'href', url );
|
|
125
|
+
} );
|
|
126
|
+
|
|
127
|
+
it( 'should set `href` to `currentPostLink` if `currentPostLink` is specified.', async () => {
|
|
128
|
+
const url = 'https://wordpress.org';
|
|
129
|
+
|
|
130
|
+
render(
|
|
131
|
+
<PostPreviewButton
|
|
132
|
+
isSaveable
|
|
133
|
+
postId={ 123 }
|
|
134
|
+
currentPostLink={ url }
|
|
135
|
+
/>
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
expect( screen.getByRole( 'link' ) ).toHaveAttribute( 'href', url );
|
|
139
|
+
} );
|
|
140
|
+
|
|
141
|
+
it( 'should prioritize `previewLink` if both `previewLink` and `currentPostLink` are specified.', async () => {
|
|
142
|
+
const url1 = 'https://wordpress.org';
|
|
143
|
+
const url2 = 'https://wordpress.com';
|
|
144
|
+
|
|
145
|
+
render(
|
|
146
|
+
<PostPreviewButton
|
|
147
|
+
isSaveable
|
|
148
|
+
postId={ 123 }
|
|
149
|
+
previewLink={ url1 }
|
|
150
|
+
currentPostLink={ url2 }
|
|
151
|
+
/>
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
expect( screen.getByRole( 'link' ) ).toHaveAttribute( 'href', url1 );
|
|
155
|
+
} );
|
|
156
|
+
|
|
157
|
+
it( 'should properly set target to `wp-preview-${ postId }`.', async () => {
|
|
158
|
+
const postId = 123;
|
|
159
|
+
const url = 'https://wordpress.org';
|
|
160
|
+
|
|
161
|
+
render(
|
|
162
|
+
<PostPreviewButton
|
|
163
|
+
isSaveable
|
|
164
|
+
postId={ postId }
|
|
165
|
+
previewLink={ url }
|
|
166
|
+
/>
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
expect( screen.getByRole( 'link' ) ).toHaveAttribute(
|
|
170
|
+
'target',
|
|
171
|
+
`wp-preview-${ postId }`
|
|
172
|
+
);
|
|
173
|
+
} );
|
|
174
|
+
|
|
175
|
+
it( 'should save post if `isDraft` is `true`', async () => {
|
|
176
|
+
const user = userEvent.setup( {
|
|
177
|
+
advanceTimers: jest.advanceTimersByTime,
|
|
148
178
|
} );
|
|
179
|
+
const url = 'https://wordpress.org';
|
|
180
|
+
const savePost = jest.fn();
|
|
181
|
+
const autosave = jest.fn();
|
|
182
|
+
|
|
183
|
+
render(
|
|
184
|
+
<PostPreviewButton
|
|
185
|
+
isAutosaveable
|
|
186
|
+
isSaveable
|
|
187
|
+
isDraft
|
|
188
|
+
postId={ 123 }
|
|
189
|
+
previewLink={ url }
|
|
190
|
+
savePost={ savePost }
|
|
191
|
+
autosave={ autosave }
|
|
192
|
+
/>
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
await user.click( screen.getByRole( 'link' ) );
|
|
196
|
+
|
|
197
|
+
expect( savePost ).toHaveBeenCalledWith(
|
|
198
|
+
expect.objectContaining( { isPreview: true } )
|
|
199
|
+
);
|
|
200
|
+
expect( autosave ).not.toHaveBeenCalled();
|
|
149
201
|
} );
|
|
150
202
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
currentPostLink="https://wordpress.org/?p=1"
|
|
159
|
-
/>
|
|
160
|
-
);
|
|
203
|
+
it( 'should autosave post if `isDraft` is `false`', async () => {
|
|
204
|
+
const user = userEvent.setup( {
|
|
205
|
+
advanceTimers: jest.advanceTimersByTime,
|
|
206
|
+
} );
|
|
207
|
+
const url = 'https://wordpress.org';
|
|
208
|
+
const savePost = jest.fn();
|
|
209
|
+
const autosave = jest.fn();
|
|
161
210
|
|
|
162
|
-
|
|
211
|
+
render(
|
|
212
|
+
<PostPreviewButton
|
|
213
|
+
isAutosaveable
|
|
214
|
+
isSaveable
|
|
215
|
+
isDraft={ false }
|
|
216
|
+
postId={ 123 }
|
|
217
|
+
previewLink={ url }
|
|
218
|
+
savePost={ savePost }
|
|
219
|
+
autosave={ autosave }
|
|
220
|
+
/>
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
await user.click( screen.getByRole( 'link' ) );
|
|
224
|
+
|
|
225
|
+
expect( savePost ).not.toHaveBeenCalled();
|
|
226
|
+
expect( autosave ).toHaveBeenCalledWith(
|
|
227
|
+
expect.objectContaining( { isPreview: true } )
|
|
228
|
+
);
|
|
229
|
+
} );
|
|
230
|
+
|
|
231
|
+
it( 'should open a window with the specified target', async () => {
|
|
232
|
+
const user = userEvent.setup( {
|
|
233
|
+
advanceTimers: jest.advanceTimersByTime,
|
|
163
234
|
} );
|
|
235
|
+
const postId = 123;
|
|
236
|
+
const url = 'https://wordpress.org';
|
|
164
237
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
238
|
+
render(
|
|
239
|
+
<PostPreviewButton
|
|
240
|
+
isAutosaveable
|
|
241
|
+
isSaveable
|
|
242
|
+
postId={ postId }
|
|
243
|
+
previewLink={ url }
|
|
244
|
+
savePost={ jest.fn() }
|
|
245
|
+
autosave={ jest.fn() }
|
|
246
|
+
/>
|
|
247
|
+
);
|
|
173
248
|
|
|
174
|
-
|
|
249
|
+
await user.click( screen.getByRole( 'link' ) );
|
|
250
|
+
|
|
251
|
+
expect( global.open ).toHaveBeenCalledWith(
|
|
252
|
+
'',
|
|
253
|
+
`wp-preview-${ postId }`
|
|
254
|
+
);
|
|
255
|
+
} );
|
|
256
|
+
|
|
257
|
+
it( 'should set the location in the window properly', async () => {
|
|
258
|
+
const user = userEvent.setup( {
|
|
259
|
+
advanceTimers: jest.advanceTimersByTime,
|
|
175
260
|
} );
|
|
261
|
+
const postId = 123;
|
|
262
|
+
const url = 'https://wordpress.org';
|
|
263
|
+
|
|
264
|
+
const { rerender } = render(
|
|
265
|
+
<PostPreviewButton
|
|
266
|
+
isSaveable
|
|
267
|
+
postId={ postId }
|
|
268
|
+
savePost={ jest.fn() }
|
|
269
|
+
autosave={ jest.fn() }
|
|
270
|
+
/>
|
|
271
|
+
);
|
|
176
272
|
|
|
177
|
-
|
|
178
|
-
const wrapper = shallow(
|
|
179
|
-
<PostPreviewButton
|
|
180
|
-
postId={ 1 }
|
|
181
|
-
currentPostLink="https://wordpress.org/?p=1"
|
|
182
|
-
/>
|
|
183
|
-
);
|
|
273
|
+
await user.click( screen.getByRole( 'button' ) );
|
|
184
274
|
|
|
185
|
-
|
|
275
|
+
expect( setLocation ).toHaveBeenCalledWith( undefined );
|
|
276
|
+
|
|
277
|
+
rerender(
|
|
278
|
+
<PostPreviewButton
|
|
279
|
+
isSaveable
|
|
280
|
+
postId={ postId }
|
|
281
|
+
previewLink={ url }
|
|
282
|
+
savePost={ jest.fn() }
|
|
283
|
+
autosave={ jest.fn() }
|
|
284
|
+
/>
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
expect( setLocation ).toHaveBeenCalledWith( url );
|
|
288
|
+
} );
|
|
289
|
+
|
|
290
|
+
it( 'should display a `Generating preview` message while waiting for autosaving', async () => {
|
|
291
|
+
const user = userEvent.setup( {
|
|
292
|
+
advanceTimers: jest.advanceTimersByTime,
|
|
186
293
|
} );
|
|
294
|
+
const previewText = 'Generating preview…';
|
|
295
|
+
const url = 'https://wordpress.org';
|
|
296
|
+
const savePost = jest.fn();
|
|
297
|
+
const autosave = jest.fn();
|
|
298
|
+
|
|
299
|
+
render(
|
|
300
|
+
<PostPreviewButton
|
|
301
|
+
isAutosaveable
|
|
302
|
+
isSaveable
|
|
303
|
+
isDraft={ false }
|
|
304
|
+
postId={ 123 }
|
|
305
|
+
previewLink={ url }
|
|
306
|
+
savePost={ savePost }
|
|
307
|
+
autosave={ autosave }
|
|
308
|
+
/>
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
await user.click( screen.getByRole( 'link' ) );
|
|
312
|
+
|
|
313
|
+
expect( documentWrite ).toHaveBeenCalledWith(
|
|
314
|
+
expect.stringContaining( previewText )
|
|
315
|
+
);
|
|
316
|
+
expect( documentTitle ).toHaveBeenCalledWith( previewText );
|
|
317
|
+
expect( documentClose ).toHaveBeenCalled();
|
|
187
318
|
} );
|
|
188
319
|
} );
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`PostPreviewButton render() should render currentPostLink otherwise 1`] = `
|
|
4
|
-
<ForwardRef(Button)
|
|
5
|
-
className="editor-post-preview"
|
|
6
|
-
disabled={false}
|
|
7
|
-
href="https://wordpress.org/?p=1"
|
|
8
|
-
onClick={[Function]}
|
|
9
|
-
target="wp-preview-1"
|
|
10
|
-
variant="tertiary"
|
|
11
|
-
>
|
|
12
|
-
Preview
|
|
13
|
-
<VisuallyHidden
|
|
14
|
-
as="span"
|
|
15
|
-
>
|
|
16
|
-
(opens in a new tab)
|
|
17
|
-
</VisuallyHidden>
|
|
18
|
-
</ForwardRef(Button)>
|
|
19
|
-
`;
|
|
20
|
-
|
|
21
|
-
exports[`PostPreviewButton render() should render previewLink if provided 1`] = `
|
|
22
|
-
<ForwardRef(Button)
|
|
23
|
-
className="editor-post-preview"
|
|
24
|
-
disabled={false}
|
|
25
|
-
href="https://wordpress.org/?p=1&preview=true"
|
|
26
|
-
onClick={[Function]}
|
|
27
|
-
target="wp-preview-1"
|
|
28
|
-
variant="tertiary"
|
|
29
|
-
>
|
|
30
|
-
Preview
|
|
31
|
-
<VisuallyHidden
|
|
32
|
-
as="span"
|
|
33
|
-
>
|
|
34
|
-
(opens in a new tab)
|
|
35
|
-
</VisuallyHidden>
|
|
36
|
-
</ForwardRef(Button)>
|
|
37
|
-
`;
|