From 80b11d4449b2f6959a616e8df64b0fcaed58bcd3 Mon Sep 17 00:00:00 2001 From: Dennis Kigen Date: Thu, 3 Mar 2022 11:58:47 +0300 Subject: [PATCH 1/2] (test) Enhancements to tests in the login app --- .../esm-login-app/__mocks__/config.mock.ts | 18 ++ .../__mocks__/lodash.debounce.mock.ts | 3 - .../__mocks__/lodash.isEmpty.mock.ts | 3 - .../__mocks__/openmrs-esm-framework.mock.tsx | 68 -------- packages/apps/esm-login-app/jest.config.js | 6 +- .../change-location-link.component.test.tsx | 6 +- .../choose-location.component.test.tsx | 162 ++++++++++-------- .../location-picker.component.test.tsx | 87 +++++----- .../src/login/login.component.test.tsx | 71 ++++---- .../src/login/login.component.tsx | 1 + .../esm-login-app/src/root.component.test.tsx | 10 -- 11 files changed, 193 insertions(+), 242 deletions(-) create mode 100644 packages/apps/esm-login-app/__mocks__/config.mock.ts delete mode 100644 packages/apps/esm-login-app/__mocks__/lodash.debounce.mock.ts delete mode 100644 packages/apps/esm-login-app/__mocks__/lodash.isEmpty.mock.ts delete mode 100644 packages/apps/esm-login-app/__mocks__/openmrs-esm-framework.mock.tsx delete mode 100644 packages/apps/esm-login-app/src/root.component.test.tsx diff --git a/packages/apps/esm-login-app/__mocks__/config.mock.ts b/packages/apps/esm-login-app/__mocks__/config.mock.ts new file mode 100644 index 000000000..f2bc82a7e --- /dev/null +++ b/packages/apps/esm-login-app/__mocks__/config.mock.ts @@ -0,0 +1,18 @@ +export const mockConfig = { + provider: { + type: "basic", + loginUrl: "", + logoutUrl: "", + }, + chooseLocation: { + enabled: true, + numberToShow: 3, + }, + logo: { + src: null, + alt: "Logo", + }, + links: { + loginSuccess: "${openmrsSpaBase}/home", + }, +}; diff --git a/packages/apps/esm-login-app/__mocks__/lodash.debounce.mock.ts b/packages/apps/esm-login-app/__mocks__/lodash.debounce.mock.ts deleted file mode 100644 index 58e8f185f..000000000 --- a/packages/apps/esm-login-app/__mocks__/lodash.debounce.mock.ts +++ /dev/null @@ -1,3 +0,0 @@ -const debounce = jest.fn((fn) => fn); - -export default debounce; diff --git a/packages/apps/esm-login-app/__mocks__/lodash.isEmpty.mock.ts b/packages/apps/esm-login-app/__mocks__/lodash.isEmpty.mock.ts deleted file mode 100644 index f2a882d67..000000000 --- a/packages/apps/esm-login-app/__mocks__/lodash.isEmpty.mock.ts +++ /dev/null @@ -1,3 +0,0 @@ -const isEmpty = jest.fn((arr) => arr.length === 0); - -export default isEmpty; diff --git a/packages/apps/esm-login-app/__mocks__/openmrs-esm-framework.mock.tsx b/packages/apps/esm-login-app/__mocks__/openmrs-esm-framework.mock.tsx deleted file mode 100644 index fdd44da92..000000000 --- a/packages/apps/esm-login-app/__mocks__/openmrs-esm-framework.mock.tsx +++ /dev/null @@ -1,68 +0,0 @@ -import { of } from "rxjs"; -import React from "react"; - -export function openmrsFetch() { - return new Promise(() => {}); -} - -export function getCurrentUser() { - return of({ authenticated: false }); -} - -export function defineConfigSchema() {} - -export const setSessionLocation = jest.fn(() => Promise.resolve()); - -export const validators = { - isBoolean: jest.fn(), - isString: jest.fn(), -}; - -export const navigate = jest.fn(); - -export const Type = { - Array: "Array", - Boolean: "Boolean", - ConceptUuid: "ConceptUuid", - Number: "Number", - Object: "Object", - String: "String", - UUID: "UUID", -}; - -export function createErrorHandler() { - return function errorHandler(err) { - console.log(`Received error ${err}`); - }; -} - -export const openmrsComponentDecorator = jest - .fn() - .mockImplementation(() => (f) => f); - -export const config = { - provider: { - type: "basic", - loginUrl: "", - logoutUrl: "", - }, - chooseLocation: { - enabled: true, - numberToShow: 3, - }, - logo: { - src: null, - alt: "Logo", - }, - links: { - loginSuccess: "${openmrsSpaBase}/home", - }, -}; - -export function useConfig() { - return config; -} - -export const ComponentContext = React.createContext({ - moduleName: "fake-module-config", -}); diff --git a/packages/apps/esm-login-app/jest.config.js b/packages/apps/esm-login-app/jest.config.js index 347dc73cd..ca826223d 100644 --- a/packages/apps/esm-login-app/jest.config.js +++ b/packages/apps/esm-login-app/jest.config.js @@ -5,11 +5,9 @@ module.exports = { moduleNameMapper: { "^@carbon/icons-react/es/(.*)$": "@carbon/icons-react/lib/$1", "^carbon-components-react/es/(.*)$": "carbon-components-react/lib/$1", - "@openmrs/esm-framework": - "/__mocks__/openmrs-esm-framework.mock.tsx", + "@openmrs/esm-framework": "@openmrs/esm-framework/mock", "\\.(s?css)$": "identity-obj-proxy", - "lodash-es/debounce": "/__mocks__/lodash.debounce.mock.ts", - "lodash-es/isEmpty": "/__mocks__/lodash.isEmpty.mock.ts", + "^lodash-es/(.*)$": "lodash/$1", }, setupFiles: ["/src/setup-tests.js"], }; diff --git a/packages/apps/esm-login-app/src/change-location-link/change-location-link.component.test.tsx b/packages/apps/esm-login-app/src/change-location-link/change-location-link.component.test.tsx index 497d7e925..f02e30646 100644 --- a/packages/apps/esm-login-app/src/change-location-link/change-location-link.component.test.tsx +++ b/packages/apps/esm-login-app/src/change-location-link/change-location-link.component.test.tsx @@ -20,12 +20,14 @@ describe("", () => { ); }); - it("should display the change link", async () => { + it("should display the `Change location` link", async () => { const changeLocationButton = await screen.findByRole("button", { name: /Change/i, }); + fireEvent.click(changeLocationButton); - expect(navigate).toHaveBeenCalledWith({ + + expect(navigateMock).toHaveBeenCalledWith({ to: "${openmrsSpaBase}/login/location?returnToUrl=/openmrs/spa/home", }); }); diff --git a/packages/apps/esm-login-app/src/choose-location/choose-location.component.test.tsx b/packages/apps/esm-login-app/src/choose-location/choose-location.component.test.tsx index e09917ad9..c027b33ba 100644 --- a/packages/apps/esm-login-app/src/choose-location/choose-location.component.test.tsx +++ b/packages/apps/esm-login-app/src/choose-location/choose-location.component.test.tsx @@ -1,14 +1,14 @@ import "@testing-library/jest-dom"; -import { act } from "react-dom/test-utils"; -import { cleanup, wait } from "@testing-library/react"; -import { navigate } from "@openmrs/esm-framework"; +import { waitFor } from "@testing-library/react"; +import { navigate, useConfig } from "@openmrs/esm-framework"; import { queryLocations } from "./choose-location.resource"; +import { mockConfig } from "../../__mocks__/config.mock"; import ChooseLocation from "./choose-location.component"; import renderWithRouter from "../test-helpers/render-with-router"; const navigateMock = navigate as jest.Mock; - -const { config } = require("@openmrs/esm-framework"); +const mockedQueryLocations = queryLocations as jest.Mock; +const mockedUseConfig = useConfig as jest.Mock; jest.mock("../CurrentUserContext", () => ({ useCurrentUser() { @@ -19,19 +19,21 @@ jest.mock("../CurrentUserContext", () => ({ })); jest.mock("./choose-location.resource.ts", () => ({ - queryLocations: jest.fn(() => - Promise.resolve([ - { - resource: { - id: "abc", - name: "foo", - }, + queryLocations: jest.fn().mockResolvedValue([ + { + resource: { + id: "abc", + name: "foo", }, - ]) - ), + }, + ]), })); describe(``, () => { + beforeEach(() => { + mockedUseConfig.mockReturnValue(mockConfig); + }); + afterEach(() => { navigateMock.mockClear(); }); @@ -42,99 +44,117 @@ describe(``, () => { referrer: "/home/patient-search", }, }; - cleanup(); + renderWithRouter(ChooseLocation, { location: locationMock, isLoginEnabled: true, }); - await act(wait); - expect(navigate).toHaveBeenCalledWith({ - to: "${openmrsSpaBase}" + locationMock.state.referrer, - }); + + await waitFor(() => + expect(navigate).toHaveBeenCalledWith({ + to: "${openmrsSpaBase}" + locationMock.state.referrer, + }) + ); }); it(`should set location and skip location select page if there is exactly one location`, async () => { - cleanup(); renderWithRouter(ChooseLocation, { isLoginEnabled: true }); - await act(wait); - expect(navigate).toHaveBeenCalledWith({ to: "${openmrsSpaBase}/home" }); + + await waitFor(() => + expect(navigate).toHaveBeenCalledWith({ to: "${openmrsSpaBase}/home" }) + ); }); it(`should set location and skip location select page if there is no location`, async () => { - cleanup(); - (queryLocations as any).mockImplementationOnce(() => Promise.resolve([])); + mockedQueryLocations.mockResolvedValueOnce([]); + renderWithRouter(ChooseLocation, { isLoginEnabled: true }); - await act(wait); - expect(navigate).toHaveBeenCalledWith({ to: "${openmrsSpaBase}/home" }); + + await waitFor(() => + expect(navigate).toHaveBeenCalledWith({ to: "${openmrsSpaBase}/home" }) + ); }); it(`should show the location picker when multiple locations exist`, async () => { - cleanup(); - (queryLocations as any).mockImplementationOnce(() => - Promise.resolve([ - { - resource: { - id: "abc", - name: "foo", - }, + mockedQueryLocations.mockResolvedValueOnce([ + { + resource: { + id: "abc", + name: "foo", }, - { - resource: { - id: "def", - name: "ghi", - }, + }, + { + resource: { + id: "def", + name: "ghi", }, - ]) - ); + }, + ]); + renderWithRouter(ChooseLocation, { isLoginEnabled: true }); - await act(wait); - expect(navigate).not.toHaveBeenCalled(); + + await waitFor(() => expect(navigate).not.toHaveBeenCalled()); }); it(`should not show the location picker when disabled`, async () => { - cleanup(); - config.chooseLocation.enabled = false; - (queryLocations as any).mockImplementationOnce(() => - Promise.resolve([ - { - resource: { - id: "abc", - name: "foo", - }, + mockedUseConfig.mockReturnValue({ + ...mockConfig, + chooseLocation: { + enabled: false, + }, + }); + + mockedQueryLocations.mockResolvedValueOnce([ + { + resource: { + id: "abc", + name: "foo", }, - { - resource: { - id: "def", - name: "ghi", - }, + }, + { + resource: { + id: "def", + name: "ghi", }, - ]) + }, + ]); + + renderWithRouter(ChooseLocation, { isLoginEnabled: true }); + + await waitFor(() => + expect(navigate).toHaveBeenCalledWith({ to: "${openmrsSpaBase}/home" }) ); - const wrapper = renderWithRouter(ChooseLocation, { isLoginEnabled: true }); - await act(wait); - expect(navigate).toHaveBeenCalledWith({ to: "${openmrsSpaBase}/home" }); }); it(`should redirect to custom path if configured`, async () => { - cleanup(); - config.links.loginSuccess = "${openmrsSpaBase}/foo"; - const wrapper = renderWithRouter(ChooseLocation, { isLoginEnabled: true }); - await act(wait); - expect(navigate).toHaveBeenCalledWith({ to: "${openmrsSpaBase}/foo" }); + mockedUseConfig.mockReturnValue({ + ...mockConfig, + links: { + loginSuccess: "${openmrsSpaBase}/foo", + }, + }); + + renderWithRouter(ChooseLocation, { isLoginEnabled: true }); + + await waitFor(() => + expect(navigate).toHaveBeenCalledWith({ to: "${openmrsSpaBase}/foo" }) + ); }); it(`should redirect back to returnUrl when provided`, async () => { const locationMock = { search: "?returnToUrl=/openmrs/spa/home", }; - cleanup(); + renderWithRouter(ChooseLocation, { location: locationMock, isLoginEnabled: true, }); - await act(wait); - expect(navigate).toHaveBeenCalledWith({ - to: "/openmrs/spa/home", - }); + + await waitFor(() => + expect(navigate).toHaveBeenCalledWith({ + to: "/openmrs/spa/home", + }) + ); }); }); diff --git a/packages/apps/esm-login-app/src/location-picker/location-picker.component.test.tsx b/packages/apps/esm-login-app/src/location-picker/location-picker.component.test.tsx index 551f5e6fa..18059a404 100644 --- a/packages/apps/esm-login-app/src/location-picker/location-picker.component.test.tsx +++ b/packages/apps/esm-login-app/src/location-picker/location-picker.component.test.tsx @@ -2,13 +2,9 @@ import "@testing-library/jest-dom"; import React from "react"; import LocationPicker from "./location-picker.component"; import { act } from "react-dom/test-utils"; -import { - cleanup, - fireEvent, - render, - wait, - screen, -} from "@testing-library/react"; +import { fireEvent, render, waitFor, screen } from "@testing-library/react"; +import { useConfig } from "@openmrs/esm-framework"; +import { mockConfig } from "../../__mocks__/config.mock"; const loginLocations = { data: { @@ -19,11 +15,14 @@ const loginLocations = { }, }; +const mockedUseConfig = useConfig as jest.Mock; + +jest.mock("lodash-es/debounce", () => jest.fn((fn) => fn)); + describe(``, () => { let searchInput, marsInput, submitButton, - wrapper, locationEntries, onChangeLocation, searchLocations; @@ -37,13 +36,15 @@ describe(``, () => { writable: true, }); + mockedUseConfig.mockReturnValue(mockConfig); + // reset mocks locationEntries = loginLocations.data.entry; onChangeLocation = jest.fn(() => {}); searchLocations = jest.fn(() => Promise.resolve([])); - //prepare components - wrapper = render( + // prepare components + render( `, () => { /> ); - searchInput = wrapper.container.querySelector("input"); - submitButton = wrapper.getByText("Confirm", { selector: "button" }); + searchInput = screen.getByRole("searchbox"); + submitButton = screen.getByText("Confirm", { selector: "button" }); }); - afterEach(cleanup); - it("trigger search on typing", async () => { - cleanup(); searchLocations = jest.fn(() => Promise.resolve(loginLocations)); - wrapper = render( + + render( `, () => { fireEvent.change(searchInput, { target: { value: "mars" } }); - await wait(() => { - expect(wrapper.getByLabelText("Mars")).not.toBeNull(); + await waitFor(() => { + expect(screen.getByLabelText("Mars")).not.toBeNull(); }); }); @@ -84,16 +83,16 @@ describe(``, () => { fireEvent.change(searchInput, { target: { value: "Mars" } }); }); - await wait(() => { - expect(wrapper.queryByText("Mars")).not.toBeNull(); - marsInput = wrapper.getByLabelText("Mars"); + await waitFor(() => { + expect(screen.queryByText("Mars")).not.toBeNull(); + marsInput = screen.getByLabelText("Mars"); }); act(() => { fireEvent.click(marsInput); }); - await wait(() => { + await waitFor(() => { expect(submitButton).not.toHaveAttribute("disabled"); }); }); @@ -105,15 +104,15 @@ describe(``, () => { fireEvent.change(searchInput, { target: { value: "Mars" } }); }); - await wait(() => { - expect(wrapper.queryByText("Mars")).not.toBeNull(); - marsInput = wrapper.getByLabelText("Mars"); + await waitFor(() => { + expect(screen.queryByText("Mars")).not.toBeNull(); + marsInput = screen.getByLabelText("Mars"); }); fireEvent.click(marsInput); fireEvent.click(submitButton); - await wait(() => expect(onChangeLocation).toHaveBeenCalled()); + await waitFor(() => expect(onChangeLocation).toHaveBeenCalled()); }); it(`send the user to the home page on submit`, async () => { @@ -123,15 +122,15 @@ describe(``, () => { fireEvent.change(searchInput, { target: { value: "Mars" } }); }); - await wait(() => { - expect(wrapper.queryByText("Mars")).not.toBeNull(); - marsInput = wrapper.getByLabelText("Mars"); + await waitFor(() => { + expect(screen.queryByText("Mars")).not.toBeNull(); + marsInput = screen.getByLabelText("Mars"); }); fireEvent.click(marsInput); fireEvent.click(submitButton); - await wait(() => { + await waitFor(() => { expect(onChangeLocation).toHaveBeenCalled(); }); }); @@ -143,17 +142,17 @@ describe(``, () => { fireEvent.change(searchInput, { target: { value: "Mars" } }); }); - await wait(() => { - expect(wrapper.queryByText("Mars")).not.toBeNull(); - marsInput = wrapper.getByLabelText("Mars"); + await waitFor(() => { + expect(screen.queryByText("Mars")).not.toBeNull(); + marsInput = screen.getByLabelText("Mars"); }); - submitButton = wrapper.getByText("Confirm", { selector: "button" }); + submitButton = screen.getByText("Confirm", { selector: "button" }); fireEvent.click(marsInput); fireEvent.click(submitButton); - await wait(() => { + await waitFor(() => { expect(onChangeLocation).toHaveBeenCalled(); }); }); @@ -163,7 +162,7 @@ describe(``, () => { }); it("should deselect active location when user searches for a location", async () => { - const locationRadioButton: HTMLElement = await wrapper.getByRole("radio", { + const locationRadioButton: HTMLElement = await screen.getByRole("radio", { name: /Earth/, }); fireEvent.click(locationRadioButton); @@ -175,9 +174,9 @@ describe(``, () => { it("shows error message when no matching locations can be found", async () => { fireEvent.change(searchInput, { target: { value: "doof" } }); - await wait(() => { + await waitFor(() => { expect( - wrapper.getByText("Sorry, no matching location was found") + screen.getByText("Sorry, no matching location was found") ).not.toBeNull(); }); expect(submitButton).toHaveAttribute("disabled"); @@ -187,14 +186,14 @@ describe(``, () => { expect( window.localStorage.getItem("userDefaultLoginLocationKeyDemo") ).toEqual("111"); - const locationRadioButton: HTMLElement = await wrapper.getByRole("radio", { + const locationRadioButton: HTMLElement = await screen.getByRole("radio", { name: /Earth/, }); expect(locationRadioButton).toHaveProperty("checked", true); }); it("should set user Default location when location is changed", async () => { - const locationRadioButton: HTMLElement = await wrapper.findByLabelText( + const locationRadioButton: HTMLElement = await screen.findByLabelText( /Earth/ ); fireEvent.click(locationRadioButton); @@ -207,7 +206,7 @@ describe(``, () => { it("should display the correct pageSize", async () => { expect(screen.getByText(/Showing 2 of 2 locations/i)).toBeInTheDocument(); - cleanup(); + const loginLocations: any = { data: { entry: [ @@ -217,7 +216,8 @@ describe(``, () => { ], }, }; - const wrapper = render( + + render( `, () => { isLoginEnabled={true} /> ); - expect(wrapper.getByText(/Showing 3 of 3 locations/i)).toBeInTheDocument(); + + expect(screen.getByText(/Showing 3 of 3 locations/i)).toBeInTheDocument(); }); }); diff --git a/packages/apps/esm-login-app/src/login/login.component.test.tsx b/packages/apps/esm-login-app/src/login/login.component.test.tsx index ab15c8485..191e21035 100644 --- a/packages/apps/esm-login-app/src/login/login.component.test.tsx +++ b/packages/apps/esm-login-app/src/login/login.component.test.tsx @@ -1,12 +1,13 @@ import "@testing-library/jest-dom"; import Login from "./login.component"; import { useState } from "react"; -import { cleanup, wait } from "@testing-library/react"; -import { setSessionLocation } from "@openmrs/esm-framework"; +import { waitFor, screen } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import { setSessionLocation, useConfig } from "@openmrs/esm-framework"; import { performLogin } from "./login.resource"; import { useCurrentUser } from "../CurrentUserContext"; +import { mockConfig } from "../../__mocks__/config.mock"; import renderWithRouter from "../test-helpers/render-with-router"; -import userEvent from "@testing-library/user-event"; const mockedLogin = performLogin as jest.Mock; @@ -16,6 +17,7 @@ jest.mock("./login.resource", () => ({ const mockedSetSessionLocation = setSessionLocation as jest.Mock; const mockedUseCurrentUser = useCurrentUser as jest.Mock; +const mockedUseConfig = useConfig as jest.Mock; jest.mock("../CurrentUserContext", () => ({ useCurrentUser: jest.fn(), @@ -31,22 +33,23 @@ describe(``, () => { mockedLogin.mockReset(); mockedSetSessionLocation.mockReset(); mockedUseCurrentUser.mockReset(); + mockedUseConfig.mockReturnValue(mockConfig); }); - afterEach(cleanup); - it(`renders a login form`, () => { - const wrapper = renderWithRouter(Login, { + renderWithRouter(Login, { loginLocations: loginLocations, isLoginEnabled: true, }); - wrapper.getByRole("textbox", { name: /Username/i }); - wrapper.getByRole("button", { name: /Continue/i }); + screen.getByRole("img", { name: /OpenMRS svg/i }); + expect(screen.queryByAltText(/logo/i)).not.toBeInTheDocument(); + screen.getByRole("textbox", { name: /Username/i }); + screen.getByRole("button", { name: /Continue/i }); }); it(`should return user focus to username input when input is invalid`, () => { - const wrapper = renderWithRouter( + renderWithRouter( Login, { loginLocations: loginLocations, @@ -59,25 +62,22 @@ describe(``, () => { ); expect( - wrapper.getByRole("textbox", { name: /username/i }) + screen.getByRole("textbox", { name: /username/i }) ).toBeInTheDocument(); - userEvent.type(wrapper.getByRole("textbox", { name: /Username/i }), ""); - const continueButton = wrapper.getByRole("button", { name: /Continue/i }); + userEvent.type(screen.getByRole("textbox", { name: /Username/i }), ""); + const continueButton = screen.getByRole("button", { name: /Continue/i }); userEvent.click(continueButton); - expect(wrapper.getByRole("textbox", { name: /username/i })).toHaveFocus(); - userEvent.type( - wrapper.getByRole("textbox", { name: /Username/i }), - "yoshi" - ); + expect(screen.getByRole("textbox", { name: /username/i })).toHaveFocus(); + userEvent.type(screen.getByRole("textbox", { name: /Username/i }), "yoshi"); userEvent.click(continueButton); - userEvent.type(wrapper.getByLabelText("password"), "yoshi"); - expect(wrapper.getByLabelText(/password/i)).toHaveFocus(); + userEvent.type(screen.getByLabelText("password"), "yoshi"); + expect(screen.getByLabelText(/password/i)).toHaveFocus(); }); it(`makes an API request when you submit the form`, async () => { mockedLogin.mockReturnValue(Promise.resolve({ some: "data" })); - const wrapper = renderWithRouter( + renderWithRouter( Login, { loginLocations: loginLocations, @@ -90,18 +90,16 @@ describe(``, () => { ); expect(performLogin).not.toHaveBeenCalled(); - userEvent.type( - wrapper.getByRole("textbox", { name: /Username/i }), - "yoshi" + userEvent.type(screen.getByRole("textbox", { name: /Username/i }), "yoshi"); + userEvent.click(screen.getByRole("button", { name: /Continue/i })); + userEvent.type(screen.getByLabelText("password"), "no-tax-fraud"); + userEvent.click(screen.getByRole("button", { name: /submit/i })); + await waitFor(() => + expect(performLogin).toHaveBeenCalledWith("yoshi", "no-tax-fraud") ); - userEvent.click(wrapper.getByRole("button", { name: /Continue/i })); - userEvent.type(wrapper.getByLabelText("password"), "no-tax-fraud"); - userEvent.click(wrapper.getByRole("button", { name: /submit/i })); - await wait(); - expect(performLogin).toHaveBeenCalledWith("yoshi", "no-tax-fraud"); }); - it(`send the user to the location select page on login if there is more than one location`, async () => { + it(`sends the user to the location select page on login if there is more than one location`, async () => { let refreshUser = (user: any) => {}; mockedLogin.mockImplementation(() => { refreshUser({ @@ -130,15 +128,12 @@ describe(``, () => { } ); - userEvent.type( - wrapper.getByRole("textbox", { name: /Username/i }), - "yoshi" + userEvent.type(screen.getByRole("textbox", { name: /Username/i }), "yoshi"); + userEvent.click(screen.getByRole("button", { name: /Continue/i })); + userEvent.type(screen.getByLabelText("password"), "no-tax-fraud"); + userEvent.click(screen.getByRole("button", { name: /submit/i })); + await waitFor(() => + expect(wrapper.history.location.pathname).toBe("/login/location") ); - userEvent.click(wrapper.getByRole("button", { name: /Continue/i })); - userEvent.type(wrapper.getByLabelText("password"), "no-tax-fraud"); - userEvent.click(wrapper.getByRole("button", { name: /submit/i })); - await wait(); - - expect(wrapper.history.location.pathname).toBe("/login/location"); }); }); diff --git a/packages/apps/esm-login-app/src/login/login.component.tsx b/packages/apps/esm-login-app/src/login/login.component.tsx index c41fa5be6..06d03e2e0 100644 --- a/packages/apps/esm-login-app/src/login/login.component.tsx +++ b/packages/apps/esm-login-app/src/login/login.component.tsx @@ -123,6 +123,7 @@ const Login: React.FC = ({ history, location, isLoginEnabled }) => { /> ) : ( + OpenMRS svg ); diff --git a/packages/apps/esm-login-app/src/root.component.test.tsx b/packages/apps/esm-login-app/src/root.component.test.tsx deleted file mode 100644 index 9c11626f4..000000000 --- a/packages/apps/esm-login-app/src/root.component.test.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import React from "react"; -import { render, cleanup } from "@testing-library/react"; -import Root from "./root.component"; - -describe(``, () => { - afterEach(cleanup); - it(`renders without dying`, () => { - render(); - }); -}); From 1862e94b6bce5ab54ca1d35cea44c16ffffef358 Mon Sep 17 00:00:00 2001 From: Dennis Kigen Date: Thu, 3 Mar 2022 20:31:22 +0300 Subject: [PATCH 2/2] Review feedback --- packages/apps/esm-login-app/src/login/login.component.test.tsx | 2 +- packages/apps/esm-login-app/src/login/login.component.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/apps/esm-login-app/src/login/login.component.test.tsx b/packages/apps/esm-login-app/src/login/login.component.test.tsx index 191e21035..a0aee267e 100644 --- a/packages/apps/esm-login-app/src/login/login.component.test.tsx +++ b/packages/apps/esm-login-app/src/login/login.component.test.tsx @@ -42,7 +42,7 @@ describe(``, () => { isLoginEnabled: true, }); - screen.getByRole("img", { name: /OpenMRS svg/i }); + screen.getByRole("img", { name: /OpenMRS logo/i }); expect(screen.queryByAltText(/logo/i)).not.toBeInTheDocument(); screen.getByRole("textbox", { name: /Username/i }); screen.getByRole("button", { name: /Continue/i }); diff --git a/packages/apps/esm-login-app/src/login/login.component.tsx b/packages/apps/esm-login-app/src/login/login.component.tsx index 06d03e2e0..f92073693 100644 --- a/packages/apps/esm-login-app/src/login/login.component.tsx +++ b/packages/apps/esm-login-app/src/login/login.component.tsx @@ -123,7 +123,7 @@ const Login: React.FC = ({ history, location, isLoginEnabled }) => { /> ) : ( - OpenMRS svg + OpenMRS logo );