UNPKG

stitch-ui

Version:

103 lines (92 loc) 3.15 kB
/* global it, describe, beforeEach, beforeAll, expect */ import React from "react"; // eslint-disable-line no-unused-vars import { Provider } from "react-redux"; import { mount } from "enzyme"; import { JSDOM } from "jsdom"; import { testSetup, noConsoleErrorsAllowed } from "../../testutil"; import * as homeActions from "../../home/actions"; import * as appActions from "../../app/actions"; import * as actions from "../actions"; import * as authActions from "../../auth/actions"; import { User } from "../../user"; import DebugConsole from "../components/DebugConsole"; global.navigator = { userAgent: "node.js" }; const doc = new JSDOM("<!doctype html><html><body></body></html>"); global.document = doc; global.window = doc.defaultView; const testAppName = "my-test-app"; describe("DebugConsole", () => { noConsoleErrorsAllowed(); let store; let testApp; let simDisplay; let actionSub; beforeAll(async () => { const testHarness = await testSetup(); store = testHarness.store; actionSub = testHarness.actionSub; testApp = await store.dispatch( homeActions.createApp(testHarness.groupId, testAppName) ); await store.dispatch(appActions.loadApp(testApp.groupId, testApp._id)); // create an API key so that there's at least one user we can run // the pipeline as await store.dispatch( authActions.apiKeyActions.createAPIKey(testApp.groupId, testApp._id, { name: "test" }) ); simDisplay = mount( <Provider store={store}> <DebugConsole app={testApp} history={{ location: { search: "" } }} /> </Provider> ); }); beforeEach(() => { actionSub.reset(); }); it("Loads the debug console", async () => { expect( simDisplay.find("button").findWhere(b => b.text() === "Execute") ).toHaveLength(1); }); it("Shows an error if you try to execute without a user selected", async () => { await simDisplay .find("button") .findWhere(b => b.text() === "Execute") .simulate("click"); expect(simDisplay.find(".banner-error").text()).toEqual( "Must select a user first." ); }); it("Can execute the pipeline successfully after choosing a user", async () => { // load the users list await store.dispatch(actions.loadUsers(testApp.groupId, testApp._id, {})); expect( store.getState().debugconsole.users.users.toJS().length ).toBeGreaterThan(0); const userObj = new User( store.getState().debugconsole.users.users.toJS()[0] ); store.dispatch(actions.selectUser(userObj)); expect(store.getState().debugconsole.debugconsole.selectedUser).toEqual( userObj ); await new Promise(resolve => { actionSub.subscribe( actions.executePipelineActions.rcv.getType(), resolve ); simDisplay .find("button") .findWhere(b => b.text() === "Execute") .simulate("click"); }); expect(simDisplay.find(".banner-error")).toHaveLength(0); expect(store.getState().debugconsole.debugconsole.output).toEqual({ result: [{ x: { $numberDouble: "1" }, y: "foo" }] }); }); });