-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add integration tests for speaker + audience views
- Loading branch information
Showing
7 changed files
with
371 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import {connectStorageEmulator, getStorage} from 'firebase/storage'; | ||
import {connectAuthEmulator, signInAnonymously} from 'firebase/auth'; | ||
import {connectFirestoreEmulator, doc, setDoc} from 'firebase/firestore'; | ||
import {RouterProvider, createMemoryRouter} from 'react-router-dom'; | ||
import {app, auth, firestore} from '../firebase'; | ||
import {screen, userEvent, render, findByRole} from '../test/test-utils'; | ||
import Routes from '../Routes'; | ||
|
||
beforeAll(async () => { | ||
const storage = getStorage(app); | ||
connectAuthEmulator(auth, 'http://127.0.0.1:9099'); | ||
connectFirestoreEmulator(firestore, '127.0.0.1', 8080); | ||
connectStorageEmulator(storage, '127.0.0.1', 9199); | ||
|
||
// Use anonymous auth because email link is complicated to emulate | ||
const cred = await signInAnonymously(auth); | ||
|
||
await fetch( | ||
'http://127.0.0.1:8080/emulator/v1/projects/demo-test/databases/(default)/documents/presentations/presentation-2', | ||
{method: 'DELETE'}, | ||
); | ||
|
||
await fetch( | ||
'http://127.0.0.1:8080/emulator/v1/projects/demo-test/databases/(default)/documents/sessions/test', | ||
{method: 'DELETE'}, | ||
); | ||
|
||
await fetch( | ||
'http://127.0.0.1:8080/emulator/v1/projects/demo-test/databases/(default)/documents/sessions/test/reactions', | ||
{method: 'DELETE'}, | ||
); | ||
|
||
// Add a single presentation to firestore | ||
await setDoc(doc(firestore, 'presentations', 'presentation-2'), { | ||
uid: cred.user.uid, | ||
created: Date.now(), | ||
username: 'test user', | ||
pages: ['img1.jpg', 'img2.jpg', 'img3.jpg'], | ||
notes: [], | ||
title: 'test presentation', | ||
}); | ||
}); | ||
|
||
describe('Audience view', () => { | ||
it('synchronizes the current slide', async () => { | ||
const presentationRouter = createMemoryRouter(Routes, { | ||
initialEntries: ['/p/presentation-2?slide=1&session=test'], | ||
}); | ||
const audienceRouter = createMemoryRouter(Routes, { | ||
initialEntries: ['/i/presentation-2?slide=1&session=test'], | ||
}); | ||
|
||
render( | ||
<> | ||
<div data-testid="presentation"> | ||
<RouterProvider router={presentationRouter} /> | ||
</div> | ||
<div data-testid="audience"> | ||
<RouterProvider router={audienceRouter} /> | ||
</div> | ||
</>, | ||
); | ||
|
||
const presentation = await screen.findByTestId('presentation'); | ||
const audience = await screen.findByTestId('audience'); | ||
|
||
await findByRole(audience, 'img', {name: 'Slide page 1'}); | ||
const next = await findByRole(presentation, 'button', {name: 'next'}); | ||
await userEvent.click(next); | ||
const slide2 = await findByRole(audience, 'img', {name: 'Slide page 2'}); | ||
expect(slide2).toHaveAttribute('src', 'img2.jpg'); | ||
}); | ||
|
||
it('renders reactions on audience view', async () => { | ||
const presentationRouter = createMemoryRouter(Routes, { | ||
initialEntries: ['/p/presentation-2?slide=1&session=test'], | ||
}); | ||
const audienceRouter = createMemoryRouter(Routes, { | ||
initialEntries: ['/i/presentation-2?slide=1&session=test'], | ||
}); | ||
|
||
render( | ||
<> | ||
<div data-testid="presentation"> | ||
<RouterProvider router={presentationRouter} /> | ||
</div> | ||
<div data-testid="audience"> | ||
<RouterProvider router={audienceRouter} /> | ||
</div> | ||
</>, | ||
); | ||
|
||
const presentation = await screen.findByTestId('presentation'); | ||
const audience = await screen.findByTestId('audience'); | ||
|
||
await findByRole(presentation, 'img', {name: 'Slide page 1'}); | ||
|
||
const love = await findByRole(audience, 'button', {name: 'love'}); | ||
await userEvent.click(love); | ||
|
||
await findByRole(audience, 'figure', { | ||
name: 'love', | ||
}); | ||
}); | ||
|
||
it('renders reactions on presentation view', async () => { | ||
const presentationRouter = createMemoryRouter(Routes, { | ||
initialEntries: ['/p/presentation-2?slide=1&session=test'], | ||
}); | ||
const audienceRouter = createMemoryRouter(Routes, { | ||
initialEntries: ['/i/presentation-2?slide=1&session=test'], | ||
}); | ||
|
||
render( | ||
<> | ||
<div data-testid="presentation"> | ||
<RouterProvider router={presentationRouter} /> | ||
</div> | ||
<div data-testid="audience"> | ||
<RouterProvider router={audienceRouter} /> | ||
</div> | ||
</>, | ||
); | ||
|
||
const presentation = await screen.findByTestId('presentation'); | ||
const audience = await screen.findByTestId('audience'); | ||
|
||
await findByRole(audience, 'img', {name: 'Slide page 1'}); | ||
|
||
const love = await findByRole(audience, 'button', {name: 'love'}); | ||
await userEvent.click(love); | ||
|
||
await findByRole(presentation, 'figure', { | ||
name: 'love', | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.