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

e2e tests for temporal data - RISDEV-3848 #319

Merged
merged 8 commits into from
May 13, 2024
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
104 changes: 83 additions & 21 deletions frontend/e2e/navigate-to-temporal-data-page-and-test-content.spec.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,96 @@
import { test, expect } from "@playwright/test"

test("navigate to temporal data page for an amending law", async ({ page }) => {
await page.goto(
"/amending-laws/eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1/temporal-data",
)
await expect(
page.locator('[data-testid="temporalDataHeading"]'),
).toBeVisible()
})
test.describe("Navigate to temporal data page", () => {
test("navigate to temporal data page for an amending law using side navigation", async ({
page,
}) => {
await page.goto(
"/amending-laws/eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1",
)

test.describe("Temporal Data for an amending law", () => {
const BASE_URL =
"/amending-laws/eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1/temporal-data"
await page.getByText("Zeitgrenzen anlegen").click()

test.beforeEach(async ({ page }) => {
await page.goto(BASE_URL)
await expect(page).toHaveURL(
`/amending-laws/eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1/temporal-data`,
)

await expect(
page.getByRole("heading", { level: 1, name: "Zeitgrenzen anlegen" }),
).toBeVisible()
})
})

test(`contents of entry into force article html rendering`, async ({
test.describe("management of Temporal Data for an amending law", () => {
test(`adding, editing, deleting and saving time boundaries`, async ({
page,
}) => {
await page.goto(
"/amending-laws/eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1/temporal-data",
)

// check contents of entry into force article html rendering
await expect(page.getByText("Artikel 3Inkrafttreten")).toBeVisible()
})

test(`renders correct number of date inputs for the time boundaries`, async ({
page,
}) => {
const dateInput = page.locator('[data-testid="date-input-field"]')
await expect(dateInput).toHaveCount(1)
const inputValue = await dateInput.inputValue()
const saveButton = page.locator("text=Speichern")
let dateInputs = page.locator('[data-testid="date-input-field"]')

await expect(dateInputs).toHaveCount(1)
const inputValue = await dateInputs.inputValue()
await expect(inputValue).toBe("16.03.2017")
hamo225 marked this conversation as resolved.
Show resolved Hide resolved

// add new time boundaries
const newDateInput = page.locator('[data-testid="new-date-input-field"]')
await newDateInput.fill("01-05-2023")
await newDateInput.fill("02-06-2023")
hamo225 marked this conversation as resolved.
Show resolved Hide resolved
await saveButton.click()

await page.waitForResponse(
(response) =>
response.url().includes("timeBoundaries") && response.status() === 200,
hamo225 marked this conversation as resolved.
Show resolved Hide resolved
)

await page.reload()

await expect(dateInputs).toHaveCount(3)
//edit time boundaries

await expect(dateInputs).toHaveCount(3)
hamo225 marked this conversation as resolved.
Show resolved Hide resolved
const dateInputToEdit = page
.locator('[data-testid="date-input-field"]')
.nth(1)
await dateInputToEdit.fill("03.06.2023")
await saveButton.click()
await page.reload()
hamo225 marked this conversation as resolved.
Show resolved Hide resolved

const editedValue = await dateInputs.nth(1).inputValue()
await expect(editedValue).toBe("03.06.2023")
hamo225 marked this conversation as resolved.
Show resolved Hide resolved

// delete time boundaries

for (let i = 2; i > 0; i--) {
const deleteButton = page.locator(`[data-testid="delete-button-${i}"]`)
await deleteButton.click()
await saveButton.click()
await page.reload()
hamo225 marked this conversation as resolved.
Show resolved Hide resolved
dateInputs = page.locator('[data-testid="date-input-field"]')
await expect(dateInputs).toHaveCount(i)
}

const deleteButton = page.locator(`[data-testid="delete-button-0"]`)
const isDisabled = await deleteButton.isDisabled()
expect(isDisabled).toBe(true)

await page.request.put(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this PUT request? You are not expecting anything from it. And it does not change anything on the state.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PUT is not part of the user interaction. Its for the test, to set up and reset the environment. I have moved this into a function that will be called at the start and end of the test. This whole setup for the tests will change soon i hope.

`/api/v1/norms/eli/bund/bgbl-1/2017/s419/2017-03-15/1/deu/regelungstext-1/timeBoundaries`,
{
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
data: JSON.stringify([
{ date: "2017-03-16", eventRefEid: "meta-1_lebzykl-1_ereignis-2" },
]),
},
)
})
})