UNPKG

stitch-ui

Version:

98 lines (94 loc) 3.23 kB
/* global it, describe, beforeAll, expect */ /* eslint-disable no-underscore-dangle */ import { List } from "immutable"; import { testSetup, noConsoleErrorsAllowed } from "../../testutil"; import * as actions from "../actions"; import { Pipeline, PipelineStage } from "../../models"; import { GlobalService } from "../../services/registry"; global.navigator = { userAgent: "node.js" }; const pipelineKey = "test"; describe("pipelineeditor", () => { noConsoleErrorsAllowed(); let store; beforeAll(async () => { const testHarness = await testSetup(); store = testHarness.store; }); it("can create a pipeline", () => { expect(store.getState().pipeline.pipelines.size).toBe(0); store.dispatch( actions.initPipeline({ pipelineKey, pipelineObj: new Pipeline() }) ); expect(store.getState().pipeline.pipelines.get(pipelineKey)).toEqual( new Pipeline() ); expect(store.getState().pipeline.pipelines.get(pipelineKey).dirty).toBe( false ); }); it("can add a stage", () => { store.dispatch(actions.addStageAction({ pipelineKey })); expect(store.getState().pipeline.pipelines.get(pipelineKey)).toEqual( new Pipeline({ stages: new List([ new PipelineStage({ service: "", action: "literal", args: GlobalService.actions.get("literal").defaultArgs.toJS() }) ]), stageEditStates: new List([null]), dirty: true }) ); }); it("can set a stage by index", () => { const testStage = new PipelineStage({ service: "mongodb1", action: "find", args: { database: "d1", collection: "c1", query: {} } }); store.dispatch( actions.setStageAction({ pipelineKey, index: 0, stage: testStage }) ); expect( store.getState().pipeline.pipelines.get(pipelineKey).stages.get(0) ).toEqual(testStage); }); it("can reorder stages", () => { store.dispatch(actions.addStageAction({ pipelineKey })); const oldStages = store.getState().pipeline.pipelines.get(pipelineKey) .stages; store.dispatch( actions.moveStageAction({ pipelineKey, fromIndex: 0, toIndex: 1 }) ); const newStages = store.getState().pipeline.pipelines.get(pipelineKey) .stages; expect(oldStages.get(0)).toEqual(newStages.get(1)); expect(oldStages.get(1)).toEqual(newStages.get(0)); }); it("can remove a stage", () => { const oldStages = store.getState().pipeline.pipelines.get(pipelineKey) .stages; expect(oldStages.size).toBe(2); store.dispatch(actions.removeStageAction({ pipelineKey, index: 0 })); const newStages = store.getState().pipeline.pipelines.get(pipelineKey) .stages; expect(newStages.size).toBe(1); expect(newStages.get(0)).toEqual(oldStages.get(1)); }); it("can discard the changes", () => { expect(store.getState().pipeline.pipelines.get(pipelineKey).dirty).toBe( true ); store.dispatch(actions.discardChanges({ pipelineKey })); expect(store.getState().pipeline.pipelines.get(pipelineKey)).toEqual( new Pipeline() ); expect(store.getState().pipeline.pipelines.get(pipelineKey).dirty).toBe( false ); }); });