Skip to content

Commit 568d177

Browse files
authored
Merge pull request #890 from Kit/tests-block-toggles-by-name
Tests: Block Toggles: Reference by name
2 parents a15d2ac + 251cd69 commit 568d177

File tree

6 files changed

+54
-40
lines changed

6 files changed

+54
-40
lines changed

tests/EndToEnd/broadcasts/blocks-shortcodes/PageBlockBroadcastsCest.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public function testBroadcastsBlockWithDisplayGridParameter(EndToEndTester $I)
225225
blockName: 'Kit Broadcasts',
226226
blockProgrammaticName: 'convertkit-broadcasts',
227227
blockConfiguration: [
228-
'#inspector-toggle-control-0' => [ 'toggle', true ],
228+
'Display as grid' => [ 'toggle', true ],
229229
]
230230
);
231231

@@ -359,8 +359,8 @@ public function testBroadcastsBlockWithDisplayImageParameter(EndToEndTester $I)
359359
blockName: 'Kit Broadcasts',
360360
blockProgrammaticName: 'convertkit-broadcasts',
361361
blockConfiguration: [
362-
'#inspector-toggle-control-0' => [ 'toggle', true ],
363-
'#inspector-toggle-control-1' => [ 'toggle', true ],
362+
'Display as grid' => [ 'toggle', true ],
363+
'Display images' => [ 'toggle', true ],
364364
]
365365
);
366366

@@ -403,7 +403,7 @@ public function testBroadcastsBlockWithDisplayDescriptionParameter(EndToEndTeste
403403
blockName: 'Kit Broadcasts',
404404
blockProgrammaticName: 'convertkit-broadcasts',
405405
blockConfiguration: [
406-
'#inspector-toggle-control-2' => [ 'toggle', true ],
406+
'Display descriptions' => [ 'toggle', true ],
407407
]
408408
);
409409

@@ -445,8 +445,8 @@ public function testBroadcastsBlockWithDisplayReadMoreLinkParameter(EndToEndTest
445445
blockName: 'Kit Broadcasts',
446446
blockProgrammaticName: 'convertkit-broadcasts',
447447
blockConfiguration: [
448-
'#inspector-toggle-control-3' => [ 'toggle', true ],
449-
'read_more_label' => [ 'input', 'Continue reading' ],
448+
'Display read more links' => [ 'toggle', true ],
449+
'read_more_label' => [ 'input', 'Continue reading' ],
450450
]
451451
);
452452

@@ -588,8 +588,8 @@ public function testBroadcastsBlockWithPaginationEnabled(EndToEndTester $I)
588588
blockName: 'Kit Broadcasts',
589589
blockProgrammaticName: 'convertkit-broadcasts',
590590
blockConfiguration: [
591-
'limit' => [ 'input', '2', 'Pagination' ], // Click the Pagination tab first before starting to complete fields.
592-
'#inspector-toggle-control-4' => [ 'toggle', true ],
591+
'limit' => [ 'input', '2', 'Pagination' ], // Click the Pagination tab first before starting to complete fields.
592+
'Display pagination' => [ 'toggle', true ],
593593
]
594594
);
595595

@@ -625,10 +625,10 @@ public function testBroadcastsBlockWithPaginationLabelParameters(EndToEndTester
625625
blockName: 'Kit Broadcasts',
626626
blockProgrammaticName: 'convertkit-broadcasts',
627627
blockConfiguration: [
628-
'limit' => [ 'input', '2', 'Pagination' ], // Click the Pagination tab first before starting to complete fields.
629-
'#inspector-toggle-control-4' => [ 'toggle', true ],
630-
'paginate_label_prev' => [ 'input', 'Newer' ],
631-
'paginate_label_next' => [ 'input', 'Older' ],
628+
'limit' => [ 'input', '2', 'Pagination' ], // Click the Pagination tab first before starting to complete fields.
629+
'Display pagination' => [ 'toggle', true ],
630+
'paginate_label_prev' => [ 'input', 'Newer' ],
631+
'paginate_label_next' => [ 'input', 'Older' ],
632632
]
633633
);
634634

@@ -664,10 +664,10 @@ public function testBroadcastsBlockWithBlankPaginationLabelParameters(EndToEndTe
664664
blockName: 'Kit Broadcasts',
665665
blockProgrammaticName: 'convertkit-broadcasts',
666666
blockConfiguration: [
667-
'limit' => [ 'input', '2', 'Pagination' ], // Click the Pagination tab first before starting to complete fields.
668-
'#inspector-toggle-control-4' => [ 'toggle', true ],
669-
'paginate_label_prev' => [ 'input', '' ],
670-
'paginate_label_next' => [ 'input', '' ],
667+
'limit' => [ 'input', '2', 'Pagination' ], // Click the Pagination tab first before starting to complete fields.
668+
'Display pagination' => [ 'toggle', true ],
669+
'paginate_label_prev' => [ 'input', '' ],
670+
'paginate_label_next' => [ 'input', '' ],
671671
]
672672
);
673673

tests/EndToEnd/broadcasts/blocks-shortcodes/WidgetBroadcastsCest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ public function testBroadcastsBlockWidgetWithPaginationEnabled(EndToEndTester $I
147147
blockName: 'Kit Broadcasts',
148148
blockProgrammaticName: 'convertkit-broadcasts',
149149
blockConfiguration: [
150-
'#inspector-toggle-control-4' => [ 'toggle', true, 'Pagination' ], // Click the Pagination tab first before starting to complete fields.
151-
'limit' => [ 'input', '2' ],
150+
'Display pagination' => [ 'toggle', true, 'Pagination' ], // Click the Pagination tab first before starting to complete fields.
151+
'limit' => [ 'input', '2' ],
152152
]
153153
);
154154

@@ -174,10 +174,10 @@ public function testBroadcastsBlockWithPaginationLabelParameters(EndToEndTester
174174
blockName: 'Kit Broadcasts',
175175
blockProgrammaticName: 'convertkit-broadcasts',
176176
blockConfiguration: [
177-
'#inspector-toggle-control-4' => [ 'toggle', true, 'Pagination' ], // Click the Pagination tab first before starting to complete fields.
178-
'limit' => [ 'input', '2' ],
179-
'paginate_label_prev' => [ 'input', 'Newer' ],
180-
'paginate_label_next' => [ 'input', 'Older' ],
177+
'Display pagination' => [ 'toggle', true, 'Pagination' ], // Click the Pagination tab first before starting to complete fields.
178+
'limit' => [ 'input', '2' ],
179+
'paginate_label_prev' => [ 'input', 'Newer' ],
180+
'paginate_label_next' => [ 'input', 'Older' ],
181181
]
182182
);
183183

@@ -207,10 +207,10 @@ public function testBroadcastsBlockWithBlankPaginationLabelParameters(EndToEndTe
207207
blockName: 'Kit Broadcasts',
208208
blockProgrammaticName: 'convertkit-broadcasts',
209209
blockConfiguration: [
210-
'#inspector-toggle-control-4' => [ 'toggle', true, 'Pagination' ], // Click the Pagination tab first before starting to complete fields.
211-
'limit' => [ 'input', '2' ],
212-
'paginate_label_prev' => [ 'input', '' ],
213-
'paginate_label_next' => [ 'input', '' ],
210+
'Display pagination' => [ 'toggle', true, 'Pagination' ], // Click the Pagination tab first before starting to complete fields.
211+
'limit' => [ 'input', '2' ],
212+
'paginate_label_prev' => [ 'input', '' ],
213+
'paginate_label_next' => [ 'input', '' ],
214214
]
215215
);
216216

tests/EndToEnd/forms/blocks-shortcodes/PageBlockFormBuilderCest.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ public function testFormBuilderBlockWithTextCustomization(EndToEndTester $I)
153153
blockName: 'Kit Form Builder',
154154
blockProgrammaticName: 'convertkit-form-builder',
155155
blockConfiguration: [
156-
'#inspector-toggle-control-1' => [ 'toggle', false ],
157-
'text_if_subscribed' => [ 'text', 'Welcome to the newsletter!' ],
156+
'Display form' => [ 'toggle', false ],
157+
'text_if_subscribed' => [ 'text', 'Welcome to the newsletter!' ],
158158
]
159159
);
160160

@@ -945,10 +945,7 @@ public function testFormBuilderWithRecaptchaEnabledAndHighMinimumScore(EndToEndT
945945
$I->addGutenbergBlock(
946946
$I,
947947
blockName: 'Kit Form Builder',
948-
blockProgrammaticName: 'convertkit-form-builder',
949-
blockConfiguration: [
950-
'#inspector-toggle-control-0' => [ 'toggle', true ],
951-
]
948+
blockProgrammaticName: 'convertkit-form-builder'
952949
);
953950

954951
// Publish and view the Page on the frontend site.
@@ -1007,9 +1004,9 @@ public function testFormBuilderWithStoreEntriesEnabled(EndToEndTester $I)
10071004
blockName: 'Kit Form Builder',
10081005
blockProgrammaticName: 'convertkit-form-builder',
10091006
blockConfiguration: [
1010-
'#inspector-toggle-control-0' => [ 'toggle', true ],
1011-
'sequence_id' => [ 'select', $_ENV['CONVERTKIT_API_SEQUENCE_ID'] ],
1012-
'tag_id' => [ 'select', $_ENV['CONVERTKIT_API_TAG_ID'] ],
1007+
'Store form submissions' => [ 'toggle', true ],
1008+
'sequence_id' => [ 'select', $_ENV['CONVERTKIT_API_SEQUENCE_ID'] ],
1009+
'tag_id' => [ 'select', $_ENV['CONVERTKIT_API_TAG_ID'] ],
10131010
]
10141011
);
10151012

tests/EndToEnd/products/PageBlockProductCest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ public function testProductBlockWithCheckoutParameterEnabled(EndToEndTester $I)
349349
blockName: 'Kit Product',
350350
blockProgrammaticName: 'convertkit-product',
351351
blockConfiguration: [
352-
'product' => [ 'select', $_ENV['CONVERTKIT_API_PRODUCT_NAME'] ],
353-
'#inspector-toggle-control-0' => [ 'toggle', true ],
352+
'product' => [ 'select', $_ENV['CONVERTKIT_API_PRODUCT_NAME'] ],
353+
'Load checkout step' => [ 'toggle', true ],
354354
]
355355
);
356356

@@ -406,8 +406,8 @@ public function testProductBlockWithDisableModalOnMobileParameterEnabled(EndToEn
406406
blockName: 'Kit Product',
407407
blockProgrammaticName: 'convertkit-product',
408408
blockConfiguration: [
409-
'product' => [ 'select', $_ENV['CONVERTKIT_API_PRODUCT_NAME'] ],
410-
'#inspector-toggle-control-1' => [ 'toggle', true ],
409+
'product' => [ 'select', $_ENV['CONVERTKIT_API_PRODUCT_NAME'] ],
410+
'Disable modal on mobile' => [ 'toggle', true ],
411411
]
412412
);
413413

tests/Support/Helper/WPGutenberg.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ public function addGutenbergBlock($I, $blockName, $blockProgrammaticName, $block
100100
$I->selectOption($fieldID, $attributes[1]);
101101
break;
102102
case 'toggle':
103+
// The block editor doesn't use the field ID, so we need to find the field by the label.
104+
$field = "//label[normalize-space(text())='" . $field . "']/preceding-sibling::span/input";
105+
103106
// Determine if the toggle has checked the checkbox.
104107
$isChecked = $I->grabAttributeFrom($field, 'checked');
105108

tests/Support/Helper/WPWidget.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,21 @@ public function addBlockWidget($I, $blockName, $blockProgrammaticName, $blockCon
143143
$I->selectOption($fieldID, $attributes[1]);
144144
break;
145145
case 'toggle':
146-
$I->click($field);
146+
// The block editor doesn't use the field ID, so we need to find the field by the label.
147+
$field = "//label[normalize-space(text())='" . $field . "']/preceding-sibling::span/input";
148+
149+
// Determine if the toggle has checked the checkbox.
150+
$isChecked = $I->grabAttributeFrom($field, 'checked');
151+
152+
// If the attribute is true, and the checkbox is not checked, click the toggle to check it.
153+
if ( $attributes[1] && ! $isChecked ) {
154+
$I->click($field);
155+
}
156+
157+
// If the attribute is false, and the checkbox is checked, click the toggle to uncheck it.
158+
if ( ! $attributes[1] && $isChecked ) {
159+
$I->click($field);
160+
}
147161
break;
148162
default:
149163
$I->fillField($fieldID, $attributes[1]);

0 commit comments

Comments
 (0)