2021-04-12 13:32:25 +00:00
|
|
|
import React from "react";
|
|
|
|
import { mount, shallow } from "enzyme";
|
2016-11-16 16:58:25 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
import { connectedComponent, reduxMockStore } from "test/helpers";
|
|
|
|
import ConnectedRegistrationPage, {
|
|
|
|
RegistrationPage,
|
|
|
|
} from "pages/RegistrationPage/RegistrationPage";
|
2016-11-16 16:58:25 +00:00
|
|
|
|
|
|
|
const baseStore = {
|
|
|
|
app: {},
|
2016-11-21 20:22:14 +00:00
|
|
|
auth: {},
|
|
|
|
};
|
|
|
|
const user = {
|
|
|
|
id: 1,
|
2021-04-12 13:32:25 +00:00
|
|
|
name: "Gnar Dog",
|
|
|
|
email: "hi@gnar.dog",
|
2016-11-16 16:58:25 +00:00
|
|
|
};
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
describe("RegistrationPage - component", () => {
|
|
|
|
it("redirects to the login page when a user is logged in", () => {
|
2016-11-21 20:22:14 +00:00
|
|
|
const storeWithUser = {
|
|
|
|
...baseStore,
|
|
|
|
auth: {
|
|
|
|
loading: false,
|
|
|
|
user,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const mockStore = reduxMockStore(storeWithUser);
|
|
|
|
|
|
|
|
mount(connectedComponent(ConnectedRegistrationPage, { mockStore }));
|
|
|
|
|
|
|
|
const dispatchedActions = mockStore.getActions();
|
|
|
|
|
|
|
|
const redirectToHomeAction = {
|
2021-04-12 13:32:25 +00:00
|
|
|
type: "@@router/CALL_HISTORY_METHOD",
|
2016-11-21 20:22:14 +00:00
|
|
|
payload: {
|
2021-04-12 13:32:25 +00:00
|
|
|
method: "push",
|
|
|
|
args: ["/"],
|
2016-11-21 20:22:14 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-12-01 18:15:12 +00:00
|
|
|
expect(dispatchedActions).toContainEqual(redirectToHomeAction);
|
2016-11-21 20:22:14 +00:00
|
|
|
});
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
it("displays the Kolide background triangles", () => {
|
2016-11-16 16:58:25 +00:00
|
|
|
const mockStore = reduxMockStore(baseStore);
|
|
|
|
|
|
|
|
mount(connectedComponent(ConnectedRegistrationPage, { mockStore }));
|
|
|
|
|
2020-12-01 18:15:12 +00:00
|
|
|
expect(mockStore.getActions()).toContainEqual({
|
2021-04-12 13:32:25 +00:00
|
|
|
type: "SHOW_BACKGROUND_IMAGE",
|
2016-11-16 16:58:25 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
it("does not render the RegistrationForm if the user is loading", () => {
|
2016-11-21 20:22:14 +00:00
|
|
|
const mockStore = reduxMockStore({
|
|
|
|
app: {},
|
|
|
|
auth: { loading: true },
|
|
|
|
});
|
2021-04-12 13:32:25 +00:00
|
|
|
const page = mount(
|
|
|
|
connectedComponent(ConnectedRegistrationPage, { mockStore })
|
|
|
|
);
|
2016-11-21 20:22:14 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
expect(page.find("RegistrationForm").length).toEqual(0);
|
2016-11-21 20:22:14 +00:00
|
|
|
});
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
it("renders the RegistrationForm when there is no user", () => {
|
2016-11-16 16:58:25 +00:00
|
|
|
const mockStore = reduxMockStore(baseStore);
|
2021-04-12 13:32:25 +00:00
|
|
|
const page = mount(
|
|
|
|
connectedComponent(ConnectedRegistrationPage, { mockStore })
|
|
|
|
);
|
2016-11-16 16:58:25 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
expect(page.find("RegistrationForm").length).toEqual(1);
|
2016-11-16 16:58:25 +00:00
|
|
|
});
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
it("sets the page number to 1", () => {
|
2016-11-16 16:58:25 +00:00
|
|
|
const page = mount(<RegistrationPage />);
|
|
|
|
|
2020-12-01 18:15:12 +00:00
|
|
|
expect(page.state()).toMatchObject({ page: 1 });
|
2016-11-16 16:58:25 +00:00
|
|
|
});
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
it("displays the setup breadcrumbs", () => {
|
2016-11-16 16:58:25 +00:00
|
|
|
const mockStore = reduxMockStore(baseStore);
|
2021-04-12 13:32:25 +00:00
|
|
|
const page = mount(
|
|
|
|
connectedComponent(ConnectedRegistrationPage, { mockStore })
|
|
|
|
);
|
2016-11-16 16:58:25 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
expect(page.find("Breadcrumbs").length).toEqual(1);
|
2016-11-16 16:58:25 +00:00
|
|
|
});
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
describe("#onSetPage", () => {
|
|
|
|
it("sets state to the page number", () => {
|
2020-12-01 18:15:12 +00:00
|
|
|
const page = shallow(<RegistrationPage />);
|
2016-12-01 18:57:19 +00:00
|
|
|
page.setState({ page: 3 });
|
2019-01-14 21:45:28 +00:00
|
|
|
page.instance().onSetPage(3);
|
2016-11-16 16:58:25 +00:00
|
|
|
|
2020-12-01 18:15:12 +00:00
|
|
|
expect(page.state()).toMatchObject({ page: 3 });
|
2016-11-16 16:58:25 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|