From 431f4cd531205542576b1c8bcddfdbd7414358fb Mon Sep 17 00:00:00 2001 From: Kari Schmitt Date: Wed, 8 Jul 2020 20:57:08 -0400 Subject: [PATCH] fixed console warnings --- ui/src/tests/AccountDropdown.test.tsx | 61 ++++++++++++++------------- ui/src/tests/AssignmentForm.test.tsx | 47 ++++++++++++--------- 2 files changed, 59 insertions(+), 49 deletions(-) diff --git a/ui/src/tests/AccountDropdown.test.tsx b/ui/src/tests/AccountDropdown.test.tsx index 0861bfa87..b34e9eacf 100644 --- a/ui/src/tests/AccountDropdown.test.tsx +++ b/ui/src/tests/AccountDropdown.test.tsx @@ -15,7 +15,7 @@ * limitations under the License. */ -import {fireEvent, RenderResult, wait} from '@testing-library/react'; +import {act, fireEvent, RenderResult, wait} from '@testing-library/react'; import TestUtils, {renderWithRedux} from './TestUtils'; import PeopleMover from '../Application/PeopleMover'; import React from 'react'; @@ -36,56 +36,59 @@ describe('Account Dropdown', () => { process.env.REACT_APP_INVITE_USERS_TO_SPACE_ENABLED = 'true'; history = createMemoryHistory({ initialEntries: ['/teamName'] }); - - await wait(async () => { - - app = renderWithRedux( - - - - ); - + await act( async () => { + await wait(async () => { + app = renderWithRedux( + + + + ); + }); + const userIconButton = await app.findByTestId('userIcon'); + fireEvent.click(userIconButton); }); - const userIconButton = await app.findByTestId('userIcon'); - fireEvent.click(userIconButton); }); it('Should open Edit Contributors modal on click of text in dropdown', async () => { - fireEvent.click(await app.findByText('Invite Contributors')); + await act( async() => { + fireEvent.click(await app.findByText('Invite Contributors')); + }); expect(app.getByText('Edit Contributors')); }); it('should close Edit Contributors modal on click of Cancel button', async () => { - fireEvent.click(await app.findByText('Invite Contributors')); - const cancelButton = await app.findByText('Cancel'); - fireEvent.click(cancelButton); - + await act( async() => { + fireEvent.click(await app.findByText('Invite Contributors')); + const cancelButton = await app.findByText('Cancel'); + fireEvent.click(cancelButton); + }); expect(app.queryByText('Edit Contributors')).toBe(null); }); it('should submit invited contributors, current space name, and access token on click of Save button', async () => { - fireEvent.click(await app.findByText('Invite Contributors')); - SpaceClient.inviteUsersToSpace = jest.fn().mockImplementation(() => Promise.resolve({})); + await act( async() => { + fireEvent.click(await app.findByText('Invite Contributors')); + SpaceClient.inviteUsersToSpace = jest.fn().mockImplementation(() => Promise.resolve({})); - const usersToInvite = app.getByTestId('emailTextArea'); - fireEvent.change(usersToInvite, { target: { value: 'some1@email.com,some2@email.com,some3@email.com' } }); - - const saveButton = await app.findByText('Save'); - fireEvent.click(saveButton); + const usersToInvite = app.getByTestId('emailTextArea'); + fireEvent.change(usersToInvite, {target: {value: 'some1@email.com,some2@email.com,some3@email.com'}}); + const saveButton = await app.findByText('Save'); + fireEvent.click(saveButton); + }); expect(SpaceClient.inviteUsersToSpace).toHaveBeenCalledWith('teamName', ['some1@email.com', 'some2@email.com', 'some3@email.com']); }); it('should remove accessToken from cookies and redirect to homepage on click of sign out', async () => { - const cookies = new Cookies(); + await act( async() => { - cookies.set('accessToken', 'FAKE_TOKEN'); + cookies.set('accessToken', 'FAKE_TOKEN'); - expect(cookies.get('accessToken')).toEqual('FAKE_TOKEN'); - - fireEvent.click(await app.findByText('Sign Out')); + expect(cookies.get('accessToken')).toEqual('FAKE_TOKEN'); + fireEvent.click(await app.findByText('Sign Out')); + }); expect(cookies.get('accessToken')).toBeUndefined(); expect(history.location.pathname).toEqual('/'); }); diff --git a/ui/src/tests/AssignmentForm.test.tsx b/ui/src/tests/AssignmentForm.test.tsx index 7a47b24e3..7972eb2e9 100644 --- a/ui/src/tests/AssignmentForm.test.tsx +++ b/ui/src/tests/AssignmentForm.test.tsx @@ -63,14 +63,16 @@ describe('AssignmentForm', () => { }); it('submits an assignment with the given person and product', async () => { - const app = renderWithRedux(, undefined, initialState); - await openAssignPersonForm(app); + await act( async () => { + const app = renderWithRedux(, undefined, initialState); + await openAssignPersonForm(app); - const labelElement = await app.findByLabelText('Name'); - const containerToFindOptionsIn = { container: await app.findByTestId('assignmentForm') }; - await selectEvent.select(labelElement, /Person 1/, containerToFindOptionsIn); + const labelElement = await app.findByLabelText('Name'); + const containerToFindOptionsIn = { container: await app.findByTestId('assignmentForm') }; + await selectEvent.select(labelElement, /Person 1/, containerToFindOptionsIn); - fireEvent.click(app.getByText('Assign')); + fireEvent.click(app.getByText('Assign')); + }); expect(AssignmentClient.createAssignmentForDate).toBeCalledTimes(1); expect(AssignmentClient.createAssignmentForDate).toBeCalledWith({ @@ -84,14 +86,16 @@ describe('AssignmentForm', () => { }); it('submits an assignment when the enter key is pressed', async () => { - const app = renderWithRedux(, undefined, initialState); - await openAssignPersonForm(app); + await act(async() => { + const app = renderWithRedux(, undefined, initialState); + await openAssignPersonForm(app); - const labelElement = await app.findByLabelText('Name'); - const containerToFindOptionsIn = { container: await app.findByTestId('assignmentForm') }; - await selectEvent.select(labelElement, /Person 1/, containerToFindOptionsIn); + const labelElement = await app.findByLabelText('Name'); + const containerToFindOptionsIn = { container: await app.findByTestId('assignmentForm') }; + await selectEvent.select(labelElement, /Person 1/, containerToFindOptionsIn); - fireEvent.keyDown(app.getByText('Assign'), {key: 'Enter', code: 13}); + fireEvent.keyDown(app.getByText('Assign'), {key: 'Enter', code: 13}); + }); expect(AssignmentClient.createAssignmentForDate).toBeCalledTimes(1); expect(AssignmentClient.createAssignmentForDate).toBeCalledWith({ @@ -105,15 +109,18 @@ describe('AssignmentForm', () => { }); it('submits an assignment with the given placeholder status', async () => { - const app = renderWithRedux(, undefined, initialState); - await openAssignPersonForm(app); + await act( async() => { + const app = renderWithRedux(, undefined, initialState); + await openAssignPersonForm(app); - const labelElement = await app.findByLabelText('Name'); - const containerToFindOptionsIn = { container: await app.findByTestId('assignmentForm') }; - await selectEvent.select(labelElement, /Person 1/, containerToFindOptionsIn); + const labelElement = await app.findByLabelText('Name'); + const containerToFindOptionsIn = { container: await app.findByTestId('assignmentForm') }; + await selectEvent.select(labelElement, /Person 1/, containerToFindOptionsIn); + + fireEvent.click(app.getByLabelText('Mark as Placeholder')); + fireEvent.click(app.getByText('Assign')); + }); - fireEvent.click(app.getByLabelText('Mark as Placeholder')); - fireEvent.click(app.getByText('Assign')); expect(AssignmentClient.createAssignmentForDate).toBeCalledTimes(1); expect(AssignmentClient.createAssignmentForDate).toBeCalledWith({ @@ -242,4 +249,4 @@ describe('AssignmentForm', () => { const prefillReactSelectField = async (app: RenderResult, label: string, prefillText: string): Promise => { const labelElement = await app.findByLabelText(label); fireEvent.change(labelElement, {target: {value: prefillText}}); -}; \ No newline at end of file +};