@wordpress/edit-post 8.48.0 → 8.48.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.
@@ -1,263 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import {
5
- act,
6
- addBlock,
7
- fireEvent,
8
- getBlock,
9
- getEditorHtml,
10
- getEditorTitle,
11
- initializeEditor,
12
- pasteIntoRichText,
13
- screen,
14
- setupCoreBlocks,
15
- within,
16
- } from 'test/helpers';
17
- import { BackHandler } from 'react-native';
18
-
19
- /**
20
- * WordPress dependencies
21
- */
22
- import {
23
- requestMediaImport,
24
- subscribeMediaAppend,
25
- subscribeParentToggleHTMLMode,
26
- subscribeToContentUpdate,
27
- } from '@wordpress/react-native-bridge';
28
-
29
- setupCoreBlocks();
30
-
31
- let toggleModeCallback;
32
- subscribeParentToggleHTMLMode.mockImplementation( ( callback ) => {
33
- toggleModeCallback = callback;
34
- } );
35
-
36
- let mediaAppendCallback;
37
- subscribeMediaAppend.mockImplementation( ( callback ) => {
38
- mediaAppendCallback = callback;
39
- } );
40
-
41
- let onContentUpdateCallback;
42
- subscribeToContentUpdate.mockImplementation( ( callback ) => {
43
- onContentUpdateCallback = callback;
44
- } );
45
-
46
- const MEDIA = [
47
- {
48
- localId: 1,
49
- mediaUrl: 'file:///local-image-1.jpeg',
50
- mediaType: 'image',
51
- serverId: 2000,
52
- serverUrl: 'https://test-site.files.wordpress.com/local-image-1.jpeg',
53
- },
54
- {
55
- localId: 2,
56
- mediaUrl: 'file:///local-file-1.pdf',
57
- mediaType: 'other',
58
- serverId: 2001,
59
- serverUrl: 'https://test-site.files.wordpress.com/local-file-1.pdf',
60
- },
61
- {
62
- localId: 3,
63
- mediaUrl: 'file:///local-image-3.jpeg',
64
- mediaType: 'image',
65
- serverId: 2002,
66
- serverUrl: 'https://test-site.files.wordpress.com/local-image-3.jpeg',
67
- },
68
- {
69
- localId: 4,
70
- mediaUrl: 'file:///local-video-4.mp4',
71
- mediaType: 'video',
72
- serverId: 2003,
73
- serverUrl: 'https://test-site.files.wordpress.com/local-video-4.mp4',
74
- },
75
- ];
76
-
77
- describe( 'Editor', () => {
78
- afterEach( () => {
79
- jest.clearAllMocks();
80
- } );
81
-
82
- it( 'toggles the editor from Visual to HTML mode', async () => {
83
- // Arrange
84
- await initializeEditor();
85
- await addBlock( screen, 'Paragraph' );
86
-
87
- // Act
88
- const paragraphBlock = getBlock( screen, 'Paragraph' );
89
- fireEvent.press( paragraphBlock );
90
- act( () => {
91
- toggleModeCallback();
92
- } );
93
-
94
- // Assert
95
- const htmlEditor = screen.getByLabelText( 'html-view-content' );
96
- expect( htmlEditor ).toBeVisible();
97
-
98
- act( () => {
99
- toggleModeCallback();
100
- } );
101
- } );
102
-
103
- it( 'adds empty image block when pasting unsupported HTML local image path', async () => {
104
- await initializeEditor();
105
- await addBlock( screen, 'Paragraph' );
106
-
107
- const paragraphBlock = getBlock( screen, 'Paragraph' );
108
- fireEvent.press( paragraphBlock );
109
- const paragraphTextInput =
110
- within( paragraphBlock ).getByPlaceholderText( 'Start writing…' );
111
-
112
- pasteIntoRichText( paragraphTextInput, {
113
- text: '<div><img src="file:LOW-RES.png"></div>',
114
- } );
115
-
116
- expect( getEditorHtml() ).toMatchSnapshot();
117
- } );
118
-
119
- it( 'adds image block when pasting HTML local image path', async () => {
120
- await initializeEditor();
121
- await addBlock( screen, 'Paragraph' );
122
-
123
- const paragraphBlock = getBlock( screen, 'Paragraph' );
124
- fireEvent.press( paragraphBlock );
125
- const paragraphTextInput =
126
- within( paragraphBlock ).getByPlaceholderText( 'Start writing…' );
127
-
128
- pasteIntoRichText( paragraphTextInput, {
129
- files: [ 'file:///path/to/file.png' ],
130
- } );
131
-
132
- expect( getEditorHtml() ).toMatchSnapshot();
133
- } );
134
-
135
- it( 'appends media correctly for allowed types', async () => {
136
- // Arrange
137
- requestMediaImport
138
- .mockImplementationOnce( ( _, callback ) =>
139
- callback( MEDIA[ 0 ].id, MEDIA[ 0 ].serverUrl )
140
- )
141
- .mockImplementationOnce( ( _, callback ) =>
142
- callback( MEDIA[ 2 ].id, MEDIA[ 2 ].serverUrl )
143
- );
144
- await initializeEditor();
145
-
146
- // Act
147
- act( () => mediaAppendCallback( MEDIA[ 0 ] ) );
148
- act( () => mediaAppendCallback( MEDIA[ 2 ] ) );
149
- await screen.findByTestId( `network-image-${ MEDIA[ 0 ].serverUrl }` );
150
- await screen.findByTestId( `network-image-${ MEDIA[ 2 ].serverUrl }` );
151
-
152
- // Assert
153
- expect( getEditorHtml() ).toMatchSnapshot();
154
- } );
155
-
156
- it( 'appends media correctly for allowed types and skips unsupported ones', async () => {
157
- // Arrange
158
- requestMediaImport
159
- .mockImplementationOnce( ( _, callback ) =>
160
- callback( MEDIA[ 0 ].id, MEDIA[ 0 ].serverUrl )
161
- )
162
- .mockImplementationOnce( ( _, callback ) =>
163
- callback( MEDIA[ 3 ].id, MEDIA[ 3 ].serverUrl )
164
- );
165
- await initializeEditor();
166
-
167
- // Act
168
- act( () => mediaAppendCallback( MEDIA[ 0 ] ) );
169
- // Unsupported type (PDF file)
170
- act( () => mediaAppendCallback( MEDIA[ 1 ] ) );
171
- act( () => mediaAppendCallback( MEDIA[ 3 ] ) );
172
- await screen.findByTestId( `network-image-${ MEDIA[ 0 ].serverUrl }` );
173
-
174
- // Assert
175
- expect( getEditorHtml() ).toMatchSnapshot();
176
- } );
177
-
178
- it( 'unselects current block when tapping on the hardware back button', async () => {
179
- // Arrange
180
- await initializeEditor();
181
- await addBlock( screen, 'Spacer' );
182
-
183
- // Act
184
- act( () => {
185
- BackHandler.mockPressBack();
186
- } );
187
-
188
- // Assert
189
- const openBlockSettingsButton =
190
- screen.queryAllByLabelText( 'Open Settings' );
191
- expect( openBlockSettingsButton.length ).toBe( 0 );
192
- } );
193
-
194
- describe( 'on content update', () => {
195
- const MARKDOWN = `# Sample Document\nLorem ipsum dolor sit amet, consectetur adipiscing
196
- elit.\n## Overview\n- Lorem ipsum dolor sit amet\n- Consectetur adipiscing
197
- elit\n- Integer nec odio\n## Details\n1. Sed cursus ante dapibus diam\n2.
198
- Nulla quis sem at nibh elementum imperdiet\n3. Duis sagittis ipsum\n
199
- ## Mixed Lists\n- Key Points:\n 1. Lorem ipsum dolor sit amet\n 2.
200
- Consectetur adipiscing elit\n 3. Integer nec odio\n- Additional Info:\n -
201
- Sed cursus ante dapibus diam\n - Nulla quis sem at nibh elementum imperdiet\n`;
202
-
203
- it( 'parses markdown into blocks', async () => {
204
- // Arrange
205
- await initializeEditor( {
206
- initialTitle: null,
207
- } );
208
-
209
- // Act
210
- act( () => {
211
- onContentUpdateCallback( {
212
- content: MARKDOWN,
213
- } );
214
- } );
215
-
216
- // Assert
217
- // Needed to for the "Processed HTML piece" log.
218
- expect( console ).toHaveLogged();
219
- expect( getEditorTitle() ).toBe( 'Sample Document' );
220
- expect( getEditorHtml() ).toMatchSnapshot();
221
- } );
222
-
223
- it( 'parses a markdown heading into a title', async () => {
224
- // Arrange
225
- await initializeEditor( {
226
- initialTitle: null,
227
- } );
228
-
229
- // Act
230
- act( () => {
231
- onContentUpdateCallback( {
232
- content: `# Sample Document`,
233
- } );
234
- } );
235
-
236
- // Assert
237
- // Needed to for the "Processed HTML piece" log.
238
- expect( console ).toHaveLogged();
239
- expect( getEditorTitle() ).toBe( 'Sample Document' );
240
- expect( getEditorHtml() ).toBe( '' );
241
- } );
242
-
243
- it( 'parses standard text into blocks', async () => {
244
- // Arrange
245
- await initializeEditor( {
246
- initialTitle: null,
247
- } );
248
-
249
- // Act
250
- act( () => {
251
- onContentUpdateCallback( {
252
- content: `Lorem ipsum dolor sit amet`,
253
- } );
254
- } );
255
-
256
- // Assert
257
- // Needed to for the "Processed HTML piece" log.
258
- expect( console ).toHaveLogged();
259
- expect( getEditorTitle() ).toBe( 'Lorem ipsum dolor sit amet' );
260
- expect( getEditorHtml() ).toBe( '' );
261
- } );
262
- } );
263
- } );