stitch-ui
Version:
111 lines (97 loc) • 2.85 kB
JavaScript
/* global it, describe, beforeAll, 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 { MemoryRouter } from "react-router-dom";
import EditService from "../EditService";
import {
testSetup,
noConsoleErrorsAllowed,
braceCompatShim
} from "../../../testutil";
import * as homeActions from "../../../home/actions";
import * as appActions from "../../../app/actions";
import * as actions from "../../actions";
import { INCOMING_WEBHOOK_TAB } from "../../registry";
global.navigator = {
userAgent: "node.js"
};
const doc = new JSDOM("<!doctype html><html><body></body></html>");
global.document = doc;
global.window = doc.defaultView;
braceCompatShim(global.window);
const testAppName = "my-test-app";
const testSvcName = "http1";
describe("EditService", () => {
noConsoleErrorsAllowed();
let store;
let testApp;
let editSvc;
let match;
beforeAll(async () => {
const testHarness = await testSetup();
store = testHarness.store;
testApp = await store.dispatch(
homeActions.createApp(testHarness.groupId, testAppName)
);
await store.dispatch(
appActions.createService(
testApp.groupId,
testApp._id,
testSvcName,
"http"
)
);
await store.dispatch(
actions.saveConfig(testApp.groupId, testApp._id, testSvcName, {})
);
await store.dispatch(appActions.loadApp(testApp.groupId, testApp._id));
await store.dispatch(
actions.loadSvc(testApp.groupId, testApp._id, testSvcName)
);
match = {
url: `http://website.com/${testSvcName}`,
params: { svcname: testSvcName }
};
editSvc = mount(
<Provider store={store}>
<MemoryRouter>
<EditService app={testApp} match={match} />
</MemoryRouter>
</Provider>
);
});
it("Renders redirect to default tab for service type 'http`", async () => {
expect(editSvc.find("Switch").props().children[0].props).toHaveProperty(
"to",
`${match.url}/${INCOMING_WEBHOOK_TAB}`
);
});
it("Renders redirect to current url when svcname is not found in services", async () => {
const testSvcName2 = "http2";
match = {
url: `http://website.com/${testSvcName2}`,
params: { svcname: testSvcName2 }
};
await store.dispatch(
appActions.createService(
testApp.groupId,
testApp._id,
testSvcName2,
"http"
)
);
editSvc = mount(
<Provider store={store}>
<MemoryRouter>
<EditService app={testApp} match={match} />
</MemoryRouter>
</Provider>
);
expect(editSvc.find("Switch").props().children[0].props).toHaveProperty(
"to",
`${match.url}/`
);
});
});