Skip to content

Commit 29f56e8

Browse files
committed
test(e2e): add e2e tests for Feedzy Loop
1 parent 6e2dfcc commit 29f56e8

File tree

7 files changed

+248
-5
lines changed

7 files changed

+248
-5
lines changed

includes/gutenberg/feedzy-rss-feeds-loop-block.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,24 @@ public function register_block() {
6969
// Pass in REST URL
7070
wp_localize_script(
7171
'feedzy-rss-feeds-loop-editor-script',
72-
'feedzyloopjs',
72+
'feedzyData',
7373
array(
7474
'defaultImage' => esc_url( FEEDZY_ABSURL . 'img/feedzy.svg' ),
7575
'isPro' => feedzy_is_pro(),
7676
)
7777
);
78+
79+
wp_localize_script(
80+
'feedzy-rss-feeds-loop-editor-script',
81+
'feedzyConditionsData',
82+
apply_filters(
83+
'feedzy_conditions_data',
84+
array(
85+
'isPro' => feedzy_is_pro(),
86+
'operators' => Feedzy_Rss_Feeds_Conditions::get_operators(),
87+
)
88+
)
89+
);
7890
}
7991

8092
/**
@@ -113,7 +125,8 @@ public function render_callback( $attributes, $content ) {
113125
'refresh' => '12_hours',
114126
);
115127

116-
$query = isset( $attributes['query'] ) ? wp_parse_args( $attributes['query'], $default_query ) : $default_query;
128+
$query = isset( $attributes['query'] ) ? wp_parse_args( $attributes['query'], $default_query ) : $default_query;
129+
$filters = isset( $attributes['conditions'] ) ? $attributes['conditions'] : array();
117130

118131
$options = array(
119132
'max' => $query['max'],
@@ -129,6 +142,7 @@ public function render_callback( $attributes, $content ) {
129142
'multiple_meta' => 'no',
130143
'summary' => 'yes',
131144
'summarylength' => '',
145+
'filters' => wp_json_encode( $filters ),
132146
);
133147

134148
$sizes = array(

js/FeedzyLoop/block.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,36 @@
5555
}
5656
}
5757
},
58+
"conditions": {
59+
"type": "object",
60+
"properties": {
61+
"match": {
62+
"type": "string",
63+
"enum": [ "all", "any" ],
64+
"default": "all"
65+
},
66+
"conditions": {
67+
"type": "array",
68+
"items": {
69+
"type": "object",
70+
"properties": {
71+
"field": {
72+
"type": "string",
73+
"default": "title"
74+
},
75+
"operator": {
76+
"type": "string",
77+
"default": "contains"
78+
},
79+
"value": {
80+
"type": "string",
81+
"default": ""
82+
}
83+
}
84+
}
85+
}
86+
}
87+
},
5888
"innerBlocksContent": {
5989
"type": "string",
6090
"default": ""

js/FeedzyLoop/edit.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import ServerSideRender from '@wordpress/server-side-render';
3131
* Internal dependencies.
3232
*/
3333
import Placeholder from './placeholder';
34+
import ConditionsControl from '../Conditions/ConditionsControl';
3435

3536
const Edit = ({ attributes, setAttributes, clientId }) => {
3637
const blockProps = useBlockProps();
@@ -214,6 +215,33 @@ const Edit = ({ attributes, setAttributes, clientId }) => {
214215
}
215216
/>
216217
</PanelBody>
218+
219+
<PanelBody
220+
title={[
221+
__('Filter items', 'feedzy-rss-feeds'),
222+
!feedzyData.isPro && (
223+
<span className="fz-pro-label">Pro</span>
224+
),
225+
]}
226+
initialOpen={false}
227+
className={
228+
feedzyData.isPro
229+
? 'feedzy-item-filter'
230+
: 'feedzy-item-filter fz-locked'
231+
}
232+
>
233+
<ConditionsControl
234+
conditions={
235+
attributes?.conditions || {
236+
conditions: [],
237+
match: 'all',
238+
}
239+
}
240+
setConditions={(conditions) => {
241+
setAttributes({ conditions });
242+
}}
243+
/>
244+
</PanelBody>
217245
</InspectorControls>
218246

219247
<div {...blockProps}>
@@ -244,7 +272,7 @@ const Edit = ({ attributes, setAttributes, clientId }) => {
244272
[
245273
'core/image',
246274
{
247-
url: window.feedzyloopjs.defaultImage,
275+
url: window.feedzyData.defaultImage,
248276
alt: '{{feedzy_title}}',
249277
href: '{{feedzy_url}}',
250278
},

js/FeedzyLoop/editor.scss

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,95 @@
44
width: 100%;
55
}
66
}
7+
}
8+
9+
.fz-condition-control {
10+
padding: 0;
11+
12+
&.is-upsell {
13+
opacity: 0.6;
14+
}
15+
16+
.components-button {
17+
width: 100%;
18+
margin: 0;
19+
padding: 6px 12px;
20+
justify-content: center;
21+
}
22+
}
23+
24+
.fz-panel-tab {
25+
z-index: 999999;
26+
margin: 24px 0;
27+
28+
&__header {
29+
display: flex;
30+
background: #fff;
31+
border: 1px solid #d5dadf;
32+
33+
&__label {
34+
cursor: pointer;
35+
flex-basis: 90%;
36+
display: flex;
37+
align-items: center;
38+
padding-left: 15px;
39+
40+
&::selection {
41+
background: none;
42+
}
43+
}
44+
45+
.components-button {
46+
height: auto;
47+
flex-basis: 10%;
48+
justify-content: center;
49+
padding: 10px 5px;
50+
border-left: 1px solid #d5dadf;
51+
border-radius: 0;
52+
53+
.dashicon {
54+
margin: 2px;
55+
}
56+
}
57+
58+
&:hover {
59+
background: #fafafb;
60+
}
61+
}
62+
63+
&__content {
64+
background: #fff;
65+
border: 1px solid #d5dadf;
66+
border-top: none;
67+
padding: 10px 15px;
68+
69+
.components-select-control {
70+
label {
71+
overflow: visible;
72+
white-space: normal;
73+
}
74+
}
75+
76+
.components-base-control {
77+
margin: 12px 0;
78+
79+
.components-dropdown {
80+
width: 100%;
81+
82+
.components-button {
83+
display: flex;
84+
justify-content: center;
85+
width: 100%;
86+
}
87+
}
88+
89+
.components-datetime__time-field-hours-input {
90+
min-width: 60px;
91+
}
92+
93+
.components-datetime__timezone {
94+
display: inline-block;
95+
}
96+
}
97+
}
798
}

js/FeedzyLoop/extension.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { useSelect } from '@wordpress/data';
1616

1717
import { addFilter } from '@wordpress/hooks';
1818

19-
const defaultImage = window.feedzyloopjs.defaultImage;
19+
const defaultImage = window.feedzyData.defaultImage;
2020

2121
const withFeedzyLoopImage = createHigherOrderComponent((BlockEdit) => {
2222
return (props) => {

js/FeedzyLoop/placeholder.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,14 @@ const BlockPlaceholder = ({ attributes, setAttributes, onSaveFeed }) => {
123123
/>
124124
)}
125125

126-
<Button variant="primary" onClick={onSaveFeed}>
126+
<Button
127+
variant="primary"
128+
onClick={onSaveFeed}
129+
disabled={
130+
!attributes?.feed?.source ||
131+
attributes?.feed?.source.length === 0
132+
}
133+
>
127134
{__('Save', 'feedzy-rss-feeds')}
128135
</Button>
129136
</>

tests/e2e/specs/loop.spec.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
import { test, expect } from '@wordpress/e2e-test-utils-playwright';
5+
6+
test.describe('Feedzy Loop', () => {
7+
const FEED_URL =
8+
'https://s3.amazonaws.com/verti-utils/sample-feed-import.xml';
9+
10+
test('add Feedzy Loop Block', async ({ editor, page }) => {
11+
await page.goto('/wp-admin/post-new.php');
12+
13+
if (
14+
(await page.$(
15+
'.edit-post-welcome-guide .components-modal__header button'
16+
)) !== null
17+
) {
18+
await page.click(
19+
'.edit-post-welcome-guide .components-modal__header button'
20+
);
21+
}
22+
23+
await page.getByLabel('Add title').click();
24+
await page.keyboard.type('Feedzy Loop Test');
25+
26+
await page.getByLabel('Toggle block inserter').click();
27+
28+
await page.getByPlaceholder('Search').click();
29+
await page.keyboard.type('Feedzy Loop');
30+
await page.waitForTimeout(1000);
31+
32+
await page.getByRole('option', { name: ' Feedzy Loop' }).click();
33+
await page.waitForTimeout(1000);
34+
await page.getByLabel('Feed URL').click();
35+
36+
await page.getByPlaceholder('Enter feed URLs separated by').click();
37+
await page.keyboard.type(FEED_URL);
38+
39+
await page.getByRole('button', { name: 'Save', exact: true }).click();
40+
await page.waitForTimeout(1000);
41+
42+
await page
43+
.getByRole('button', { name: 'Publish', exact: true })
44+
.click();
45+
await page.waitForTimeout(1000);
46+
47+
await page
48+
.getByLabel('Editor publish')
49+
.getByRole('button', { name: 'Publish', exact: true })
50+
.click();
51+
await page.waitForTimeout(5000);
52+
53+
const snackbar = await page.getByTestId('snackbar');
54+
const snackbarText = await snackbar.textContent();
55+
expect(snackbarText).toContain('Post published.');
56+
});
57+
58+
test('visit Feedzy Loop Page', async ({ editor, page }) => {
59+
await page.goto('/wp-admin/edit.php');
60+
61+
await page.hover('a.row-title');
62+
await page.getByLabel('View “Feedzy Loop Test”').click();
63+
64+
await page.waitForTimeout(5000);
65+
66+
// We want to confirm .wp-block-feedzy-rss-feeds-loop is present and it has 5 children
67+
const feedzyLoop = await page.$('.wp-block-feedzy-rss-feeds-loop');
68+
expect(feedzyLoop).not.toBeNull();
69+
70+
const feedzyLoopChildren = await feedzyLoop.$$(':scope > *');
71+
expect(feedzyLoopChildren.length).toBe(5);
72+
});
73+
});

0 commit comments

Comments
 (0)