Skip to content

Commit 22dcc52

Browse files
test: add validation tests for invalid feed URLs in classic block
1 parent 9a72a9e commit 22dcc52

File tree

3 files changed

+85
-7
lines changed

3 files changed

+85
-7
lines changed

js/FeedzyLoop/placeholder.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ const BlockPlaceholder = ({ attributes, setAttributes, onSaveFeed }) => {
115115
return (
116116
<div
117117
className="feedzy-validation-results"
118-
style={{
118+
style={{
119119
display: 'flex',
120120
flexDirection: 'column',
121121
gap: '10px',
@@ -154,7 +154,8 @@ const BlockPlaceholder = ({ attributes, setAttributes, onSaveFeed }) => {
154154
{isValidating
155155
? __(
156156
'Validating and fetching feed…',
157-
'feedzy-rss-feeds')
157+
'feedzy-rss-feeds'
158+
)
158159
: __('Loading…', 'feedzy-rss-feeds')}
159160
</p>
160161
</div>
@@ -195,11 +196,7 @@ const BlockPlaceholder = ({ attributes, setAttributes, onSaveFeed }) => {
195196
</BaseControl>
196197

197198
<div>
198-
<Button
199-
variant="primary"
200-
onClick={handleLoadFeed}
201-
disabled={!attributes?.feed?.source}
202-
>
199+
<Button variant="primary" onClick={handleLoadFeed}>
203200
{__('Load Feed', 'feedzy-rss-feeds')}
204201
</Button>
205202
</div>

tests/e2e/specs/classic-block.spec.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
import { test, expect } from '@wordpress/e2e-test-utils-playwright';
5+
6+
test.describe('Feedzy Classic Block', () => {
7+
test('check validation for invalid URL', async ({ editor, page, admin }) => {
8+
await admin.createNewPost();
9+
10+
await editor.insertBlock({
11+
name: 'feedzy-rss-feeds/feedzy-block',
12+
});
13+
14+
await page.getByPlaceholder('Enter URL or group of your').fill(
15+
'http://invalid-url.com/feed'
16+
);
17+
18+
await page.getByRole('button', { name: 'Load Feed' }).click();
19+
20+
await page.waitForSelector('.feedzy-validation-results');
21+
22+
await expect( page.locator('.feedzy-validation-results .is-error').getByText('http://invalid-url.com/feed', { exact: true }) ).toBeVisible();
23+
});
24+
25+
test('check validation for invalid and valid URL', async ({ editor, page, admin }) => {
26+
await admin.createNewPost();
27+
28+
await editor.insertBlock({
29+
name: 'feedzy-rss-feeds/feedzy-block',
30+
});
31+
32+
await page.getByPlaceholder('Enter URL or group of your').fill(
33+
'http://invalid-url.com/feed, https://www.nasa.gov/feeds/iotd-feed/'
34+
);
35+
36+
await page.getByRole('button', { name: 'Load Feed' }).click();
37+
38+
await page.waitForSelector('.feedzy-validation-results');
39+
40+
await expect( page.locator('.feedzy-validation-results .is-error').getByText('http://invalid-url.com/feed', { exact: true }) ).toBeVisible();
41+
42+
await expect( page.locator('.feedzy-validation-results .is-success').getByText('https://www.nasa.gov/feeds/iotd-feed/', { exact: true }) ).toBeVisible();
43+
});
44+
45+
});

tests/e2e/specs/loop.spec.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,40 @@ test.describe('Feedzy Loop', () => {
106106
const feedzyLoopChildren = await feedzyLoop.$$(':scope > *');
107107
expect(feedzyLoopChildren.length).toBe(5);
108108
});
109+
110+
test('check validation for invalid URL', async ({ editor, page, admin }) => {
111+
await admin.createNewPost();
112+
113+
await editor.insertBlock({
114+
name: 'feedzy-rss-feeds/loop',
115+
});
116+
117+
await page.getByPlaceholder('Enter URLs or select a Feed').fill(
118+
'http://invalid-url.com/feed'
119+
);
120+
await page.getByRole('button', { name: 'Load Feed' }).click();
121+
122+
await page.waitForSelector('.feedzy-validation-results');
123+
124+
await expect( page.locator('.feedzy-validation-results .is-error').getByText('http://invalid-url.com/feed', { exact: true }) ).toBeVisible();
125+
});
126+
127+
test('check validation for invalid and valid url', async ({ editor, page, admin }) => {
128+
await admin.createNewPost();
129+
130+
await editor.insertBlock({
131+
name: 'feedzy-rss-feeds/loop',
132+
});
133+
134+
await page.getByPlaceholder('Enter URLs or select a Feed').fill(
135+
'http://invalid-url.com/feed, https://www.nasa.gov/feeds/iotd-feed/'
136+
);
137+
await page.getByRole('button', { name: 'Load Feed' }).click();
138+
139+
await page.waitForSelector('.feedzy-validation-results');
140+
141+
await expect( page.locator('.feedzy-validation-results .is-error').getByText('http://invalid-url.com/feed', { exact: true }) ).toBeVisible();
142+
143+
await expect( page.locator('.feedzy-validation-results .is-success').getByText('https://www.nasa.gov/feeds/iotd-feed/', { exact: true }) ).toBeVisible();
144+
});
109145
});

0 commit comments

Comments
 (0)