This repository has been archived by the owner on Jun 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MF-56: Add logout to primary nav bar (#5)
* MF-56: Add logout to primary nav bar * Review changes * Fix breaking build
- Loading branch information
1 parent
009e0ba
commit 7cd583b
Showing
8 changed files
with
301 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { of } from "rxjs"; | ||
|
||
export function openmrsFetch() { | ||
return new Promise(() => {}); | ||
} | ||
|
||
export function getCurrentUser() { | ||
return of({ authenticated: false }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,80 @@ | ||
import React from "react"; | ||
import { render, cleanup } from "@testing-library/react"; | ||
import { render, cleanup, fireEvent, wait } from "@testing-library/react"; | ||
import Root from "./root.component"; | ||
import { of } from "rxjs"; | ||
import { getCurrentUser } from "@openmrs/esm-api"; | ||
import { act } from "react-dom/test-utils"; | ||
import { createMemoryHistory } from "history"; | ||
import { Router } from "react-router"; | ||
|
||
function renderWithRouter( | ||
ui, | ||
{ | ||
route = "/", | ||
history = createMemoryHistory({ initialEntries: [route] }), | ||
match = { params: {}, isExact: true, path: "", url: "" } | ||
} = {} | ||
) { | ||
return { | ||
...render(<Router history={history}>{ui}</Router>), | ||
history, | ||
match | ||
}; | ||
} | ||
|
||
const mockGetCurrentUser = getCurrentUser as jest.Mock; | ||
window["getOpenmrsSpaBase"] = jest.fn().mockImplementation(() => "/"); | ||
afterAll(cleanup); | ||
|
||
const mockUser = { | ||
authenticated: true, | ||
user: { | ||
uuid: "uuid", | ||
display: "admin", | ||
person: { uuid: "uuid", display: "Test User" }, | ||
privileges: [], | ||
roles: [{ uuid: "uuid", display: "System Developer" }] | ||
} | ||
}; | ||
|
||
jest.mock("@openmrs/esm-api", () => ({ | ||
openmrsFetch: jest.fn().mockResolvedValue({}), | ||
getCurrentUser: jest | ||
.fn() | ||
.mockImplementation(() => ({ subscribe: () => {}, unsubscribe: () => {} })) | ||
})); | ||
|
||
describe(`<Root />`, () => { | ||
it(`renders without dying`, () => { | ||
const wrapper = render(<Root />); | ||
let wrapper; | ||
act(() => { | ||
wrapper = render(<Root />); | ||
}); | ||
}); | ||
|
||
it(`renders avatar`, async () => { | ||
mockGetCurrentUser.mockImplementation(() => of(mockUser)); | ||
let wrapper; | ||
act(() => { | ||
wrapper = render(<Root />); | ||
}); | ||
await wait(() => expect(wrapper.getByText("TU")).not.toBeNull()); | ||
}); | ||
|
||
it(`logs out patient`, async () => { | ||
mockGetCurrentUser.mockImplementation(() => of(mockUser)); | ||
let wrapper; | ||
act(() => { | ||
wrapper = renderWithRouter(<Root />); | ||
}); | ||
const userMenuBtn = wrapper.container.querySelector(".avatar"); | ||
act(() => { | ||
fireEvent.click(userMenuBtn); | ||
}); | ||
const logoutBtn = wrapper.getByText(/Logout/i); | ||
expect(logoutBtn).not.toBeNull(); | ||
act(() => { | ||
fireEvent.click(logoutBtn); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.