Skip to content

Commit

Permalink
Added acceptance test
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Nov 1, 2024
1 parent f263c63 commit f5c2cbb
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 36 deletions.
93 changes: 59 additions & 34 deletions tests/codeception/functional/Paragraphs/AccordionCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}

}
2 changes: 1 addition & 1 deletion themes/stanford_basic/dist/js/behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
});
Expand Down
3 changes: 2 additions & 1 deletion themes/stanford_basic/src/js/stanford_basic.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down

0 comments on commit f5c2cbb

Please sign in to comment.