describe('Loading', () => { it('should show loading and change UI after 3 seconds', async () => { const { getByText, getByTestId } = render(<Loading />); const loading = getByText(/loading/i); expect(loading).toBeVisible(); await waitForElement(() => getByTestId('loading')); expect(getByTestId('loading')).toBeInTheDocument(); }) })
test('count up', async () => { const { getByText } = render(<Counter />) fireEvent.click(getByText('Inc')) await waitForElement(() => getByText(/Count:/)) expect(getByText('Count: 1')).toBeInTheDocument() })
it('renders an error when authentication fails', async () => { const { getByText, getByTestId, queryByTestId, getByLabelText } = render( <SignInView />, ) const emailField = getByLabelText('Email') const passwordField = getByLabelText('Password') const submitButton = getByText('Submit') expect(submitButton).toHaveAttribute('disabled') fireEvent.focus(emailField) fireEvent.change(emailField, { target: { value: 'test@fail.com' } }) fireEvent.blur(emailField) fireEvent.focus(passwordField) fireEvent.change(passwordField, { target: { value: '1234567890' } }) fireEvent.blur(passwordField) expect(submitButton).not.toHaveAttribute('disabled') fireEvent.click(submitButton) await waitForElement(() => getByTestId('form-error')) expect(queryByTestId('form-message')).toBeNull() expect(getByTestId('form-error').textContent).toBe( 'There was a login failure.', ) })
xdescribe('Profile Page', () => { // automatically unmount and cleanup DOM after the test is finished. afterEach(cleanup); it('renders profile page', async () => { const mocks = [ { request: { query: GET_MY_TRIPS }, result: { data: { me: mockMe } }, }, ]; const { getByText } = renderApollo(<Profile />, { mocks }); // if the profile renders, it will have the list of missions booked await waitForElement(() => getByText(/test mission/i)); }); });
expect(loading).toBeDefined(); await waitForElement(() => getByText(/Data from Users/i));
]; const { getByTestId } = renderApollo(<Cart />, { mocks, cache }); return waitForElement(() => getByTestId('empty-message')); }); ]; const { getByTestId } = renderApollo(<Cart />, { mocks, cache: undefined }); return waitForElement(() => getByTestId('empty-message')); }); });
await waitForElement(() => getByText(/log in/i));
return waitForElement(() => getByText(/test mission/i)); }); }); waitForElement(() => getByText(/error: aw shucks/i)); }); });
); fireEvent.click(getByTestId('action-button')); await waitForElement(() => getByTestId('action-button'));
const successText = await waitForElement(() => getByTestId('message')); });
// TODO: un-skip after local state fixes xdescribe('Launch Page', () => { // automatically unmount and cleanup DOM after the test is finished. afterEach(cleanup); it('renders launch', async () => { const mocks = [ { request: { query: GET_LAUNCH_DETAILS, variables: { launchId: 1 } }, result: { data: { launch: mockLaunch } }, }, ]; const { getByText } = await renderApollo(<Launch launchId={1} />, { mocks, }); await waitForElement(() => getByText(/test mission/i)); }); });
// TODO: un-skip after local state fixes xdescribe('Launches Page', () => { // automatically unmount and cleanup DOM after the test is finished. afterEach(cleanup); it('renders launches', async () => { const mocks = [ { request: { query: GET_LAUNCHES }, result: { data: { isLoggedIn: true, launches: { cursor: '123', hasMore: true, launches: [mockLaunch] }, }, }, }, ]; const { getByText } = await renderApollo(<Launches />, { mocks, }); await waitForElement(() => getByText(/test mission/i)); }); });
test('count down', async () => { const { getByText } = render(<Counter />) fireEvent.click(getByText('Dec')) await waitForElement(() => getByText(/Count:/)) expect(getByText('Count: -1')).toBeInTheDocument() })
it('renders an message when authentication succeeds', async () => { const { getByText, getByTestId, queryByTestId, getByLabelText } = render( <SignInView />, ) const emailField = getByLabelText('Email') const passwordField = getByLabelText('Password') const submitButton = getByText('Submit') expect(submitButton).toHaveAttribute('disabled') fireEvent.focus(emailField) fireEvent.change(emailField, { target: { value: 'test@succeed.com' } }) fireEvent.blur(emailField) fireEvent.focus(passwordField) fireEvent.change(passwordField, { target: { value: '1234567890' } }) fireEvent.blur(passwordField) expect(submitButton).not.toHaveAttribute('disabled') fireEvent.click(submitButton) await waitForElement(() => getByTestId('form-message')) expect(queryByTestId('form-error')).toBeNull() expect(getByTestId('form-message').textContent).toBe('You are logged in!') })