This repository has been archived by the owner on Jun 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(app): complete layouts coverage (#1052)
- Loading branch information
1 parent
b5ad11f
commit 30f4acc
Showing
10 changed files
with
423 additions
and
15 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
105 changes: 105 additions & 0 deletions
105
packages/app/src/layouts/AdminMain/__tests__/index.test.js
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,105 @@ | ||
import React from "react"; | ||
import { create } from "react-test-renderer"; | ||
|
||
jest.mock("../../AdminMenu"); | ||
jest.mock("../../Main"); | ||
|
||
import AdminMain from ".."; | ||
import AdminMenu from "../../AdminMenu"; | ||
import Main from "../../Main"; | ||
|
||
describe("layouts/<AdminMain />", () => { | ||
const PROPS = {}; | ||
|
||
beforeAll(() => { | ||
Main.mockImplementation(({ children }) => <div>{children}</div>); | ||
}); | ||
|
||
describe(`with {children}=undefined`, () => { | ||
beforeAll(() => { | ||
PROPS.children = undefined; | ||
}); | ||
|
||
it(`should render as expected`, () => { | ||
create(<AdminMain {...PROPS} />); | ||
|
||
expect(AdminMenu).toHaveBeenCalledTimes(1); | ||
expect(Main).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
afterAll(() => { | ||
delete PROPS.children; | ||
}); | ||
}); | ||
|
||
describe(`with {isLoading}`, () => { | ||
beforeAll(() => { | ||
PROPS.isLoading = true; | ||
}); | ||
|
||
it(`should render as expected`, () => { | ||
create(<AdminMain {...PROPS} />); | ||
|
||
expect(AdminMenu).toHaveBeenCalledTimes(1); | ||
expect(Main).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
afterAll(() => { | ||
delete PROPS.isLoading; | ||
}); | ||
}); | ||
|
||
describe(`with {children}=<p>An Element</p>`, () => { | ||
beforeAll(() => { | ||
PROPS.children = <p data-testid="element">An Element</p>; | ||
}); | ||
|
||
it(`should render as expected`, () => { | ||
const $adminMain = create(<AdminMain {...PROPS} />); | ||
|
||
expect(AdminMenu).toHaveBeenCalledTimes(1); | ||
expect(Main).toHaveBeenCalledTimes(1); | ||
expect($adminMain).toHaveTestRenderedProperty("noScroll", false, "content"); | ||
expect($adminMain).toHaveTestRenderedStyleRule("overflow-y", "scroll", {}, "content"); | ||
expect($adminMain).toHaveTestRenderedTextContent(`An Element`, "element"); | ||
}); | ||
|
||
describe(`with {noScroll}`, () => { | ||
beforeAll(() => { | ||
PROPS.noScroll = true; | ||
}); | ||
|
||
it(`should render as expected`, () => { | ||
const $adminMain = create(<AdminMain {...PROPS} />); | ||
|
||
expect($adminMain).toHaveTestRenderedProperty("noScroll", true, "content"); | ||
expect($adminMain).toHaveTestRenderedStyleRule("overflow-y", "hidden", {}, "content"); | ||
expect($adminMain).toHaveTestRenderedTextContent(`An Element`, "element"); | ||
}); | ||
|
||
afterAll(() => { | ||
delete PROPS.noScroll; | ||
}); | ||
}); | ||
|
||
describe(`with {hasBareContent}`, () => { | ||
beforeAll(() => { | ||
PROPS.hasBareContent = true; | ||
}); | ||
|
||
it(`should render as expected`, () => { | ||
const $adminMain = create(<AdminMain {...PROPS} />); | ||
|
||
expect($adminMain).toHaveTestRenderedTextContent(`An Element`, "element"); | ||
}); | ||
|
||
afterAll(() => { | ||
delete PROPS.hasBareContent; | ||
}); | ||
}); | ||
|
||
afterAll(() => { | ||
delete PROPS.children; | ||
}); | ||
}); | ||
}); |
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
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,74 @@ | ||
import React from "react"; | ||
import { create } from "react-test-renderer"; | ||
|
||
jest.mock("next/router"); | ||
|
||
import Router from "next/router"; | ||
|
||
jest.mock("../../Menu"); | ||
jest.mock("../../../cache"); | ||
|
||
import Header from ".."; | ||
import runTestRenderedProperty from "../../../../tests/utils/runTestRenderedProperty"; | ||
import cache from "../../../cache"; | ||
import Menu from "../../Menu"; | ||
|
||
describe("layouts/<Header />", () => { | ||
describe("when the user is not authenticated", () => { | ||
beforeAll(() => { | ||
cache.get.mockReturnValue({ isAuthenticated: false }); | ||
}); | ||
|
||
it(`should render as expected`, () => { | ||
create(<Header />); | ||
|
||
expect(Menu).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe("when the user is authenticated", () => { | ||
beforeAll(() => { | ||
cache.get.mockReturnValue({ isAuthenticated: true }); | ||
}); | ||
|
||
it(`should render as expected`, () => { | ||
create(<Header />); | ||
|
||
expect(Menu).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
describe("when the user is a contributor", () => { | ||
beforeAll(() => { | ||
cache.get.mockReturnValue({ isAdmin: false, isAuthenticated: true }); | ||
}); | ||
|
||
it(`should behave as expected`, () => { | ||
const $header = create(<Header />); | ||
|
||
runTestRenderedProperty($header, "onClick", "brand"); | ||
runTestRenderedProperty($header, "onKeyUp", "brand"); | ||
|
||
expect(Router.push).toHaveBeenCalledTimes(2); | ||
expect(Router.push).toHaveBeenNthCalledWith(1, "/"); | ||
expect(Router.push).toHaveBeenNthCalledWith(2, "/"); | ||
}); | ||
}); | ||
|
||
describe("when the user is an administrator", () => { | ||
beforeAll(() => { | ||
cache.get.mockReturnValue({ isAdmin: true, isAuthenticated: true }); | ||
}); | ||
|
||
it(`should behave as expected`, () => { | ||
const $header = create(<Header />); | ||
|
||
runTestRenderedProperty($header, "onClick", "brand"); | ||
runTestRenderedProperty($header, "onKeyUp", "brand"); | ||
|
||
expect(Router.push).toHaveBeenCalledTimes(2); | ||
expect(Router.push).toHaveBeenNthCalledWith(1, "/admin"); | ||
expect(Router.push).toHaveBeenNthCalledWith(2, "/admin"); | ||
}); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React from "react"; | ||
import { create } from "react-test-renderer"; | ||
|
||
jest.mock("../../Header"); | ||
jest.mock("../../../components/Modal", () => jest.fn(() => null)); | ||
|
||
import Main from ".."; | ||
import ModaWithWrapper from "../../../components/Modal"; | ||
import Header from "../../Header"; | ||
|
||
describe("layouts/<Main />", () => { | ||
const PROPS = {}; | ||
|
||
it(`should render as expected`, () => { | ||
create(<Main {...PROPS} />); | ||
|
||
expect(Header).toHaveBeenCalledTimes(1); | ||
expect(ModaWithWrapper).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
describe(`with {isLoading}`, () => { | ||
beforeAll(() => { | ||
PROPS.isLoading = true; | ||
}); | ||
|
||
it(`should render as expected`, () => { | ||
create(<Main {...PROPS} />); | ||
|
||
expect(Header).toHaveBeenCalledTimes(1); | ||
expect(ModaWithWrapper).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
afterAll(() => { | ||
delete PROPS.isLoading; | ||
}); | ||
}); | ||
|
||
describe(`with {isHorizontal}`, () => { | ||
beforeAll(() => { | ||
PROPS.isHorizontal = true; | ||
}); | ||
|
||
it(`should render as expected`, () => { | ||
create(<Main {...PROPS} />); | ||
|
||
expect(Header).toHaveBeenCalledTimes(1); | ||
expect(ModaWithWrapper).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
afterAll(() => { | ||
delete PROPS.isHorizontal; | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.