From e2159527cd4f02376b1b078eff93e20576e7de69 Mon Sep 17 00:00:00 2001 From: Juan Rodriguez Date: Tue, 2 Apr 2024 11:08:49 +0200 Subject: [PATCH] test: update showASsignmentTitle checks for assignment card --- .env.test | 4 ++- package.json | 2 +- tests/pages/assignments.spec.ts | 46 ++++++++++++++++++++++++++------- tests/pages/home.spec.ts | 9 ++++++- 4 files changed, 48 insertions(+), 13 deletions(-) diff --git a/.env.test b/.env.test index 75b55b4..d0825b2 100644 --- a/.env.test +++ b/.env.test @@ -1,4 +1,6 @@ -HOST=localhost NODE_ENV=test +LOG_LEVEL=fatal + +HOST=localhost SECRET_KEY=secret_123456 DATABASE_URL=db.test.sqlite diff --git a/package.json b/package.json index 0eadfa9..d54b6a5 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .", "start": "remix-serve ./build/server/index.js", "typecheck": "tsc", - "test": "NODE_ENV=test LOG_LEVEL=fatal playwright test --retries=1", + "test": "NODE_ENV=test playwright test --retries=1", "test:ui": "NODE_ENV=test DEBUG=pw:webserver playwright test --ui", "db:drop": "rm -rf db.sqlite*", "db:check": "drizzle-kit check:sqlite", diff --git a/tests/pages/assignments.spec.ts b/tests/pages/assignments.spec.ts index 886af52..ac93714 100644 --- a/tests/pages/assignments.spec.ts +++ b/tests/pages/assignments.spec.ts @@ -119,18 +119,24 @@ test.describe('Assignments page - Admin', () => { test.describe('Show Assignment', () => { test('should go to show assignment page', async ({ page }) => { const assignment = page.getByRole('row').nth(ASSIGNMENT_ROW); - const showAssignmentButton = assignment.locator('a').first(); + const showAssignmentLink = assignment.locator('a').first(); const assignmentTitle = await assignment.getByRole('cell').first().textContent(); const assignmentContent = await assignment.getByRole('cell').nth(4).textContent(); const assignmentDueAt = await assignment.getByRole('cell').nth(6).textContent(); const assignmentCreatedAt = await assignment.getByRole('cell').nth(7).textContent(); - const showAssignmentUrl = await showAssignmentButton.getAttribute('href'); + const showAssignmentUrl = await showAssignmentLink.getAttribute('href'); + + await showAssignmentLink.click(); - await showAssignmentButton.click(); + const showASsignmentTitle = await page + .getByLabel('Breadcrumb') + .getByRole('link') + .nth(1) + .textContent(); await expect(page).toHaveURL(showAssignmentUrl!); - await expect(page.locator('h1')).toHaveText(assignmentTitle!); + expect(showASsignmentTitle).toBe(assignmentTitle!); await expect(page.getByText(assignmentContent!)).toBeVisible(); await expect(page.getByText(assignmentDueAt!)).toBeVisible(); await expect(page.getByText(assignmentCreatedAt!)).toBeVisible(); @@ -231,7 +237,14 @@ test.describe('Assignments page - Admin', () => { await page.waitForLoadState('networkidle'); await page.goto(showAssignmentUrl!); - await expect(page.locator('h1')).toHaveText(title); + + const showASsignmentTitle = await page + .getByLabel('Breadcrumb') + .getByRole('link') + .nth(1) + .textContent(); + + expect(showASsignmentTitle).toBe(title); // restore previous title await page.goto(editAssignmentUrl!); @@ -340,18 +353,24 @@ test.describe('Assignments page - Teacher', () => { test('should go to show assignment page', async ({ page }) => { const assignment = page.getByRole('row').nth(ASSIGNMENT_ROW); - const showAssignmentButton = assignment.locator('a').first(); + const showAssignmentLink = assignment.locator('a').first(); const assignmentTitle = await assignment.getByRole('cell').first().textContent(); const assignmentContent = await assignment.getByRole('cell').nth(4).textContent(); const assignmentDueAt = await assignment.getByRole('cell').nth(6).textContent(); const assignmentCreatedAt = await assignment.getByRole('cell').nth(7).textContent(); - const showAssignmentUrl = await showAssignmentButton.getAttribute('href'); + const showAssignmentUrl = await showAssignmentLink.getAttribute('href'); + + await showAssignmentLink.click(); - await showAssignmentButton.click(); + const showASsignmentTitle = await page + .getByLabel('Breadcrumb') + .getByRole('link') + .nth(1) + .textContent(); await expect(page).toHaveURL(showAssignmentUrl!); - await expect(page.locator('h1')).toHaveText(assignmentTitle!); + expect(showASsignmentTitle).toBe(assignmentTitle!); await expect(page.getByText(assignmentContent!)).toBeVisible(); await expect(page.getByText(assignmentDueAt!)).toBeVisible(); await expect(page.getByText(assignmentCreatedAt!)).toBeVisible(); @@ -466,7 +485,14 @@ test.describe('Assignments page - Teacher', () => { await page.waitForLoadState('networkidle'); await page.goto(showAssignmentUrl!); - await expect(page.locator('h1')).toHaveText(title); + + const showASsignmentTitle = await page + .getByLabel('Breadcrumb') + .getByRole('link') + .nth(1) + .textContent(); + + expect(showASsignmentTitle).toBe(title); // restore previous title await page.goto(editAssignmentUrl!); diff --git a/tests/pages/home.spec.ts b/tests/pages/home.spec.ts index 8c11036..7eed849 100644 --- a/tests/pages/home.spec.ts +++ b/tests/pages/home.spec.ts @@ -48,7 +48,14 @@ test.describe('Home page - Admin', () => { await assignmentLink.click(); await expect(page).toHaveURL(assignmentUrl!); - await expect(page.locator('h1')).toHaveText(assignmentTitle); + + const showASsignmentTitle = await page + .getByLabel('Breadcrumb') + .getByRole('link') + .nth(1) + .textContent(); + + expect(showASsignmentTitle).toBe(assignmentTitle); }); });