From f5c2cbbbe616cf499fab1c59e4cb9bc25d2ba4cb Mon Sep 17 00:00:00 2001 From: Mike Decker Date: Thu, 31 Oct 2024 20:50:43 -0700 Subject: [PATCH] Added acceptance test --- .../functional/Paragraphs/AccordionCest.php | 93 ++++++++++++------- themes/stanford_basic/dist/js/behaviors.js | 2 +- .../src/js/stanford_basic.behavior.js | 3 +- 3 files changed, 62 insertions(+), 36 deletions(-) diff --git a/tests/codeception/functional/Paragraphs/AccordionCest.php b/tests/codeception/functional/Paragraphs/AccordionCest.php index 7c2c23f7a..343f482de 100644 --- a/tests/codeception/functional/Paragraphs/AccordionCest.php +++ b/tests/codeception/functional/Paragraphs/AccordionCest.php @@ -6,59 +6,84 @@ * Class AccordionCest. * * @group paragraphs + * @group accordions */ -abstract class AccordionCest { +class AccordionCest { + + protected $faker; + + public function __construct() { + $this->faker = Factory::create(); + } /** * Create and check the accordion. */ public function testCreatingAccordion(FunctionalTester $I) { - $faker = Factory::create(); + $q_and_a = [ + [$this->faker->words(3, TRUE), $this->faker->paragraph()], + [$this->faker->words(3, TRUE), $this->faker->paragraph()], + [$this->faker->words(3, TRUE), $this->faker->paragraph()], + ]; + + $questions = []; + foreach ($q_and_a as $item) { + $question_paragraph = $I->createEntity([ + 'type' => 'stanford_accordion', + 'su_accordion_title' => $item[0], + 'su_accordion_body' => [ + 'value' => $item[1], + 'format' => 'stanford_minimal_html', + ], + ], 'paragraph'); + $questions[] = [ + 'target_id' => $question_paragraph->id(), + 'entity' => $question_paragraph, + ]; + } $paragraph = $I->createEntity([ - 'type' => 'stanford_accordion', - 'su_accordion_body' => [ - 'value' => 'I can see it in your smile.', - 'format' => 'stanford_minimal_html', + 'type' => 'stanford_faq', + 'su_faq_headline' => $this->faker->words(4, TRUE), + 'su_faq_description' => [ + 'value' => $this->faker->paragraph, + 'format' => 'stanford_html', ], + 'su_faq_questions' => $questions, ], 'paragraph'); - $row = $I->createEntity([ - 'type' => 'node_stanford_page_row', - 'su_page_components' => [ - 'target_id' => $paragraph->id(), - 'entity' => $paragraph, - ], - ], 'paragraph_row'); - $node = $I->createEntity([ 'type' => 'stanford_page', - 'title' => $faker->text(30), + 'title' => $this->faker->text(30), 'su_page_components' => [ - 'target_id' => $row->id(), - 'entity' => $row, + 'target_id' => $paragraph->id(), + 'entity' => $paragraph, ], ]); - $I->logInWithRole('contributor'); - $I->amOnPage($node->toUrl('edit-form')->toString()); - $I->waitForElementVisible('#row-0'); - $I->click('Edit', '.inner-row-wrapper'); - $I->waitForText('Title/Question'); - $I->fillField('Title/Question', 'Hello. Is it me you\'re looking for?'); + $I->amOnPage($node->toUrl()->toString()); + $I->canSee($node->label(), 'h1'); + + foreach ($q_and_a as $delta => $item) { + [$question, $answer] = $item; + $I->canSee($question); + $I->cantSee($answer); + + $child_index = $delta + 1; + $I->click(".ptype-stanford-accordion:nth-child($child_index) summary"); + $I->waitForText($answer); + $I->click(".ptype-stanford-accordion:nth-child($child_index) summary"); + } - $I->click('Continue'); - $I->waitForElementNotVisible('.MuiDialog-scrollPaper'); - $I->click('Save'); + $I->click('Expand All'); + foreach ($q_and_a as $item) { + $I->canSee($item[1]); + } - $I->canSee('Hello. Is it me you\'re looking for?'); - $I->cantSeeElement('.open'); - $open = $I->grabAttributeFrom('details', 'open'); - $I->assertNull($open); - $I->clickWithLeftButton('summary'); - $open = $I->grabAttributeFrom('details', 'open'); - $I->assertNotNull($open); - $I->canSee('I can see it in your smile.'); + $I->click('Collapse All'); + foreach ($q_and_a as $item) { + $I->cantSee($item[1]); + } } } diff --git a/themes/stanford_basic/dist/js/behaviors.js b/themes/stanford_basic/dist/js/behaviors.js index d0fabd09a..147d21dfb 100644 --- a/themes/stanford_basic/dist/js/behaviors.js +++ b/themes/stanford_basic/dist/js/behaviors.js @@ -128,7 +128,7 @@ window.Drupal.behaviors.stanford_basic = { var $details = $('details', faq); $('summary', $details).each(function (sumIndex, summary) { var $summary = $(summary); - var groupId = $summary.text().toLowerCase().replace(/[^\w]/g, '-').replace(/^-+/, '').replace(/-+$/, ''); + var groupId = $summary.text().toLowerCase().replace(/[^\w]/g, '-').replace(/^-+/, '').replace(/-+$/, '').substring(0, 25); $summary.attr('aria-expanded', 'false').attr('aria-controls', "".concat(groupId, "-panel")).attr('id', "".concat(groupId, "-button")); $summary.next().attr('id', "".concat(groupId, "-panel")).attr('aria-labelledby', "".concat(groupId, "-button")); }); diff --git a/themes/stanford_basic/src/js/stanford_basic.behavior.js b/themes/stanford_basic/src/js/stanford_basic.behavior.js index 38e71fdb1..7d4e40faf 100644 --- a/themes/stanford_basic/src/js/stanford_basic.behavior.js +++ b/themes/stanford_basic/src/js/stanford_basic.behavior.js @@ -99,7 +99,8 @@ export default { .toLowerCase() .replace(/[^\w]/g, '-') .replace(/^-+/, '') - .replace(/-+$/, ''); + .replace(/-+$/, '') + .substring(0, 25); $summary.attr('aria-expanded', 'false') .attr('aria-controls', `${groupId}-panel`)