Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Create timepoint] test #9392

Merged
merged 3 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 65 additions & 46 deletions modules/create_timepoint/test/TestPlan.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,68 @@
# Create Timepoint Test Plan:

1. Access a candidate that does not have all timepoints from project created
from Access Profile and click "Create time point"
[Automation Testing]
2. Ensure that clicking on all elements of the breadcrumbs takes you to the
appropriate page.
[Manual Testing]
3. Ensure that the DCCID field displays the correct candidate's identifier.
[Manual Testing]
4. Ensure user can only choose from Projects and sites they are affiliated with
5. Ensure the Cohort dropdown is dynamically populated once a site and
project are selected.
[Manual Testing]
6. Ensure the Visit label dropdown is dynamically populated once the Cohort
selection is done.
[Manual Testing]
7. Confirm that options displayed for cohorts and visit labels fields match
the content of the `project_cohort_rel` table and the
`visit_project_cohort_rel` table respectively.
[Manual Testing]
8. Ensure that a popup error is displayed when a project with no cohort
associations is selected.
[Manual Testing]
9. Ensure that a popup error is displayed when a cohort is selected, in
combination with a project, where no visitlabels are defined for that
project-cohort combination.
[Manual Testing]
10. Ensure that if the user is affiliated with a single project and/or a single
site, the Project/site dropdowns are auto-populated with the sole available option
[Manual Testing]
11. Ensure that if the cohort and/or visit label dropdowns contain a single
option only, the option is auto-selected by default
[Manual Testing]
12. choose a site, project and cohort, make sure to select a visit which the
candidate already has. Ensure that an error appears stating that the
visit label already exists for the candidate.
[Manual Testing]
13. Ensure that you get an alert saying: Success! Time Point Created upon a
successful form submission. Click on "Ok" button and ensure that it brings you back
to timepoint list page for that candidate and confirm that the new timepoint appears in the list.
[Manual Testing]
14. Ensure that there is no empty option in the language select element and a language is automatically selected when only one
language exists in the `language` table.
15. Ensure that there is an empty option in the language select element and the field is required when more than one
lagnuage exists in the `language` table
16. Check that page is inaccessible if either the user does not have data_entry
permission or the user and candidate are not the same site.
[Manual Testing]
from Access Profile and click "Create time point".
[Automation Testing]

2. Ensure that clicking on all elements of the breadcrumbs takes you to the
appropriate page.
[Automation Testing]

3. Ensure the DCCID field displays the correct candidate's identifier.
[Automation Testing]

4. Ensure the user can only choose from Projects and Sites they are affiliated with.
[Automation Testing]

5. Ensure the Cohort dropdown is dynamically populated once a site and
project are selected.
[Automation Testing]

6. Ensure the Visit label dropdown is dynamically populated once the Cohort
selection is done.
[Automation Testing]

7. Confirm that options displayed for cohorts and visit labels fields match
the content of the `project_cohort_rel` table and the
`visit_project_cohort_rel` table respectively.
[Automation Testing]

8. Ensure that a popup error is displayed when a project with no cohort
associations is selected.
[Automation Testing]

9. Ensure that a popup error is displayed when a cohort is selected, in
combination with a project, where no visit labels are defined for that
project-cohort combination.
[Automation Testing]

10. Ensure that if the user is affiliated with a single project and/or a single
site, the Project/Site dropdowns are auto-populated with the sole available option.
[Automation Testing]

11. Ensure that if the cohort and/or visit label dropdowns contain a single
option only, the option is auto-selected by default.
[Automation Testing]

12. Choose a site, project, and cohort, and make sure to select a visit which
the candidate already has. Ensure that an error appears stating that the
visit label already exists for the candidate.
[Automation Testing]

13. Ensure that you get an alert saying: "Success! Time Point Created" upon
a successful form submission. Click on "Ok" button and ensure that it brings you back
to the timepoint list page for that candidate and confirm that the new timepoint appears in the list.
[Automation Testing]

14. Ensure that there is no empty option in the language select element, and
a language is automatically selected when only one language exists in the `language` table.
[Automation Testing]

15. Ensure that there is an empty option in the language select element and the field is required when more than one
language exists in the `language` table.
[Automation Testing]

16. Check that the page is inaccessible if either the user does not have data_entry
permission or the user and candidate are not in the same site.
[Automation Testing]

136 changes: 136 additions & 0 deletions modules/create_timepoint/test/create_timepointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,37 @@ function tearDown(): void
{
parent::tearDown();
}
/**
* Tests that, when loading the create_timepoint module, some
* text appears in the body.
*
* @return void
*/
function testCreateTimepointBTN()
{
$this->safeGet(
$this->url . "/900000"
);
$this->safeFindElement(
WebDriverBy::cssSelector(
"#lorisworkspace > div.col-xs-12.row > a:nth-child(2)"
)
)->click();
$bodyText = $this->safeFindElement(
WebDriverBy::cssSelector("body")
)->getText();
$this->assertStringContainsString("Create Time Point", $bodyText);
$this->assertStringNotContainsString(
"You do not have access to this page.",
$bodyText
);
$this->assertStringNotContainsString(
"An error occured while loading the page.",
$bodyText
);
}



/**
* Tests that, when loading the create_timepoint module, some
Expand All @@ -72,6 +103,111 @@ function testCreateTimepointDoespageLoad()
$bodyText
);
}
/**
* Test that ensures the user can only choose from Projects and Sites they are
* affiliated with. Ensure the Cohort dropdown is dynamically populated once
* a Site and Project are selected.
*
* Ensure the Visit label dropdown is dynamically populated once the Cohort
* selection is done.
*
* Confirm that options displayed for Cohort and Visit labels fields match
* the content of the project_cohort_rel table and the visit_project_cohort_rel
* table respectively.
*
* Ensure a popup error is displayed when a project with no cohort associations
* is selected.
*
* Ensure a popup error is displayed when a cohort is selected, in combination
* with a project, where no visit labels are defined for that project-cohort
* combination.
*
* Ensure that if the user is affiliated with a single project and/or site,
* the Project/Site dropdowns are auto-populated with the sole available option.
*
* Ensure that if the Cohort and/or Visit label dropdowns contain a single option
* only, the option is auto-selected by default.
*
* @return void
*/
function testDCCIDandProjectSite()
{
// Safe get the URL with query parameters
$this->safeGet(
$this->url .
"/create_timepoint/?candID=900000&identifier=900000&cohortID=1"
);

// Check the "Data Coordinating Center" dropdown
$this->_assertDropdownSelectedText('psc', 'Data Coordinating Center');

// Check the "Pumpernickel" dropdown
$this->_assertDropdownSelectedText('project', 'Pumpernickel');

// Check the "English" dropdown
$this->_assertDropdownSelectedText('languageID', 'English');

// Check the "cohort" dropdown has "Fresh" and "Stale" as options
$this->_assertDropdownHasOptions('cohort', ['Fresh', 'Stale']);
}

/**
* Helper function to assert that a dropdown has the expected selected text
*
* @param string $elementId The ID of the dropdown element
* @param string $expectedText The expected selected text
*
* @return void
*/
private function _assertDropdownSelectedText($elementId, $expectedText)
{
// Get the dropdown element
$selectElement = $this->safeFindElement(WebDriverBy::id($elementId));

// Create a WebDriverSelect object
$select = new WebDriverSelect($selectElement);

// Get the text of the selected option
$selectedOptionText = $select->getFirstSelectedOption()->getText();

// Assert that the selected text is as expected
$this->assertEquals(
$expectedText,
$selectedOptionText,
"The selected option in '$elementId' is not as expected."
);
}

/**
* Helper function to assert that a dropdown contains specific options
*
* @param string $elementId The ID of the dropdown element
* @param array $expectedOptions The list of expected options in the dropdown
*
* @return void
*/
private function _assertDropdownHasOptions($elementId, array $expectedOptions)
{
// Get the dropdown element
$selectElement = $this->safeFindElement(WebDriverBy::id($elementId));

// Create a WebDriverSelect object
$select = new WebDriverSelect($selectElement);

// Get all options in the dropdown
$allOptions = $select->getOptions();
$optionTexts = array_map(fn($option) => $option->getText(), $allOptions);

// Loop through expected options and assert that each exists
foreach ($expectedOptions as $expectedOption) {
$this->assertTrue(
in_array($expectedOption, $optionTexts),
"The option '$expectedOption' was not found in dropdown."
);
}
}



/**
* Tests that, when loading the create_timepoint module, some
Expand Down
Loading