2020-10-16 12:38:04 +00:00
|
|
|
import React from "react";
|
|
|
|
import { mount } from "enzyme";
|
|
|
|
import PageLayout from ".";
|
2019-11-25 11:18:12 +00:00
|
|
|
|
|
|
|
const baseProps = {
|
2020-01-24 11:59:55 +00:00
|
|
|
withBodyScroll: true,
|
2020-10-16 12:38:04 +00:00
|
|
|
withBodyAutoFocus: false,
|
|
|
|
};
|
2019-11-25 11:18:12 +00:00
|
|
|
|
2020-10-16 12:38:04 +00:00
|
|
|
describe("<PageLayout />", () => {
|
|
|
|
it("renders without error", () => {
|
|
|
|
const wrapper = mount(<PageLayout {...baseProps} />);
|
2019-11-25 11:18:12 +00:00
|
|
|
|
|
|
|
expect(wrapper).toExist();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("componentDidUpdate() test re-render", () => {
|
2020-10-16 12:38:04 +00:00
|
|
|
const wrapper = mount(<PageLayout {...baseProps} />).instance();
|
2019-11-25 11:18:12 +00:00
|
|
|
|
|
|
|
wrapper.componentDidUpdate({ withBodyScroll: false });
|
|
|
|
|
|
|
|
expect(wrapper.props).toBe(wrapper.props);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("componentDidUpdate() test no re-render", () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<PageLayout
|
|
|
|
{...baseProps}
|
|
|
|
articleHeaderContent={<>1</>}
|
|
|
|
articleMainButtonContent={<>2</>}
|
|
|
|
articleBodyContent={<>3</>}
|
|
|
|
sectionHeaderContent={<>4</>}
|
|
|
|
sectionFilterContent={<>5</>}
|
|
|
|
sectionBodyContent={<>6</>}
|
|
|
|
sectionPagingContent={<>7</>}
|
|
|
|
withBodyScroll={false}
|
|
|
|
/>
|
|
|
|
).instance();
|
|
|
|
|
|
|
|
wrapper.componentDidUpdate(wrapper.props);
|
|
|
|
|
|
|
|
expect(wrapper.props.withBodyScroll).toBe(false);
|
|
|
|
|
|
|
|
wrapper.componentDidUpdate(wrapper.props);
|
|
|
|
|
|
|
|
expect(wrapper.props).toBe(wrapper.props);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("call backdropClick()", () => {
|
2020-10-16 12:38:04 +00:00
|
|
|
const wrapper = mount(<PageLayout {...baseProps} />).instance();
|
2019-11-25 11:18:12 +00:00
|
|
|
|
|
|
|
wrapper.backdropClick();
|
|
|
|
|
|
|
|
expect(wrapper.state.isBackdropVisible).toBe(false);
|
|
|
|
expect(wrapper.state.isArticleVisible).toBe(false);
|
|
|
|
expect(wrapper.state.isArticlePinned).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("call pinArticle()", () => {
|
2020-10-16 12:38:04 +00:00
|
|
|
const wrapper = mount(<PageLayout {...baseProps} />).instance();
|
2019-11-25 11:18:12 +00:00
|
|
|
|
|
|
|
wrapper.pinArticle();
|
|
|
|
|
|
|
|
expect(wrapper.state.isBackdropVisible).toBe(false);
|
|
|
|
expect(wrapper.state.isArticleVisible).toBe(true);
|
|
|
|
expect(wrapper.state.isArticlePinned).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("call unpinArticle()", () => {
|
2020-10-16 12:38:04 +00:00
|
|
|
const wrapper = mount(<PageLayout {...baseProps} />).instance();
|
2019-11-25 11:18:12 +00:00
|
|
|
|
|
|
|
wrapper.unpinArticle();
|
|
|
|
|
|
|
|
expect(wrapper.state.isBackdropVisible).toBe(true);
|
|
|
|
expect(wrapper.state.isArticleVisible).toBe(true);
|
|
|
|
expect(wrapper.state.isArticlePinned).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("call showArticle()", () => {
|
2020-10-16 12:38:04 +00:00
|
|
|
const wrapper = mount(<PageLayout {...baseProps} />).instance();
|
2019-11-25 11:18:12 +00:00
|
|
|
|
|
|
|
wrapper.showArticle();
|
|
|
|
|
|
|
|
expect(wrapper.state.isBackdropVisible).toBe(true);
|
|
|
|
expect(wrapper.state.isArticleVisible).toBe(true);
|
|
|
|
expect(wrapper.state.isArticlePinned).toBe(false);
|
|
|
|
});
|
|
|
|
});
|