From a4815c6f14ca9309fcb0991f3b2723e730934aa3 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Thu, 14 Nov 2024 00:24:07 +0100 Subject: [PATCH] Include playwright test for changing guest name --- tests/guests.spec.ts | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/tests/guests.spec.ts b/tests/guests.spec.ts index 26c92b6..d56c5dd 100644 --- a/tests/guests.spec.ts +++ b/tests/guests.spec.ts @@ -1,7 +1,7 @@ -import { test, expect } from '@playwright/test' +import { test, expect, Page } from '@playwright/test' -test('should display the list of guests', async ({ page }) => { - await page.route('*/**/api/guests.json', async route => { +const mockGuestsAPI = ({ page }: { page: Page }) => { + page.route('*/**/api/guests.json', async route => { const json = { data: [ { @@ -29,10 +29,14 @@ test('should display the list of guests', async ({ page }) => { ] }; - await route.fulfill({json}) + await route.fulfill({ json }) }) +} - await page.goto('/dashboard/guests') +test('should display the list of guests', async ({ page }) => { + await mockGuestsAPI({ page }); + + await page.goto('/dashboard/guests'); await expect(page.getByRole('tab', { name: 'Groups' })).toBeVisible(); await expect(page.getByRole('tab', { name: 'Guests' })).toBeVisible(); @@ -42,14 +46,29 @@ test('should display the list of guests', async ({ page }) => { await expect(page.getByRole('row').nth(1).getByRole('cell', { name: 'Kristofer Rohan DVM' })).toBeVisible(); await expect(page.getByRole('row').nth(1).getByRole('cell', { name: 'Childhood friends' })).toBeVisible(); await expect(page.getByRole('row').nth(1).getByRole('cell', { name: 'Tentative' })).toBeVisible(); - await expect(page.getByRole('row').nth(1).getByRole('button', {name: 'Confirm'})).toBeVisible(); - await expect(page.getByRole('row').nth(1).getByRole('button', {name: 'Decline'})).toBeVisible(); + await expect(page.getByRole('row').nth(1).getByRole('button', { name: 'Confirm' })).toBeVisible(); + await expect(page.getByRole('row').nth(1).getByRole('button', { name: 'Decline' })).toBeVisible(); await expect(page.getByRole('row').nth(2).getByRole('cell', { name: 'Olevia Quigley Jr.' })).toBeVisible(); await expect(page.getByRole('row').nth(2).getByRole('cell', { name: 'Work' })).toBeVisible(); await expect(page.getByRole('row').nth(2).getByRole('cell', { name: 'Invited' })).toBeVisible(); - await expect(page.getByRole('row').nth(2).getByRole('button', {name: 'Confirm'})).toBeVisible(); - await expect(page.getByRole('row').nth(2).getByRole('button', {name: 'Tentative'})).toBeVisible(); - await expect(page.getByRole('row').nth(2).getByRole('button', {name: 'Decline'})).toBeVisible(); -}) \ No newline at end of file + await expect(page.getByRole('row').nth(2).getByRole('button', { name: 'Confirm' })).toBeVisible(); + await expect(page.getByRole('row').nth(2).getByRole('button', { name: 'Tentative' })).toBeVisible(); + await expect(page.getByRole('row').nth(2).getByRole('button', { name: 'Decline' })).toBeVisible(); +}); + +test('should allow changing the name of a guest', async ({ page }) => { + await mockGuestsAPI({ page }); + + await page.goto('/dashboard/guests'); + + await expect(page.getByRole('row').nth(1).getByRole('cell', { name: 'Kristofer Rohan DVM' })).toBeVisible(); + + await page.getByRole('row').nth(1).getByRole('cell', { name: 'Kristofer Rohan DVM' }).click(); + await page.getByRole('textbox').clear(); + await page.getByRole('textbox').pressSequentially('John Snow'); + await page.getByRole('textbox').evaluate(e => e.blur()); + + await expect(page.getByRole('row').nth(1).getByRole('cell', { name: 'John Snow' })).toBeVisible(); +}); \ No newline at end of file