Skip to content

Commit

Permalink
test: update showASsignmentTitle checks for assignment card
Browse files Browse the repository at this point in the history
  • Loading branch information
sjdonado committed Apr 2, 2024
1 parent b5351ea commit e215952
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 13 deletions.
4 changes: 3 additions & 1 deletion .env.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
HOST=localhost
NODE_ENV=test
LOG_LEVEL=fatal

HOST=localhost
SECRET_KEY=secret_123456
DATABASE_URL=db.test.sqlite
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
46 changes: 36 additions & 10 deletions tests/pages/assignments.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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!);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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!);
Expand Down
9 changes: 8 additions & 1 deletion tests/pages/home.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down

0 comments on commit e215952

Please sign in to comment.