Skip to content

Commit

Permalink
FORSLAG-34: Updated and fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rimi-itk committed Jun 28, 2023
1 parent 099898c commit dedb908
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Versioning](https://semver.org/spec/v2.0.0.html).
* Add Cypress tests
* Add OpenID Connect authentication for citizens
* Add citizen authentication on support proposal form
* Add Playwright tests and fixed tests run in GitHub Actions
* Add [Playwright](https://playwright.dev/) tests and fixed tests run in GitHub
Actions

## [Unreleased]

Expand Down
5 changes: 5 additions & 0 deletions documentation/Testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ docker network create frontend
docker compose up --detach
docker compose exec phpfpm composer install

# Clean up
docker compose exec phpfpm vendor/bin/drush sql:query "DELETE FROM locales_target WHERE customized = 1";
docker compose exec phpfpm vendor/bin/drush state:delete citizen_proposal_admin_form_values --yes
docker compose exec phpfpm vendor/bin/drush cache:rebuild

# Build theme assets
docker compose run --rm node yarn --cwd web/themes/custom/hoeringsportal install
docker compose run --rm node yarn --cwd web/themes/custom/hoeringsportal build
Expand Down
42 changes: 24 additions & 18 deletions playwright/citizen-proposal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ test("Can authenticate", async ({ page }) => {

await page.getByRole("link", { name: "Authenticate with MitID" }).click();

await page.getByLabel("Username").fill("citizen1");
await page.getByLabel("Username", { exact: true }).fill("citizen1");

await page.getByLabel("Password").fill("citizen1");
await page.getByLabel("Password", { exact: true }).fill("citizen1");

await page.getByRole("button", { name: "Login" }).click();

Expand All @@ -24,9 +24,9 @@ test("Create proposal", async ({ page }) => {

await page.getByRole("link", { name: "Authenticate with MitID" }).click();

await page.getByLabel("Username").fill("citizen1");
await page.getByLabel("Username", { exact: true }).fill("citizen1");

await page.getByLabel("Password").fill("citizen1");
await page.getByLabel("Password", { exact: true }).fill("citizen1");

await page.getByRole("button", { name: "Login" }).click();

Expand All @@ -36,18 +36,20 @@ test("Create proposal", async ({ page }) => {

await expect(page.getByRole("link", { name: "Sign out" })).toBeVisible();

await expect(page.getByLabel("Email")).toHaveValue("");
await expect(page.getByLabel("Email", { exact: true })).toHaveValue("");

await page.getByLabel("Email").fill("borger87@eksemple.dk");
await page.getByLabel("Email", { exact: true }).fill("borger87@eksemple.dk");

await page.getByLabel("Overskrift").fill("Sådan løser vi alle problemer!");
await page
.getByLabel("Overskrift", { exact: true })
.fill("Sådan løser vi alle problemer!");

await page
.getByLabel("Proposal")
.getByLabel("Proposal", { exact: true })
.fill("Jeg synes det er et stort problem at …");

await page
.getByLabel("Remarks")
.getByLabel("Remarks", { exact: true })
.fill("Dette vil også løse problemet med at …");

await page.getByRole("button", { name: "Create proposal" }).click();
Expand All @@ -68,9 +70,11 @@ test("Create proposal", async ({ page }) => {

await page.getByRole("link", { name: "Edit proposal" }).click();

await expect(page.getByLabel("Email")).toHaveValue("borger87@eksemple.dk");
await expect(page.getByLabel("Email", { exact: true })).toHaveValue(
"borger87@eksemple.dk"
);

await page.getByLabel("Email").fill("borger87@eksempel.dk");
await page.getByLabel("Email", { exact: true }).fill("borger87@eksempel.dk");

await page.getByRole("button", { name: "Update proposal" }).click();

Expand All @@ -82,30 +86,32 @@ test("Create proposal", async ({ page }) => {

// Test that form has been emptied
await page.goto("/citizen_proposal/add");
await expect(page.getByLabel("Email")).toHaveValue("");
await expect(page.getByLabel("Email", { exact: true })).toHaveValue("");
});

test("Cancel proposal", async ({ page }) => {
await page.goto("/citizen_proposal/add");

await page.getByRole("link", { name: "Authenticate with MitID" }).click();

await page.getByLabel("Username").fill("citizen1");
await page.getByLabel("Username", { exact: true }).fill("citizen1");

await page.getByLabel("Password").fill("citizen1");
await page.getByLabel("Password", { exact: true }).fill("citizen1");

await page.getByRole("button", { name: "Login" }).click();

await page.getByLabel("Email").fill("borger87@eksemple.dk");
await page.getByLabel("Email", { exact: true }).fill("borger87@eksemple.dk");

await page.getByLabel("Overskrift").fill("Sådan løser vi alle problemer!");
await page
.getByLabel("Overskrift", { exact: true })
.fill("Sådan løser vi alle problemer!");

await page
.getByLabel("Proposal")
.getByLabel("Proposal", { exact: true })
.fill("Jeg synes det er et stort problem at …");

await page
.getByLabel("Remarks")
.getByLabel("Remarks", { exact: true })
.fill("Dette vil også løse problemet med at …");

await page.getByRole("button", { name: "Create proposal" }).click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ public function buildForm(array $form, FormStateInterface $form_state) {
// https://www.drupal.org/forum/support/module-development-and-code-questions/2020-06-01/sessions-and-privatetempstore-for#comment-14016801
$form['#cache'] = ['max-age' => 0];

$adminFormStateValues = $this->getAdminFormStateValues();
$userData = $this->getUserData();
if (empty($userData)) {
$adminFormStateValues = $this->getAdminFormStateValues();

$form['authenticate'] = [
'#type' => 'container',

Expand Down

0 comments on commit dedb908

Please sign in to comment.