stitch-ui
Version:
101 lines (91 loc) • 3.23 kB
JavaScript
/* global it, describe, beforeAll, afterEach, expect */
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 = "s3-1";
describe("aws 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,
"aws-s3"
)
);
// populate the s3 service with an initial config
await store.dispatch(
actions.saveConfig(testApp.groupId, testApp._id, testSvcName, {
region: "us-west-2",
accessKeyId: "test-access-key",
secretAccessKey: "test-secret"
})
);
await new Promise(resolve => {
actionSub.subscribe(actions.loadSvcActions.rcv.getType(), resolve);
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("select").at(0).node.value).toBe("us-west-2");
expect(svcConfigEditor.find("input").at(0).node.value).toBe(
"test-access-key"
);
expect(svcConfigEditor.find("input").at(1).node.value).toBe("test-secret");
});
it("gets an error if a required field is missing", async () => {
// set the accessKeyId to empty to trigger the validation error.
changeInput(svcConfigEditor, "accessKeyId", "");
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 'accessKeyId' to be a 'string'"
);
});
it("saves successfully if all data is provided", async () => {
changeInput(svcConfigEditor, "accessKeyId", "test-access-key");
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);
});
});