Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Commit

Permalink
fixed console warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kschmitt20 committed Jul 9, 2020
1 parent f060bd5 commit 431f4cd
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 49 deletions.
61 changes: 32 additions & 29 deletions ui/src/tests/AccountDropdown.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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(
<Router history={history}>
<PeopleMover/>
</Router>
);

await act( async () => {
await wait(async () => {
app = renderWithRedux(
<Router history={history}>
<PeopleMover/>
</Router>
);
});
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('/');
});
Expand Down
47 changes: 27 additions & 20 deletions ui/src/tests/AssignmentForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,16 @@ describe('AssignmentForm', () => {
});

it('submits an assignment with the given person and product', async () => {
const app = renderWithRedux(<PeopleMover/>, undefined, initialState);
await openAssignPersonForm(app);
await act( async () => {
const app = renderWithRedux(<PeopleMover/>, 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({
Expand All @@ -84,14 +86,16 @@ describe('AssignmentForm', () => {
});

it('submits an assignment when the enter key is pressed', async () => {
const app = renderWithRedux(<PeopleMover/>, undefined, initialState);
await openAssignPersonForm(app);
await act(async() => {
const app = renderWithRedux(<PeopleMover/>, 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({
Expand All @@ -105,15 +109,18 @@ describe('AssignmentForm', () => {
});

it('submits an assignment with the given placeholder status', async () => {
const app = renderWithRedux(<PeopleMover/>, undefined, initialState);
await openAssignPersonForm(app);
await act( async() => {
const app = renderWithRedux(<PeopleMover/>, 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({
Expand Down Expand Up @@ -242,4 +249,4 @@ describe('AssignmentForm', () => {
const prefillReactSelectField = async (app: RenderResult, label: string, prefillText: string): Promise<void> => {
const labelElement = await app.findByLabelText(label);
fireEvent.change(labelElement, {target: {value: prefillText}});
};
};

0 comments on commit 431f4cd

Please sign in to comment.