Skip to content

Commit

Permalink
add some tests for json api
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Oct 23, 2023
1 parent 5b5e642 commit 40cda95
Showing 1 changed file with 52 additions and 11 deletions.
63 changes: 52 additions & 11 deletions tests/codeception/acceptance/Paragraphs/ListsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public function __construct() {

/**
* Shared tags on each content type are identical.
*
* @group jsonapi
*/
public function testSharedTags(AcceptanceTester $I) {
$shared_tag = $I->createEntity([
Expand Down Expand Up @@ -112,10 +114,24 @@ public function testSharedTags(AcceptanceTester $I) {
$I->canSeeOptionIsSelected('Shared Tags (value 1)', $shared_tag->label());
$I->amOnPage($publication->toUrl('edit-form')->toString());
$I->canSeeOptionIsSelected('Shared Tags (value 1)', $shared_tag->label());

$I->amOnPage('/jsonapi/views/stanford_shared_tags/card_grid?page[limit]=50&views-argument[]=' . preg_replace('/[^a-z0-9-]/', '-', strtolower($shared_tag->label())));
$json_data = json_decode($I->grabPageSource(), TRUE, 512, JSON_THROW_ON_ERROR);
$json_ids = [];
foreach ($json_data['data'] as $item) {
$json_ids[] = $item['id'];
}
$I->assertContains($basic_page->uuid(), $json_ids);
$I->assertContains($news->uuid(), $json_ids);
$I->assertContains($event->uuid(), $json_ids);
$I->assertContains($person->uuid(), $json_ids);
$I->assertContains($publication->uuid(), $json_ids);
}

/**
* News items should display in the list paragraph.
*
* @group jsonapi
*/
public function testListParagraphNews(AcceptanceTester $I) {
$I->logInWithRole('contributor');
Expand All @@ -135,13 +151,23 @@ public function testListParagraphNews(AcceptanceTester $I) {
$I->canSee('Lorem Ipsum');
$I->canSeeLink('Google', 'http://google.com');
$I->canSee($title);

$I->amOnPage('/jsonapi/views/stanford_news/block_1?page[limit]=99');
$json_data = json_decode($I->grabPageSource(), TRUE, 512, JSON_THROW_ON_ERROR);
$json_titles = [];
foreach ($json_data['data'] as $item) {
$json_titles[] = $item['attributes']['title'];
}
$I->assertContains($title, $json_titles);
}

/**
* When using the list paragraph and view arguments, it should filter results.
*
* @group jsonapi
*/
public function testListParagraphNewsFiltersNoFilter(AcceptanceTester $I) {
$I->logInWithRole('site_manager');
$I->logInWithRole('contributor');

$topic_term = $this->createTaxonomyTerm($I, 'stanford_news_topics');

Expand All @@ -163,13 +189,26 @@ public function testListParagraphNewsFiltersNoFilter(AcceptanceTester $I) {

$I->amOnPage($node->toUrl()->toString());
$I->canSee($news->label());

$I->amOnPage('/jsonapi/views/stanford_news/block_1?page[limit]=99&views-argument[]=' . $topic_term->label());
$json_data = json_decode($I->grabPageSource(), TRUE, 512, JSON_THROW_ON_ERROR);
$json_titles = [];
foreach ($json_data['data'] as $item) {
$json_titles[] = $item['attributes']['title'];
}
$I->assertContains($news->label(), $json_titles);

$topic_term = $this->createTaxonomyTerm($I, 'stanford_news_topics');
$I->amOnPage('/jsonapi/views/stanford_news/block_1?page[limit]=99&views-argument[]=' . $topic_term->label());
$json_data = json_decode($I->grabPageSource(), TRUE, 512, JSON_THROW_ON_ERROR);
$I->assertEmpty($json_data['data']);
}

/**
* When using the list paragraph and view arguments, it should filter results.
*/
public function testListParagraphNewsFiltersRandomFilter(AcceptanceTester $I) {
$I->logInWithRole('site_manager');
$I->logInWithRole('contributor');

$random_term = $this->createTaxonomyTerm($I, 'stanford_news_topics');
$topic_term = $this->createTaxonomyTerm($I, 'stanford_news_topics');
Expand Down Expand Up @@ -199,7 +238,7 @@ public function testListParagraphNewsFiltersRandomFilter(AcceptanceTester $I) {
* When using the list paragraph and view arguments, it should filter results.
*/
public function testListParagraphNewsFiltersTopicFilter(AcceptanceTester $I) {
$I->logInWithRole('site_manager');
$I->logInWithRole('contributor');

$topic_term = $this->createTaxonomyTerm($I, 'stanford_news_topics');
// Use a child term but the argument is the parent term to verify children
Expand Down Expand Up @@ -257,13 +296,6 @@ public function testEmptyResultsListEvents(AcceptanceTester $I) {
],
'su_list_button' => ['uri' => 'http://google.com', 'title' => 'Google'],
], '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',
Expand Down Expand Up @@ -341,14 +373,15 @@ public function testEmptyResultsListEvents(AcceptanceTester $I) {
],
]);

$I->amOnPage('/');
$I->amOnPage($node->toUrl()->toString());
$I->cantSee($headline_text);
$I->cantSee($message);
}

/**
* Event items should display in the list paragraph.
*
* @group jsonapi
*/
public function testListParagraphEvents(AcceptanceTester $I) {
$I->logInWithRole('contributor');
Expand Down Expand Up @@ -459,6 +492,14 @@ public function testListParagraphEvents(AcceptanceTester $I) {
]);
$I->amOnPage($node->toUrl()->toString());
$I->cantSee($event->label());

$I->amOnPage('/jsonapi/views/stanford_events/list_page?page[limit]=99');
$json_data = json_decode($I->grabPageSource(), TRUE, 512, JSON_THROW_ON_ERROR);
$json_titles = [];
foreach ($json_data['data'] as $item) {
$json_titles[] = $item['attributes']['title'];
}
$I->assertContains($event->label(), $json_titles);
}

/**
Expand Down

0 comments on commit 40cda95

Please sign in to comment.