|
| 1 | +import React from 'react'; |
| 2 | +import {render, screen} from '@testing-library/preact'; |
| 3 | +import userEvent from '@testing-library/user-event'; |
| 4 | +import AdoptionForm from '~/pages/adoption/adoption'; |
| 5 | +import FormHeader from '~/components/form-header/form-header'; |
| 6 | +import MemoryRouter from '~/../../test/helpers/future-memory-router'; |
| 7 | +import {MainClassContextProvider} from '~/contexts/main-class'; |
| 8 | +import {SharedDataContextProvider} from '~/contexts/shared-data'; |
| 9 | +import {LanguageContextProvider} from '~/contexts/language'; |
| 10 | +import usePortalContext, {PortalContextProvider} from '~/contexts/portal'; |
| 11 | + |
| 12 | +describe('adoption-form', () => { |
| 13 | + const saveWarn = console.warn; |
| 14 | + |
| 15 | + beforeAll(() => { |
| 16 | + console.warn = jest.fn(); |
| 17 | + }); |
| 18 | + afterAll(() => { |
| 19 | + console.warn = saveWarn; |
| 20 | + }); |
| 21 | + |
| 22 | + beforeEach(async () => { |
| 23 | + render( |
| 24 | + <LanguageContextProvider> |
| 25 | + <SharedDataContextProvider> |
| 26 | + <MemoryRouter |
| 27 | + initialEntries={['/details/books/college-algebra', '/adoption']} |
| 28 | + > |
| 29 | + <MainClassContextProvider> |
| 30 | + <AdoptionForm /> |
| 31 | + </MainClassContextProvider> |
| 32 | + </MemoryRouter> |
| 33 | + </SharedDataContextProvider> |
| 34 | + </LanguageContextProvider> |
| 35 | + ); |
| 36 | + await screen.findByText(/Let us know you're using/); |
| 37 | + }); |
| 38 | + |
| 39 | + it('creates with role selector', () => |
| 40 | + expect(screen.queryAllByRole('option', {hidden: true})).toHaveLength(8)); |
| 41 | + |
| 42 | + it('form appears when role is selected', async () => { |
| 43 | + const listBoxes = screen.queryAllByRole('listbox'); |
| 44 | + const user = userEvent.setup(); |
| 45 | + |
| 46 | + await user.click(listBoxes[1]); |
| 47 | + const options = await screen.findAllByRole('option', {hidden: true}); |
| 48 | + const instructorOption = options.find( |
| 49 | + (o) => o.textContent === 'Instructor' |
| 50 | + ); |
| 51 | + |
| 52 | + await user.click(instructorOption as HTMLElement); |
| 53 | + await screen.findByRole('form'); |
| 54 | + }); |
| 55 | +}); |
| 56 | + |
| 57 | +describe('form-header in portal', () => { |
| 58 | + function Component() { |
| 59 | + const {setPortal} = usePortalContext(); |
| 60 | + |
| 61 | + setPortal('some-portal'); |
| 62 | + |
| 63 | + return <FormHeader prefix="adoption" />; |
| 64 | + } |
| 65 | + |
| 66 | + it('rewrites links', async () => { |
| 67 | + render( |
| 68 | + <LanguageContextProvider> |
| 69 | + <MemoryRouter initialEntries={['/some-portal/adoption']}> |
| 70 | + <PortalContextProvider> |
| 71 | + <Component /> |
| 72 | + </PortalContextProvider> |
| 73 | + </MemoryRouter> |
| 74 | + </LanguageContextProvider> |
| 75 | + ); |
| 76 | + const link = await screen.findByRole('link'); |
| 77 | + |
| 78 | + expect(link.getAttribute('href')).toBe('/some-portal/interest'); |
| 79 | + }); |
| 80 | +}); |
0 commit comments