stitch-ui
Version:
86 lines (75 loc) • 2.78 kB
JavaScript
/* 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 * as homeActions from "../../home/actions";
import * as serviceActions from "../../services/actions";
import EditConfig from "../../services/push/gcm/components/EditConfig";
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 = "gcm";
describe("gcm 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(
serviceActions.saveConfig(testApp.groupId, testApp._id, testSvcName, {
apiKey: "myApiKey",
senderId: "123456"
})
);
await store.dispatch(
serviceActions.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='apiKey']").node.value).toBe(
"myApiKey"
);
expect(svcConfigEditor.find("input[name='senderId']").node.value).toBe(
"123456"
);
});
it("gets an error if a value is missing", async () => {
changeInput(svcConfigEditor, "apiKey", "");
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(
"'apiKey' must be a non-empty string"
);
});
it("saves successfully when valid data is provided", async () => {
changeInput(svcConfigEditor, "apiKey", "reallyGoodAPIKey");
changeInput(svcConfigEditor, "senderId", "7126313");
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);
});
});