|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { mount } from "@vue/test-utils"; |
| 3 | + |
| 4 | +import { ValueSwitch } from "@knime/components"; |
| 5 | + |
| 6 | +import { NodeState } from "@/api/gateway-api/generated-api"; |
| 7 | +import { |
| 8 | + PORT_TYPE_IDS, |
| 9 | + createAvailablePortTypes, |
| 10 | + createNativeNode, |
| 11 | + createPort, |
| 12 | +} from "@/test/factories"; |
| 13 | +import { mockStores } from "@/test/utils/mockStores"; |
| 14 | +import PortViewTabToggles from "../PortViewTabToggles.vue"; |
| 15 | + |
| 16 | +describe("PortViewTabToggles.vue", () => { |
| 17 | + type ComponentProps = InstanceType<typeof PortViewTabToggles>["$props"]; |
| 18 | + |
| 19 | + type MountOpts = { |
| 20 | + props?: Partial<ComponentProps>; |
| 21 | + }; |
| 22 | + |
| 23 | + const doMount = ({ props }: MountOpts = {}) => { |
| 24 | + const port = createPort({ typeId: PORT_TYPE_IDS.BufferedDataTable }); |
| 25 | + const node = createNativeNode({ |
| 26 | + state: { |
| 27 | + executionState: NodeState.ExecutionStateEnum.EXECUTED, |
| 28 | + }, |
| 29 | + outPorts: [port], |
| 30 | + }); |
| 31 | + const availablePortTypes = createAvailablePortTypes(); |
| 32 | + |
| 33 | + const mockedStores = mockStores(); |
| 34 | + mockedStores.applicationStore.setAvailablePortTypes(availablePortTypes); |
| 35 | + |
| 36 | + const wrapper = mount(PortViewTabToggles, { |
| 37 | + props: { |
| 38 | + uniquePortKey: "foo", |
| 39 | + selectedNode: node, |
| 40 | + selectedPort: port, |
| 41 | + ...props, |
| 42 | + }, |
| 43 | + global: { |
| 44 | + plugins: [mockedStores.testingPinia], |
| 45 | + }, |
| 46 | + }); |
| 47 | + |
| 48 | + return { wrapper, mockedStores }; |
| 49 | + }; |
| 50 | + |
| 51 | + it("renders correctly for CONFIGURED node", () => { |
| 52 | + const port = createPort({ typeId: PORT_TYPE_IDS.BufferedDataTable }); |
| 53 | + const node = createNativeNode({ |
| 54 | + state: { |
| 55 | + executionState: NodeState.ExecutionStateEnum.CONFIGURED, |
| 56 | + }, |
| 57 | + outPorts: [port], |
| 58 | + }); |
| 59 | + |
| 60 | + const { wrapper } = doMount({ |
| 61 | + props: { selectedNode: node, selectedPort: port }, |
| 62 | + }); |
| 63 | + |
| 64 | + expect(wrapper.findComponent(ValueSwitch).props("possibleValues")).toEqual([ |
| 65 | + { |
| 66 | + detachable: false, |
| 67 | + disabled: false, |
| 68 | + id: "0", |
| 69 | + text: "Table", |
| 70 | + }, |
| 71 | + { |
| 72 | + detachable: true, |
| 73 | + disabled: true, |
| 74 | + id: "2", |
| 75 | + text: "Statistics", |
| 76 | + }, |
| 77 | + ]); |
| 78 | + |
| 79 | + expect(wrapper.findAll('[data-test-id="toggle-with-detach"]')).toHaveLength( |
| 80 | + 2, |
| 81 | + ); |
| 82 | + expect( |
| 83 | + wrapper |
| 84 | + .findAll('[data-test-id="toggle-with-detach"]') |
| 85 | + .at(0) |
| 86 | + ?.attributes("disabled"), |
| 87 | + ).toBeFalsy(); |
| 88 | + expect( |
| 89 | + wrapper |
| 90 | + .findAll('[data-test-id="toggle-with-detach"]') |
| 91 | + .at(1) |
| 92 | + ?.attributes("disabled"), |
| 93 | + ).toBeDefined(); |
| 94 | + }); |
| 95 | + |
| 96 | + it("renders correctly for EXECUTED node", () => { |
| 97 | + const port = createPort({ typeId: PORT_TYPE_IDS.BufferedDataTable }); |
| 98 | + const node = createNativeNode({ |
| 99 | + state: { |
| 100 | + executionState: NodeState.ExecutionStateEnum.EXECUTED, |
| 101 | + }, |
| 102 | + outPorts: [port], |
| 103 | + }); |
| 104 | + |
| 105 | + const { wrapper } = doMount({ |
| 106 | + props: { selectedNode: node, selectedPort: port }, |
| 107 | + }); |
| 108 | + |
| 109 | + expect(wrapper.findComponent(ValueSwitch).props("possibleValues")).toEqual([ |
| 110 | + { |
| 111 | + detachable: true, |
| 112 | + disabled: false, |
| 113 | + id: "1", |
| 114 | + text: "Table", |
| 115 | + }, |
| 116 | + { |
| 117 | + detachable: true, |
| 118 | + disabled: false, |
| 119 | + id: "2", |
| 120 | + text: "Statistics", |
| 121 | + }, |
| 122 | + ]); |
| 123 | + |
| 124 | + expect(wrapper.findAll('[data-test-id="toggle-with-detach"]')).toHaveLength( |
| 125 | + 2, |
| 126 | + ); |
| 127 | + expect( |
| 128 | + wrapper |
| 129 | + .findAll('[data-test-id="toggle-with-detach"]') |
| 130 | + .at(0) |
| 131 | + ?.attributes("disabled"), |
| 132 | + ).toBeFalsy(); |
| 133 | + expect( |
| 134 | + wrapper |
| 135 | + .findAll('[data-test-id="toggle-with-detach"]') |
| 136 | + .at(1) |
| 137 | + ?.attributes("disabled"), |
| 138 | + ).toBeFalsy(); |
| 139 | + }); |
| 140 | +}); |
0 commit comments