UNPKG

stitch-ui

Version:

99 lines (89 loc) 3 kB
/* global it, describe, beforeAll, afterEach, expect */ /* eslint-disable no-underscore-dangle */ import React from "react"; // eslint-disable-line no-unused-vars import { Provider } from "react-redux"; import { JSDOM } from "jsdom"; import { mount } from "enzyme"; import { testSetup, changeInput, noConsoleErrorsAllowed } from "../../../testutil"; import EditConfig from "../components/EditConfig"; import * as homeActions from "../../../home/actions"; import * as appActions from "../../../app/actions"; import * as actions from "../../actions"; 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"; const testSvcName = "tw1"; describe("twilio config", () => { noConsoleErrorsAllowed(); let store; let testApp; let svcConfigEditor; 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.createService( testApp.groupId, testApp._id, testSvcName, "twilio" ) ); await store.dispatch( actions.saveConfig(testApp.groupId, testApp._id, testSvcName, { sid: "test-sid", auth_token: "test-authtoken" }) ); await store.dispatch( actions.loadSvc(testApp.groupId, testApp._id, testSvcName) ); svcConfigEditor = mount( <Provider store={store}> <EditConfig svcname={testSvcName} app={testApp} /> </Provider> ); }); afterEach(() => { actionSub.reset(); }); it("Loads the config editor with the correct data", async () => { expect(svcConfigEditor.find("input[name='auth_token']").node.value).toBe( "test-authtoken" ); expect(svcConfigEditor.find("input[name='sid']").node.value).toBe( "test-sid" ); }); it("gets an error if a value is missing", async () => { expect.assertions(3); changeInput(svcConfigEditor, "auth_token", ""); await svcConfigEditor.find("button").props().onClick(); expect(store.getState().service.base.savingConfig).toBe(false); expect(store.getState().service.base.configSaveError).toBeTruthy(); expect(svcConfigEditor.find(".banner-error").text()).toMatch( "expected 'auth_token' to be a 'string'" ); }); it("saves successfully when valid data is provided", async () => { changeInput(svcConfigEditor, "auth_token", "blah-authtoken"); changeInput(svcConfigEditor, "sid", "blah-sid"); await svcConfigEditor.find("button").props().onClick(); expect(store.getState().service.base.savingConfig).toBe(false); expect(store.getState().service.base.configSaveError).toBeNull(); expect(svcConfigEditor.find(".banner-error")).toHaveLength(0); }); });