UNPKG

stitch-ui

Version:

65 lines (57 loc) 2.07 kB
/* global it, describe, beforeAll, afterAll, expect */ import { testSetup, noConsoleErrorsAllowed } from "../../testutil"; import * as actions from "../actions"; import * as homeActions from "../../home/actions"; global.navigator = { userAgent: "node.js" }; describe("home page", () => { noConsoleErrorsAllowed(); let store; let testHarness; let currentLocation; let unlisten; let groupId; beforeAll(async () => { testHarness = await testSetup(); store = testHarness.store; groupId = testHarness.groupId; unlisten = store.getState().router.history.listen(location => { currentLocation = location; }); }); afterAll(async () => { unlisten(); }); it("can log out", async () => { expect.assertions(1); await testHarness.admin.client.logout(); // verify that after logging out, unauth'd requests force user to login page. await store.dispatch(homeActions.loadApps(groupId)); expect(currentLocation.pathname).toEqual("/login"); }); it("can fetch the login providers without being logged in", async () => { expect.assertions(1); await store.dispatch(actions.loadRootAuthProviders()); expect(store.getState().session.authProviders).toEqual({ "api/key": "/auth/api/key", "local/userpass": "/auth/local/userpass", "oauth2/google": "/auth/oauth2/google" }); }); it("can login", async () => { expect.assertions(2); await store.dispatch(actions.login("unique_user@domain.com", "password")); expect(store.getState().session.loginError).toBeFalsy(); expect(store.getState().home.error).toBeFalsy(); }); it("gets a login error when username/password is incorrect", async () => { expect.assertions(2); await testHarness.admin.client.logout(); expect(store.getState().session.loginError).toBeFalsy(); await store .dispatch(actions.login("unique_user@domain.com", "incorrect")) .catch(e => store.dispatch(actions.setLoginError(e))); expect(store.getState().session.loginError).toEqual("Unauthorized"); }); });