Skip to content

Commit ea17eca

Browse files
test: add validation tests for invalid feed URLs in classic block
1 parent bb454f8 commit ea17eca

File tree

3 files changed

+102
-7
lines changed

3 files changed

+102
-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: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,68 @@
44
import { test, expect } from '@wordpress/e2e-test-utils-playwright';
55

66
test.describe('Feedzy Classic Block', () => {
7+
test('check validation for invalid URL', async ({
8+
editor,
9+
page,
10+
admin,
11+
}) => {
12+
await admin.createNewPost();
13+
14+
await editor.insertBlock({
15+
name: 'feedzy-rss-feeds/feedzy-block',
16+
});
17+
18+
await page
19+
.getByPlaceholder('Enter URL or group of your')
20+
.fill('http://invalid-url.com/feed');
21+
22+
await page.getByRole('button', { name: 'Load Feed' }).click();
23+
24+
await page.waitForSelector('.feedzy-validation-results');
25+
26+
await expect(
27+
page
28+
.locator('.feedzy-validation-results .is-error')
29+
.getByText('http://invalid-url.com/feed', { exact: true })
30+
).toBeVisible();
31+
});
32+
33+
test('check validation for invalid and valid URL', async ({
34+
editor,
35+
page,
36+
admin,
37+
}) => {
38+
await admin.createNewPost();
39+
40+
await editor.insertBlock({
41+
name: 'feedzy-rss-feeds/feedzy-block',
42+
});
43+
44+
await page
45+
.getByPlaceholder('Enter URL or group of your')
46+
.fill(
47+
'http://invalid-url.com/feed, https://www.nasa.gov/feeds/iotd-feed/'
48+
);
49+
50+
await page.getByRole('button', { name: 'Load Feed' }).click();
51+
52+
await page.waitForSelector('.feedzy-validation-results');
53+
54+
await expect(
55+
page
56+
.locator('.feedzy-validation-results .is-error')
57+
.getByText('http://invalid-url.com/feed', { exact: true })
58+
).toBeVisible();
59+
60+
await expect(
61+
page
62+
.locator('.feedzy-validation-results .is-success')
63+
.getByText('https://www.nasa.gov/feeds/iotd-feed/', {
64+
exact: true,
65+
})
66+
).toBeVisible();
67+
});
68+
769
test('check aspect ratio default', async ({ editor, page, admin }) => {
870
await admin.createNewPost();
971

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)