Skip to content

Commit

Permalink
EWPP-2508: Update test coverage for teasers in content types.
Browse files Browse the repository at this point in the history
  • Loading branch information
sergepavle committed Sep 15, 2022
1 parent 2680e24 commit dfcb4f9
Show file tree
Hide file tree
Showing 7 changed files with 494 additions and 27 deletions.
124 changes: 119 additions & 5 deletions tests/src/Kernel/CallForProposalsRenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
use Drupal\Tests\oe_theme\PatternAssertions\ListItemAssert;
use Drupal\Tests\oe_theme\PatternAssertions\FieldListAssert;
use Drupal\Tests\oe_theme\PatternAssertions\PatternAssertState;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Symfony\Component\DomCrawler\Crawler;

/**
* Tests call for proposals rendering.
Expand Down Expand Up @@ -110,10 +113,35 @@ public function testTeaser(): void {
],
],
'image' => NULL,
// @todo Replace additional_information assertion with lists in EWPP-2508.
'lists' => [
new PatternAssertState(new FieldListAssert(), [
'items' => [
[
'label' => 'Reference',
'body' => 'Call for proposals reference',
], [
'label' => 'Opening date',
'body' => '14 February 2020',
], [
'label' => 'Deadline model',
'body' => 'Single-stage',
], [
'label' => 'Deadline date',
'body' => '21 February 2020',
], [
'label' => 'Funding programme',
'body' => 'Arab Common Market',
],
],
]),
],
];
$assert->assertPattern($expected_values, $html);

$crawler = new Crawler($html);
$actual = $crawler->filter('span.ecl-label.ecl-label--high');
$this->assertCount(1, $actual);

// Test short title fallback.
$node->set('oe_content_short_title', 'CFP short title')->save();
$build = $this->nodeViewBuilder->view($node, 'teaser');
Expand All @@ -131,7 +159,28 @@ public function testTeaser(): void {
$node->set('oe_call_proposals_model', 'two_stage')->save();
$build = $this->nodeViewBuilder->view($node, 'teaser');
$html = $this->renderRoot($build);
// @todo Replace additional_information assertion with lists in EWPP-2508.
$expected_values['lists'] = [
new PatternAssertState(new FieldListAssert(), [
'items' => [
[
'label' => 'Reference',
'body' => 'Call for proposals reference',
], [
'label' => 'Opening date',
'body' => '14 February 2020',
], [
'label' => 'Deadline model',
'body' => 'Two-stage',
], [
'label' => 'Deadline dates',
'body' => "21 February 2020\n | 22 February 2020",
], [
'label' => 'Funding programme',
'body' => 'Arab Common Market',
],
],
]),
];
$assert->assertPattern($expected_values, $html);

// Check status Closed and highlighted labels and background.
Expand All @@ -153,9 +202,34 @@ public function testTeaser(): void {
'variant' => 'highlight',
],
];
// @todo Replace additional_information assertion with lists in EWPP-2508.
$expected_values['lists'] = [
new PatternAssertState(new FieldListAssert(), [
'items' => [
[
'label' => 'Reference',
'body' => 'Call for proposals reference',
], [
'label' => 'Opening date',
'body' => '14 February 2020',
], [
'label' => 'Deadline model',
'body' => 'Multiple cut-off',
], [
'label' => 'Deadline date',
'body' => '17 February 2020',
], [
'label' => 'Funding programme',
'body' => 'Arab Common Market',
],
],
]),
];
$assert->assertPattern($expected_values, $html);

$crawler = new Crawler($html);
$actual = $crawler->filter('span.ecl-label.ecl-label--low');
$this->assertCount(1, $actual);

// Check status Upcoming label and background.
$opening_date->modify('+ 10 days');
$deadline_date->modify('+ 4 days');
Expand All @@ -170,9 +244,34 @@ public function testTeaser(): void {
'label' => 'Call status: Upcoming',
'variant' => 'medium',
];
// @todo Replace additional_information assertion with lists in EWPP-2508.
$expected_values['lists'] = [
new PatternAssertState(new FieldListAssert(), [
'items' => [
[
'label' => 'Reference',
'body' => 'Call for proposals reference',
], [
'label' => 'Opening date',
'body' => '24 February 2020',
], [
'label' => 'Deadline model',
'body' => 'Single-stage',
], [
'label' => 'Deadline date',
'body' => '21 February 2020',
], [
'label' => 'Funding programme',
'body' => 'Arab Common Market',
],
],
]),
];
$assert->assertPattern($expected_values, $html);

$crawler = new Crawler($html);
$actual = $crawler->filter('span.ecl-label.ecl-label--medium');
$this->assertCount(1, $actual);

// Check status N/A.
$publication_date->modify('+ 5 days');
$deadline_date->modify('+ 5 days');
Expand All @@ -184,7 +283,22 @@ public function testTeaser(): void {
$build = $this->nodeViewBuilder->view($node, 'teaser');
$html = $this->renderRoot($build);
$expected_values['badges'][0] = [];
// @todo Replace additional_information assertion with lists in EWPP-2508.
$expected_values['lists'] = [
new PatternAssertState(new FieldListAssert(), [
'items' => [
[
'label' => 'Reference',
'body' => 'Call for proposals reference',
], [
'label' => 'Deadline model',
'body' => 'Permanent',
], [
'label' => 'Funding programme',
'body' => 'Arab Common Market',
],
],
]),
];
$assert->assertPattern($expected_values, $html);
}

Expand Down
117 changes: 111 additions & 6 deletions tests/src/Kernel/CallForTendersRenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
use Drupal\Tests\oe_theme\PatternAssertions\ListItemAssert;
use Drupal\Tests\oe_theme\PatternAssertions\FieldListAssert;
use Drupal\Tests\oe_theme\PatternAssertions\PatternAssertState;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\user\Entity\User;
use Symfony\Component\DomCrawler\Crawler;

/**
* Tests call for tenders rendering.
Expand Down Expand Up @@ -115,10 +118,32 @@ public function testTeaser(): void {
],
],
'image' => NULL,
// @todo Replace additional_information assertion with lists in EWPP-2508.
'lists' => [
new PatternAssertState(new FieldListAssert(), [
'items' => [
[
'label' => 'Reference',
'body' => 'Call for tenders reference',
], [
'label' => 'Opening date',
'body' => $opening_date->format('d F Y'),
], [
'label' => 'Deadline date',
'body' => $deadline_date->format('d F Y, H:i (T)'),
], [
'label' => 'Departments',
'body' => 'Audit Board of the European Communities, Arab Common Market',
],
],
]),
],
];
$assert->assertPattern($expected_values, $html);

$crawler = new Crawler($html);
$actual = $crawler->filter('span.ecl-label.ecl-label--high');
$this->assertCount(1, $actual);

// Test short title fallback.
$node->set('oe_content_short_title', 'CFT short title');
$node->set('sticky', NodeInterface::STICKY)->save();
Expand All @@ -131,7 +156,25 @@ public function testTeaser(): void {
$node->set('oe_departments', 'http://publications.europa.eu/resource/authority/corporate-body/ABEC')->save();
$build = $this->nodeViewBuilder->view($node, 'teaser');
$html = $this->renderRoot($build);
// @todo Replace additional_information assertion with lists in EWPP-2508.
$expected_values['lists'] = [
new PatternAssertState(new FieldListAssert(), [
'items' => [
[
'label' => 'Reference',
'body' => 'Call for tenders reference',
], [
'label' => 'Opening date',
'body' => $opening_date->format('d F Y'),
], [
'label' => 'Deadline date',
'body' => $deadline_date->format('d F Y, H:i (T)'),
], [
'label' => 'Department',
'body' => 'Audit Board of the European Communities',
],
],
]),
];
$assert->assertPattern($expected_values, $html);

// Check status Closed and highlighted labels and background.
Expand All @@ -150,10 +193,35 @@ public function testTeaser(): void {
],
];
$deadline_date->setTimeZone(new \DateTimeZone('Australia/Sydney'));
// @todo Replace additional_information assertion with lists in EWPP-2508.
$expected_values['lists'] = [
new PatternAssertState(new FieldListAssert(), [
'items' => [
[
'label' => 'Reference',
'body' => 'Call for tenders reference',
], [
'label' => 'Opening date',
'body' => $opening_date->format('d F Y'),
], [
'label' => 'Deadline date',
'body' => $deadline_date->format('d F Y, H:i (T)'),
], [
'label' => 'Department',
'body' => 'Audit Board of the European Communities',
],
],
]),
];
$assert->assertPattern($expected_values, $html);

// @todo Restore Deadline date assert in EWPP-2508.
$crawler = new Crawler($html);
$actual = $crawler->filter('span.ecl-label.ecl-label--low');
$this->assertCount(1, $actual);

// Check Deadline date is striked when Call for tenders is closed.
$actual = $crawler->filter('dd.ecl-description-list__definition > .ecl-u-type-strike');
$this->assertCount(1, $actual);

// Check status Upcoming label and background.
$opening_date = (clone $static_time)->modify('+ 10 days');
$deadline_date = (clone $static_time)->modify('+ 5 days');
Expand All @@ -166,9 +234,31 @@ public function testTeaser(): void {
'label' => 'Call status: Upcoming',
'variant' => 'medium',
];
// @todo Replace additional_information assertion with lists in EWPP-2508.
$expected_values['lists'] = [
new PatternAssertState(new FieldListAssert(), [
'items' => [
[
'label' => 'Reference',
'body' => 'Call for tenders reference',
], [
'label' => 'Opening date',
'body' => $opening_date->format('d F Y'),
], [
'label' => 'Deadline date',
'body' => $deadline_date->format('d F Y, H:i (T)'),
], [
'label' => 'Department',
'body' => 'Audit Board of the European Communities',
],
],
]),
];
$assert->assertPattern($expected_values, $html);

$crawler = new Crawler($html);
$actual = $crawler->filter('span.ecl-label.ecl-label--medium');
$this->assertCount(1, $actual);

// Check status N/A.
$publication_date = (clone $static_time)->modify('+ 5 days');
$deadline_date = (clone $static_time)->modify('+ 5 days');
Expand All @@ -181,7 +271,22 @@ public function testTeaser(): void {

$deadline_date->setTimeZone(new \DateTimeZone('Australia/Sydney'));
$expected_values['badges'][0] = [];
// @todo Replace additional_information assertion with lists in EWPP-2508.
$expected_values['lists'] = [
new PatternAssertState(new FieldListAssert(), [
'items' => [
[
'label' => 'Reference',
'body' => 'Call for tenders reference',
], [
'label' => 'Deadline date',
'body' => $deadline_date->format('d F Y, H:i (T)'),
], [
'label' => 'Department',
'body' => 'Audit Board of the European Communities',
],
],
]),
];
$assert->assertPattern($expected_values, $html);
}

Expand Down
Loading

0 comments on commit dfcb4f9

Please sign in to comment.