From 9820860ec3404f5bbb87a65ab7ee99dc155f758c Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Mon, 16 Sep 2024 18:34:02 -0600 Subject: [PATCH] improve tests --- .../04.router/01.problem.router/tests/smoke.test.js | 9 ++++++++- .../04.router/01.solution.router/tests/smoke.test.js | 9 ++++++++- .../04.router/02.problem.pending-ui/tests/smoke.test.js | 9 ++++++++- .../04.router/02.solution.pending-ui/tests/smoke.test.js | 9 ++++++++- .../03.problem.race-conditions/tests/smoke.test.js | 9 ++++++++- .../03.solution.race-conditions/tests/smoke.test.js | 9 ++++++++- .../04.router/04.problem.history/tests/smoke.test.js | 9 ++++++++- .../04.router/04.solution.history/tests/smoke.test.js | 9 ++++++++- exercises/04.router/05.problem.cache/tests/smoke.test.js | 9 ++++++++- .../04.router/05.solution.cache/tests/smoke.test.js | 9 ++++++++- .../01.problem.action-reference/tests/smoke.test.js | 9 ++++++++- .../01.solution.action-reference/tests/smoke.test.js | 9 ++++++++- .../05.actions/02.problem.client/tests/smoke.test.js | 9 ++++++++- .../05.actions/02.solution.client/tests/smoke.test.js | 9 ++++++++- .../05.actions/03.problem.server/tests/smoke.test.js | 9 ++++++++- .../05.actions/03.solution.server/tests/smoke.test.js | 9 ++++++++- .../04.problem.revalidation/tests/smoke.test.js | 9 ++++++++- .../04.solution.revalidation/tests/smoke.test.js | 9 ++++++++- .../05.problem.history-revalidation/tests/smoke.test.js | 9 ++++++++- .../05.solution.history-revalidation/tests/smoke.test.js | 9 ++++++++- 20 files changed, 160 insertions(+), 20 deletions(-) diff --git a/exercises/04.router/01.problem.router/tests/smoke.test.js b/exercises/04.router/01.problem.router/tests/smoke.test.js index 3c800e8..2915ca4 100644 --- a/exercises/04.router/01.problem.router/tests/smoke.test.js +++ b/exercises/04.router/01.problem.router/tests/smoke.test.js @@ -10,11 +10,18 @@ test('should display the home page and perform search', async ({ page }) => { // Perform a search await filterInput.fill('hopper') - await filterInput.press('Enter') // Verify URL change with search params await expect(page).toHaveURL('/?search=hopper') + const shipList = page.getByRole('list').first() + + // Wait for the list to be filtered down to two items + await expect(async () => { + const items = await shipList.getByRole('listitem').all() + expect(items.length).toBe(2) + }).toPass() + // Verify filtered results const shipLinks = page .getByRole('list') diff --git a/exercises/04.router/01.solution.router/tests/smoke.test.js b/exercises/04.router/01.solution.router/tests/smoke.test.js index 3c800e8..2915ca4 100644 --- a/exercises/04.router/01.solution.router/tests/smoke.test.js +++ b/exercises/04.router/01.solution.router/tests/smoke.test.js @@ -10,11 +10,18 @@ test('should display the home page and perform search', async ({ page }) => { // Perform a search await filterInput.fill('hopper') - await filterInput.press('Enter') // Verify URL change with search params await expect(page).toHaveURL('/?search=hopper') + const shipList = page.getByRole('list').first() + + // Wait for the list to be filtered down to two items + await expect(async () => { + const items = await shipList.getByRole('listitem').all() + expect(items.length).toBe(2) + }).toPass() + // Verify filtered results const shipLinks = page .getByRole('list') diff --git a/exercises/04.router/02.problem.pending-ui/tests/smoke.test.js b/exercises/04.router/02.problem.pending-ui/tests/smoke.test.js index 3c800e8..2915ca4 100644 --- a/exercises/04.router/02.problem.pending-ui/tests/smoke.test.js +++ b/exercises/04.router/02.problem.pending-ui/tests/smoke.test.js @@ -10,11 +10,18 @@ test('should display the home page and perform search', async ({ page }) => { // Perform a search await filterInput.fill('hopper') - await filterInput.press('Enter') // Verify URL change with search params await expect(page).toHaveURL('/?search=hopper') + const shipList = page.getByRole('list').first() + + // Wait for the list to be filtered down to two items + await expect(async () => { + const items = await shipList.getByRole('listitem').all() + expect(items.length).toBe(2) + }).toPass() + // Verify filtered results const shipLinks = page .getByRole('list') diff --git a/exercises/04.router/02.solution.pending-ui/tests/smoke.test.js b/exercises/04.router/02.solution.pending-ui/tests/smoke.test.js index 3c800e8..2915ca4 100644 --- a/exercises/04.router/02.solution.pending-ui/tests/smoke.test.js +++ b/exercises/04.router/02.solution.pending-ui/tests/smoke.test.js @@ -10,11 +10,18 @@ test('should display the home page and perform search', async ({ page }) => { // Perform a search await filterInput.fill('hopper') - await filterInput.press('Enter') // Verify URL change with search params await expect(page).toHaveURL('/?search=hopper') + const shipList = page.getByRole('list').first() + + // Wait for the list to be filtered down to two items + await expect(async () => { + const items = await shipList.getByRole('listitem').all() + expect(items.length).toBe(2) + }).toPass() + // Verify filtered results const shipLinks = page .getByRole('list') diff --git a/exercises/04.router/03.problem.race-conditions/tests/smoke.test.js b/exercises/04.router/03.problem.race-conditions/tests/smoke.test.js index 3c800e8..2915ca4 100644 --- a/exercises/04.router/03.problem.race-conditions/tests/smoke.test.js +++ b/exercises/04.router/03.problem.race-conditions/tests/smoke.test.js @@ -10,11 +10,18 @@ test('should display the home page and perform search', async ({ page }) => { // Perform a search await filterInput.fill('hopper') - await filterInput.press('Enter') // Verify URL change with search params await expect(page).toHaveURL('/?search=hopper') + const shipList = page.getByRole('list').first() + + // Wait for the list to be filtered down to two items + await expect(async () => { + const items = await shipList.getByRole('listitem').all() + expect(items.length).toBe(2) + }).toPass() + // Verify filtered results const shipLinks = page .getByRole('list') diff --git a/exercises/04.router/03.solution.race-conditions/tests/smoke.test.js b/exercises/04.router/03.solution.race-conditions/tests/smoke.test.js index 3c800e8..2915ca4 100644 --- a/exercises/04.router/03.solution.race-conditions/tests/smoke.test.js +++ b/exercises/04.router/03.solution.race-conditions/tests/smoke.test.js @@ -10,11 +10,18 @@ test('should display the home page and perform search', async ({ page }) => { // Perform a search await filterInput.fill('hopper') - await filterInput.press('Enter') // Verify URL change with search params await expect(page).toHaveURL('/?search=hopper') + const shipList = page.getByRole('list').first() + + // Wait for the list to be filtered down to two items + await expect(async () => { + const items = await shipList.getByRole('listitem').all() + expect(items.length).toBe(2) + }).toPass() + // Verify filtered results const shipLinks = page .getByRole('list') diff --git a/exercises/04.router/04.problem.history/tests/smoke.test.js b/exercises/04.router/04.problem.history/tests/smoke.test.js index 3c800e8..2915ca4 100644 --- a/exercises/04.router/04.problem.history/tests/smoke.test.js +++ b/exercises/04.router/04.problem.history/tests/smoke.test.js @@ -10,11 +10,18 @@ test('should display the home page and perform search', async ({ page }) => { // Perform a search await filterInput.fill('hopper') - await filterInput.press('Enter') // Verify URL change with search params await expect(page).toHaveURL('/?search=hopper') + const shipList = page.getByRole('list').first() + + // Wait for the list to be filtered down to two items + await expect(async () => { + const items = await shipList.getByRole('listitem').all() + expect(items.length).toBe(2) + }).toPass() + // Verify filtered results const shipLinks = page .getByRole('list') diff --git a/exercises/04.router/04.solution.history/tests/smoke.test.js b/exercises/04.router/04.solution.history/tests/smoke.test.js index 3c800e8..2915ca4 100644 --- a/exercises/04.router/04.solution.history/tests/smoke.test.js +++ b/exercises/04.router/04.solution.history/tests/smoke.test.js @@ -10,11 +10,18 @@ test('should display the home page and perform search', async ({ page }) => { // Perform a search await filterInput.fill('hopper') - await filterInput.press('Enter') // Verify URL change with search params await expect(page).toHaveURL('/?search=hopper') + const shipList = page.getByRole('list').first() + + // Wait for the list to be filtered down to two items + await expect(async () => { + const items = await shipList.getByRole('listitem').all() + expect(items.length).toBe(2) + }).toPass() + // Verify filtered results const shipLinks = page .getByRole('list') diff --git a/exercises/04.router/05.problem.cache/tests/smoke.test.js b/exercises/04.router/05.problem.cache/tests/smoke.test.js index 3c800e8..2915ca4 100644 --- a/exercises/04.router/05.problem.cache/tests/smoke.test.js +++ b/exercises/04.router/05.problem.cache/tests/smoke.test.js @@ -10,11 +10,18 @@ test('should display the home page and perform search', async ({ page }) => { // Perform a search await filterInput.fill('hopper') - await filterInput.press('Enter') // Verify URL change with search params await expect(page).toHaveURL('/?search=hopper') + const shipList = page.getByRole('list').first() + + // Wait for the list to be filtered down to two items + await expect(async () => { + const items = await shipList.getByRole('listitem').all() + expect(items.length).toBe(2) + }).toPass() + // Verify filtered results const shipLinks = page .getByRole('list') diff --git a/exercises/04.router/05.solution.cache/tests/smoke.test.js b/exercises/04.router/05.solution.cache/tests/smoke.test.js index 3c800e8..2915ca4 100644 --- a/exercises/04.router/05.solution.cache/tests/smoke.test.js +++ b/exercises/04.router/05.solution.cache/tests/smoke.test.js @@ -10,11 +10,18 @@ test('should display the home page and perform search', async ({ page }) => { // Perform a search await filterInput.fill('hopper') - await filterInput.press('Enter') // Verify URL change with search params await expect(page).toHaveURL('/?search=hopper') + const shipList = page.getByRole('list').first() + + // Wait for the list to be filtered down to two items + await expect(async () => { + const items = await shipList.getByRole('listitem').all() + expect(items.length).toBe(2) + }).toPass() + // Verify filtered results const shipLinks = page .getByRole('list') diff --git a/exercises/05.actions/01.problem.action-reference/tests/smoke.test.js b/exercises/05.actions/01.problem.action-reference/tests/smoke.test.js index 3c800e8..2915ca4 100644 --- a/exercises/05.actions/01.problem.action-reference/tests/smoke.test.js +++ b/exercises/05.actions/01.problem.action-reference/tests/smoke.test.js @@ -10,11 +10,18 @@ test('should display the home page and perform search', async ({ page }) => { // Perform a search await filterInput.fill('hopper') - await filterInput.press('Enter') // Verify URL change with search params await expect(page).toHaveURL('/?search=hopper') + const shipList = page.getByRole('list').first() + + // Wait for the list to be filtered down to two items + await expect(async () => { + const items = await shipList.getByRole('listitem').all() + expect(items.length).toBe(2) + }).toPass() + // Verify filtered results const shipLinks = page .getByRole('list') diff --git a/exercises/05.actions/01.solution.action-reference/tests/smoke.test.js b/exercises/05.actions/01.solution.action-reference/tests/smoke.test.js index 3c800e8..2915ca4 100644 --- a/exercises/05.actions/01.solution.action-reference/tests/smoke.test.js +++ b/exercises/05.actions/01.solution.action-reference/tests/smoke.test.js @@ -10,11 +10,18 @@ test('should display the home page and perform search', async ({ page }) => { // Perform a search await filterInput.fill('hopper') - await filterInput.press('Enter') // Verify URL change with search params await expect(page).toHaveURL('/?search=hopper') + const shipList = page.getByRole('list').first() + + // Wait for the list to be filtered down to two items + await expect(async () => { + const items = await shipList.getByRole('listitem').all() + expect(items.length).toBe(2) + }).toPass() + // Verify filtered results const shipLinks = page .getByRole('list') diff --git a/exercises/05.actions/02.problem.client/tests/smoke.test.js b/exercises/05.actions/02.problem.client/tests/smoke.test.js index 3c800e8..2915ca4 100644 --- a/exercises/05.actions/02.problem.client/tests/smoke.test.js +++ b/exercises/05.actions/02.problem.client/tests/smoke.test.js @@ -10,11 +10,18 @@ test('should display the home page and perform search', async ({ page }) => { // Perform a search await filterInput.fill('hopper') - await filterInput.press('Enter') // Verify URL change with search params await expect(page).toHaveURL('/?search=hopper') + const shipList = page.getByRole('list').first() + + // Wait for the list to be filtered down to two items + await expect(async () => { + const items = await shipList.getByRole('listitem').all() + expect(items.length).toBe(2) + }).toPass() + // Verify filtered results const shipLinks = page .getByRole('list') diff --git a/exercises/05.actions/02.solution.client/tests/smoke.test.js b/exercises/05.actions/02.solution.client/tests/smoke.test.js index 3c800e8..2915ca4 100644 --- a/exercises/05.actions/02.solution.client/tests/smoke.test.js +++ b/exercises/05.actions/02.solution.client/tests/smoke.test.js @@ -10,11 +10,18 @@ test('should display the home page and perform search', async ({ page }) => { // Perform a search await filterInput.fill('hopper') - await filterInput.press('Enter') // Verify URL change with search params await expect(page).toHaveURL('/?search=hopper') + const shipList = page.getByRole('list').first() + + // Wait for the list to be filtered down to two items + await expect(async () => { + const items = await shipList.getByRole('listitem').all() + expect(items.length).toBe(2) + }).toPass() + // Verify filtered results const shipLinks = page .getByRole('list') diff --git a/exercises/05.actions/03.problem.server/tests/smoke.test.js b/exercises/05.actions/03.problem.server/tests/smoke.test.js index 3c800e8..2915ca4 100644 --- a/exercises/05.actions/03.problem.server/tests/smoke.test.js +++ b/exercises/05.actions/03.problem.server/tests/smoke.test.js @@ -10,11 +10,18 @@ test('should display the home page and perform search', async ({ page }) => { // Perform a search await filterInput.fill('hopper') - await filterInput.press('Enter') // Verify URL change with search params await expect(page).toHaveURL('/?search=hopper') + const shipList = page.getByRole('list').first() + + // Wait for the list to be filtered down to two items + await expect(async () => { + const items = await shipList.getByRole('listitem').all() + expect(items.length).toBe(2) + }).toPass() + // Verify filtered results const shipLinks = page .getByRole('list') diff --git a/exercises/05.actions/03.solution.server/tests/smoke.test.js b/exercises/05.actions/03.solution.server/tests/smoke.test.js index 3c800e8..2915ca4 100644 --- a/exercises/05.actions/03.solution.server/tests/smoke.test.js +++ b/exercises/05.actions/03.solution.server/tests/smoke.test.js @@ -10,11 +10,18 @@ test('should display the home page and perform search', async ({ page }) => { // Perform a search await filterInput.fill('hopper') - await filterInput.press('Enter') // Verify URL change with search params await expect(page).toHaveURL('/?search=hopper') + const shipList = page.getByRole('list').first() + + // Wait for the list to be filtered down to two items + await expect(async () => { + const items = await shipList.getByRole('listitem').all() + expect(items.length).toBe(2) + }).toPass() + // Verify filtered results const shipLinks = page .getByRole('list') diff --git a/exercises/05.actions/04.problem.revalidation/tests/smoke.test.js b/exercises/05.actions/04.problem.revalidation/tests/smoke.test.js index 3c800e8..2915ca4 100644 --- a/exercises/05.actions/04.problem.revalidation/tests/smoke.test.js +++ b/exercises/05.actions/04.problem.revalidation/tests/smoke.test.js @@ -10,11 +10,18 @@ test('should display the home page and perform search', async ({ page }) => { // Perform a search await filterInput.fill('hopper') - await filterInput.press('Enter') // Verify URL change with search params await expect(page).toHaveURL('/?search=hopper') + const shipList = page.getByRole('list').first() + + // Wait for the list to be filtered down to two items + await expect(async () => { + const items = await shipList.getByRole('listitem').all() + expect(items.length).toBe(2) + }).toPass() + // Verify filtered results const shipLinks = page .getByRole('list') diff --git a/exercises/05.actions/04.solution.revalidation/tests/smoke.test.js b/exercises/05.actions/04.solution.revalidation/tests/smoke.test.js index 3c800e8..2915ca4 100644 --- a/exercises/05.actions/04.solution.revalidation/tests/smoke.test.js +++ b/exercises/05.actions/04.solution.revalidation/tests/smoke.test.js @@ -10,11 +10,18 @@ test('should display the home page and perform search', async ({ page }) => { // Perform a search await filterInput.fill('hopper') - await filterInput.press('Enter') // Verify URL change with search params await expect(page).toHaveURL('/?search=hopper') + const shipList = page.getByRole('list').first() + + // Wait for the list to be filtered down to two items + await expect(async () => { + const items = await shipList.getByRole('listitem').all() + expect(items.length).toBe(2) + }).toPass() + // Verify filtered results const shipLinks = page .getByRole('list') diff --git a/exercises/05.actions/05.problem.history-revalidation/tests/smoke.test.js b/exercises/05.actions/05.problem.history-revalidation/tests/smoke.test.js index 3c800e8..2915ca4 100644 --- a/exercises/05.actions/05.problem.history-revalidation/tests/smoke.test.js +++ b/exercises/05.actions/05.problem.history-revalidation/tests/smoke.test.js @@ -10,11 +10,18 @@ test('should display the home page and perform search', async ({ page }) => { // Perform a search await filterInput.fill('hopper') - await filterInput.press('Enter') // Verify URL change with search params await expect(page).toHaveURL('/?search=hopper') + const shipList = page.getByRole('list').first() + + // Wait for the list to be filtered down to two items + await expect(async () => { + const items = await shipList.getByRole('listitem').all() + expect(items.length).toBe(2) + }).toPass() + // Verify filtered results const shipLinks = page .getByRole('list') diff --git a/exercises/05.actions/05.solution.history-revalidation/tests/smoke.test.js b/exercises/05.actions/05.solution.history-revalidation/tests/smoke.test.js index 3c800e8..2915ca4 100644 --- a/exercises/05.actions/05.solution.history-revalidation/tests/smoke.test.js +++ b/exercises/05.actions/05.solution.history-revalidation/tests/smoke.test.js @@ -10,11 +10,18 @@ test('should display the home page and perform search', async ({ page }) => { // Perform a search await filterInput.fill('hopper') - await filterInput.press('Enter') // Verify URL change with search params await expect(page).toHaveURL('/?search=hopper') + const shipList = page.getByRole('list').first() + + // Wait for the list to be filtered down to two items + await expect(async () => { + const items = await shipList.getByRole('listitem').all() + expect(items.length).toBe(2) + }).toPass() + // Verify filtered results const shipLinks = page .getByRole('list')