diff --git a/src/components/slides/use-presentation.ts b/src/components/slides/use-presentation.ts index 9c2295b..1995f73 100644 --- a/src/components/slides/use-presentation.ts +++ b/src/components/slides/use-presentation.ts @@ -25,7 +25,7 @@ export default function usePresentation(): PresentationAndId { return onSnapshot( doc(firestore, 'presentations', presentationId), (snapshot) => { - if (!snapshot.exists) { + if (!snapshot.exists()) { setPageError( new Error(`Presentation '${presentationId}' does not exist`), ); diff --git a/src/pages/error.e2e.ts b/src/pages/error.e2e.ts new file mode 100644 index 0000000..79be5b9 --- /dev/null +++ b/src/pages/error.e2e.ts @@ -0,0 +1,33 @@ +import {test, expect} from '../test/coverage-fixture'; + +test('displays an error when the presentation does not exist', async ({ + page, +}) => { + const errorLogs: string[] = []; + page.on('console', (message) => { + if (message.type() === 'error') { + errorLogs.push(message.text()); + } + }); + + await page.goto(`/v/does-not-exist`); + + await expect( + page.getByText('Something is not right. Try refreshing or going home.'), + ).toBeVisible(); + + await expect(page.getByRole('link', {name: 'refreshing'})).toHaveAttribute( + 'href', + /\/v\/does-not-exist/, + ); + + await expect(page.getByRole('link', {name: 'home'})).toHaveAttribute( + 'href', + '/', + ); + + expect(errorLogs.length).toBeGreaterThanOrEqual(1); + expect(errorLogs[0]).toMatch( + "Error: Presentation 'does-not-exist' does not exist", + ); +});