shellphone.app/app/pages/index.test.tsx

40 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-08-05 17:07:15 +00:00
import { GlobalRole } from "db";
import { render } from "../../test/utils";
import Home from "./index";
2021-08-05 17:07:15 +00:00
import useCurrentUser from "../core/hooks/use-current-user";
2021-07-31 14:33:18 +00:00
2021-08-05 17:07:15 +00:00
jest.mock("../core/hooks/use-current-user");
const mockUseCurrentUser = useCurrentUser as jest.MockedFunction<typeof useCurrentUser>;
2021-07-31 14:33:18 +00:00
test.skip("renders blitz documentation link", () => {
// This is an example of how to ensure a specific item is in the document
// But it's disabled by default (by test.skip) so the test doesn't fail
// when you remove the the default content from the page
// This is an example on how to mock api hooks when testing
2021-08-05 17:07:15 +00:00
mockUseCurrentUser.mockReturnValue({
organization: undefined,
user: {
2021-07-31 14:33:18 +00:00
id: uuidv4(),
2021-08-05 17:07:15 +00:00
name: "name",
email: "email@test.com",
role: GlobalRole.CUSTOMER,
memberships: [],
2021-07-31 14:33:18 +00:00
},
2021-08-01 14:01:51 +00:00
hasFilledTwilioCredentials: false,
hasCompletedOnboarding: undefined,
});
2021-07-31 14:33:18 +00:00
const { getByText } = render(<Home />);
const linkElement = getByText(/Documentation/i);
expect(linkElement).toBeInTheDocument();
});
2021-07-31 14:33:18 +00:00
function uuidv4() {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
const r = (Math.random() * 16) | 0,
v = c == "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
2021-07-31 14:33:18 +00:00
}