Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
ISAICP-6449: Add a regression test.
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiu-cristea committed Mar 24, 2021
1 parent 992805a commit 38fd911
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ Feature: "Add document" visibility options.
When I go to the homepage of the "Hunter in the Swords" collection
Then I should see the link "An amazing document"

# Check that the publication date field is prefilled with the current time.
When I go to the homepage of the "Hunter in the Swords" collection
And I click "Add document" in the plus button menu
Then I see "Publication date" filled with the current time

# Regression test to ensure that no critical errors are thrown when a new
# revision is created for a document that has a remote file attached.
# @see https://citnet.tech.ec.europa.eu/CITnet/jira/browse/ISAICP-3670
Expand Down
31 changes: 31 additions & 0 deletions tests/src/Context/JoinupContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,37 @@ public function clearDateRangeField($field, $component, $date = NULL) {
$element->setValue('');
}

/**
* Asserts that a date/time field is prefilled with the current time.
*
* @param string $field
* The date/time field name.
*
* @throws \Exception
* When the field is not found.
*
* @Then I see :field filled with the current time
*/
public function assertDateTimeFieldValue(string $field): void {
$now = new \DateTimeImmutable();

$date_part = $this->findDateRangeComponent($field, 'date')->getAttribute('value');
$time_part = $this->findDateRangeComponent($field, 'time')->getAttribute('value');
if (empty($date_part) || empty($time_part)) {
throw new ExpectationFailedException("The '{$field}' date/time field is not filled with the current time.");
}

$date = new \DateTimeImmutable("{$date_part} {$time_part}");

$interval = $now->diff($date);
// Given that such a test cannot do an exact assertion, because of the
// testing environment latency, we consider 3 seconds as an acceptable
// fuzziness.
if ($interval->f > 3000) {
throw new ExpectationFailedException("The '{$field}' date/time field is not filled with the current time.");
}
}

/**
* Finds a datetime field.
*
Expand Down

0 comments on commit 38fd911

Please sign in to comment.