Commit 203aaa57 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'ph/36804/geoNodesJest' into 'master'

Move Geo Nodes specs to Jest

Closes #36804

See merge request gitlab-org/gitlab!24399
parents 3f8969cb e545a26f
......@@ -209,7 +209,7 @@ export default {
<gl-loading-icon
v-if="isLoading"
:label="s__('GeoNodes|Loading nodes')"
:size="2"
size="md"
class="loading-animation prepend-top-20 append-bottom-20"
/>
<geo-node-item
......
......@@ -5,7 +5,7 @@ import appComponent from 'ee/geo_nodes/components/app.vue';
import eventHub from 'ee/geo_nodes/event_hub';
import GeoNodesStore from 'ee/geo_nodes/store/geo_nodes_store';
import GeoNodesService from 'ee/geo_nodes/service/geo_nodes_service';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import { NODE_ACTIONS } from 'ee/geo_nodes/constants';
import axios from '~/lib/utils/axios_utils';
import {
......@@ -16,6 +16,9 @@ import {
rawMockNodeDetails,
} from '../mock_data';
jest.mock('~/smart_interval');
jest.mock('ee/geo_nodes/event_hub');
const createComponent = () => {
const Component = Vue.extend(appComponent);
const store = new GeoNodesStore(PRIMARY_VERSION.version, PRIMARY_VERSION.revision);
......@@ -97,7 +100,7 @@ describe('AppComponent', () => {
describe('fetchGeoNodes', () => {
it('calls service.getGeoNodes and sets response to the store on success', done => {
spyOn(vm.store, 'setNodes');
jest.spyOn(vm.store, 'setNodes');
vm.fetchGeoNodes()
.then(() => {
......@@ -127,11 +130,9 @@ describe('AppComponent', () => {
describe('fetchNodeDetails', () => {
it('calls service.getGeoNodeDetails and sets response to the store on success', done => {
mock.onGet(mockNode.statusPath).reply(200, rawMockNodeDetails);
spyOn(vm.service, 'getGeoNodeDetails').and.callThrough();
vm.fetchNodeDetails(mockNode)
.then(() => {
expect(vm.service.getGeoNodeDetails).toHaveBeenCalled();
expect(Object.keys(vm.store.state.nodeDetails).length).not.toBe(0);
expect(vm.store.state.nodeDetails['1']).toBeDefined();
})
......@@ -140,9 +141,8 @@ describe('AppComponent', () => {
});
it('emits `nodeDetailsLoaded` event with fake nodeDetails object on 404 failure', done => {
spyOn(eventHub, '$emit');
mock.onGet(mockNode.statusPath).reply(404, {});
spyOn(vm.service, 'getGeoNodeDetails').and.callThrough();
jest.spyOn(vm.service, 'getGeoNodeDetails');
vm.fetchNodeDetails(mockNode)
.then(() => {
......@@ -158,9 +158,8 @@ describe('AppComponent', () => {
});
it('emits `nodeDetailsLoaded` event with fake nodeDetails object when a network error occurs', done => {
spyOn(eventHub, '$emit');
mock.onGet(mockNode.statusPath).networkError();
spyOn(vm.service, 'getGeoNodeDetails').and.callThrough();
jest.spyOn(vm.service, 'getGeoNodeDetails');
vm.fetchNodeDetails(mockNode)
.then(() => {
......@@ -176,9 +175,8 @@ describe('AppComponent', () => {
});
it('emits `nodeDetailsLoaded` event with fake nodeDetails object when a timeout occurs', done => {
spyOn(eventHub, '$emit');
mock.onGet(mockNode.statusPath).timeout();
spyOn(vm.service, 'getGeoNodeDetails').and.callThrough();
jest.spyOn(vm.service, 'getGeoNodeDetails');
vm.fetchNodeDetails(mockNode)
.then(() => {
......@@ -201,7 +199,7 @@ describe('AppComponent', () => {
expect(node.nodeActionActive).toBe(true);
return [200];
});
spyOn(vm.service, 'repairNode').and.callThrough();
jest.spyOn(vm.service, 'repairNode');
vm.repairNode(node)
.then(() => {
......@@ -222,7 +220,7 @@ describe('AppComponent', () => {
expect(node.nodeActionActive).toBe(true);
return [500];
});
spyOn(vm.service, 'repairNode').and.callThrough();
jest.spyOn(vm.service, 'repairNode');
vm.repairNode(node)
.then(() => {
......@@ -250,7 +248,7 @@ describe('AppComponent', () => {
},
];
});
spyOn(vm.service, 'toggleNode').and.callThrough();
jest.spyOn(vm.service, 'toggleNode');
node.enabled = false;
vm.toggleNode(node)
......@@ -269,7 +267,7 @@ describe('AppComponent', () => {
expect(node.nodeActionActive).toBe(true);
return [500];
});
spyOn(vm.service, 'toggleNode').and.callThrough();
jest.spyOn(vm.service, 'toggleNode');
node.enabled = false;
vm.toggleNode(node)
......@@ -293,8 +291,8 @@ describe('AppComponent', () => {
expect(node.nodeActionActive).toBe(true);
return [200];
});
spyOn(vm.service, 'removeNode').and.callThrough();
spyOn(vm.store, 'removeNode').and.stub();
jest.spyOn(vm.service, 'removeNode');
jest.spyOn(vm.store, 'removeNode');
vm.removeNode(node)
.then(() => {
......@@ -314,8 +312,8 @@ describe('AppComponent', () => {
expect(node.nodeActionActive).toBe(true);
return [500];
});
spyOn(vm.service, 'removeNode').and.callThrough();
spyOn(vm.store, 'removeNode').and.stub();
jest.spyOn(vm.service, 'removeNode');
jest.spyOn(vm.store, 'removeNode');
vm.removeNode(node)
.then(() => {
......@@ -334,8 +332,8 @@ describe('AppComponent', () => {
it('calls `toggleNode` and `hideNodeActionModal` when `targetNodeActionType` is `toggle`', () => {
vm.targetNode = { ...mockNode };
vm.targetNodeActionType = NODE_ACTIONS.TOGGLE;
spyOn(vm, 'hideNodeActionModal');
spyOn(vm, 'toggleNode').and.stub();
jest.spyOn(vm, 'hideNodeActionModal');
jest.spyOn(vm, 'toggleNode');
vm.handleNodeAction();
......@@ -346,8 +344,8 @@ describe('AppComponent', () => {
it('calls `removeNode` and `hideNodeActionModal` when `targetNodeActionType` is `remove`', () => {
vm.targetNode = { ...mockNode };
vm.targetNodeActionType = NODE_ACTIONS.REMOVE;
spyOn(vm, 'hideNodeActionModal');
spyOn(vm, 'removeNode').and.stub();
jest.spyOn(vm, 'hideNodeActionModal');
jest.spyOn(vm, 'removeNode');
vm.handleNodeAction();
......@@ -370,7 +368,7 @@ describe('AppComponent', () => {
modalMessage = 'Foobar message';
modalActionLabel = 'Disable';
modalTitle = 'Test title';
rootEmit = spyOn(vm.$root, '$emit');
rootEmit = jest.spyOn(vm.$root, '$emit');
});
it('sets target node and modal config props on component', () => {
......@@ -407,7 +405,7 @@ describe('AppComponent', () => {
it('calls toggleNode when actionType is `toggle` and node.enabled is `false`', () => {
node.enabled = false;
spyOn(vm, 'toggleNode').and.stub();
jest.spyOn(vm, 'toggleNode');
vm.showNodeActionModal({
actionType: NODE_ACTIONS.TOGGLE,
......@@ -437,7 +435,7 @@ describe('AppComponent', () => {
describe('hideNodeActionModal', () => {
it('emits `bv::hide::modal`', () => {
const rootEmit = spyOn(vm.$root, '$emit');
const rootEmit = jest.spyOn(vm.$root, '$emit');
vm.hideNodeActionModal();
expect(rootEmit).toHaveBeenCalledWith('bv::hide::modal', vm.modalId);
......@@ -447,7 +445,6 @@ describe('AppComponent', () => {
describe('created', () => {
it('binds event handler for `pollNodeDetails`', () => {
spyOn(eventHub, '$on');
const vmX = createComponent();
expect(eventHub.$on).toHaveBeenCalledWith('pollNodeDetails', jasmine.any(Function));
......@@ -459,7 +456,6 @@ describe('AppComponent', () => {
describe('beforeDestroy', () => {
it('unbinds event handler for `pollNodeDetails`', () => {
spyOn(eventHub, '$off');
const vmX = createComponent();
vmX.$destroy();
......
import Vue from 'vue';
import geoNodeActionsComponent from 'ee/geo_nodes/components/geo_node_actions.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import eventHub from 'ee/geo_nodes/event_hub';
import { NODE_ACTIONS } from 'ee/geo_nodes/constants';
import { mockNodes } from '../mock_data';
jest.mock('ee/geo_nodes/event_hub');
const createComponent = (
node = mockNodes[0],
nodeEditAllowed = true,
......@@ -68,7 +70,6 @@ describe('GeoNodeActionsComponent', () => {
describe('methods', () => {
describe('onToggleNode', () => {
it('emits showNodeActionModal with actionType `toggle`, node reference, modalMessage, modalActionLabel, and modalTitle', () => {
spyOn(eventHub, '$emit');
vm.onToggleNode();
expect(eventHub.$emit).toHaveBeenCalledWith('showNodeActionModal', {
......@@ -83,7 +84,6 @@ describe('GeoNodeActionsComponent', () => {
describe('onRemovePrimaryNode', () => {
it('emits showNodeActionModal with actionType `remove`, node reference, modalKind, modalMessage, modalActionLabel, and modalTitle', () => {
spyOn(eventHub, '$emit');
vm.onRemovePrimaryNode();
expect(eventHub.$emit).toHaveBeenCalledWith('showNodeActionModal', {
......@@ -100,7 +100,6 @@ describe('GeoNodeActionsComponent', () => {
describe('onRemoveSecondaryNode', () => {
it('emits showNodeActionModal with actionType `remove`, node reference, modalKind, modalMessage, modalActionLabel, and modalTitle', () => {
spyOn(eventHub, '$emit');
vm.onRemoveSecondaryNode();
expect(eventHub.$emit).toHaveBeenCalledWith('showNodeActionModal', {
......@@ -117,7 +116,6 @@ describe('GeoNodeActionsComponent', () => {
describe('onRepairNode', () => {
it('emits `repairNode` event with node reference', () => {
spyOn(eventHub, '$emit');
vm.onRepairNode();
expect(eventHub.$emit).toHaveBeenCalledWith('repairNode', vm.node);
......
......@@ -2,7 +2,7 @@ import Vue from 'vue';
import geoNodeDetailItemComponent from 'ee/geo_nodes/components/geo_node_detail_item.vue';
import { VALUE_TYPE, CUSTOM_TYPE } from 'ee/geo_nodes/constants';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import { rawMockNodeDetails } from '../mock_data';
const createComponent = config => {
......
import Vue from 'vue';
import geoNodeDetailsComponent from 'ee/geo_nodes/components/geo_node_details.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import { mockNode, mockNodeDetails } from '../mock_data';
const createComponent = ({
......
import Vue from 'vue';
import geoNodeEventStatusComponent from 'ee/geo_nodes/components/geo_node_event_status.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import { mockNodeDetails } from '../mock_data';
const createComponent = ({
......
import Vue from 'vue';
import GeoNodeHeaderComponent from 'ee/geo_nodes/components/geo_node_header.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import { mockNode, mockNodeDetails } from '../mock_data';
const createComponent = ({
......
......@@ -2,7 +2,7 @@ import Vue from 'vue';
import geoNodeHealthStatusComponent from 'ee/geo_nodes/components/geo_node_health_status.vue';
import { HEALTH_STATUS_ICON, HEALTH_STATUS_CLASS } from 'ee/geo_nodes/constants';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import { mockNodeDetails } from '../mock_data';
const createComponent = (status = mockNodeDetails.health) => {
......
......@@ -2,9 +2,11 @@ import Vue from 'vue';
import geoNodeItemComponent from 'ee/geo_nodes/components/geo_node_item.vue';
import eventHub from 'ee/geo_nodes/event_hub';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import { mockNode, mockNodeDetails } from '../mock_data';
jest.mock('ee/geo_nodes/event_hub');
const createComponent = (node = mockNode) => {
const Component = Vue.extend(geoNodeItemComponent);
......@@ -45,6 +47,7 @@ describe('GeoNodeItemComponent', () => {
beforeEach(() => {
// Altered mock data for secure URL
httpsNode = Object.assign({}, mockNode, {
id: mockNodeDetails.id,
url: 'https://127.0.0.1:3001/',
});
vmHttps = createComponent(httpsNode);
......@@ -56,23 +59,24 @@ describe('GeoNodeItemComponent', () => {
describe('showNodeDetails', () => {
it('returns `false` if Node details are still loading', () => {
vm.isNodeDetailsLoading = true;
vmHttps.isNodeDetailsLoading = true;
expect(vm.showNodeDetails).toBeFalsy();
expect(vmHttps.showNodeDetails).toBeFalsy();
});
it('returns `false` if Node details failed to load', () => {
vm.isNodeDetailsLoading = false;
vm.isNodeDetailsFailed = true;
vmHttps.isNodeDetailsLoading = false;
vmHttps.isNodeDetailsFailed = true;
expect(vm.showNodeDetails).toBeFalsy();
expect(vmHttps.showNodeDetails).toBeFalsy();
});
it('returns `true` if Node details loaded', () => {
vm.isNodeDetailsLoading = false;
vm.isNodeDetailsFailed = false;
vmHttps.handleNodeDetails(mockNodeDetails);
vmHttps.isNodeDetailsLoading = false;
vmHttps.isNodeDetailsFailed = false;
expect(vm.showNodeDetails).toBeTruthy();
expect(vmHttps.showNodeDetails).toBeTruthy();
});
});
});
......@@ -107,8 +111,6 @@ describe('GeoNodeItemComponent', () => {
describe('handleMounted', () => {
it('emits `pollNodeDetails` event and passes node ID', () => {
spyOn(eventHub, '$emit');
vm.handleMounted();
expect(eventHub.$emit).toHaveBeenCalledWith('pollNodeDetails', vm.node);
......@@ -118,8 +120,6 @@ describe('GeoNodeItemComponent', () => {
describe('created', () => {
it('binds `nodeDetailsLoaded` event handler', () => {
spyOn(eventHub, '$on');
const vmX = createComponent();
expect(eventHub.$on).toHaveBeenCalledWith('nodeDetailsLoaded', jasmine.any(Function));
......@@ -129,8 +129,6 @@ describe('GeoNodeItemComponent', () => {
describe('beforeDestroy', () => {
it('unbinds `nodeDetailsLoaded` event handler', () => {
spyOn(eventHub, '$off');
const vmX = createComponent();
vmX.$destroy();
......
import Vue from 'vue';
import geoNodeSyncSettingsComponent from 'ee/geo_nodes/components/geo_node_sync_settings.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import { mockNodeDetails } from '../mock_data';
const createComponent = (
......
import Vue from 'vue';
import geoNodesListComponent from 'ee/geo_nodes/components/geo_nodes_list.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import { mockNodes } from '../mock_data';
const createComponent = () => {
......
import Vue from 'vue';
import NodeDetailsSectionMainComponent from 'ee/geo_nodes/components/node_detail_sections/node_details_section_main.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import { mockNode, mockNodeDetails } from 'ee_spec/geo_nodes/mock_data';
import mountComponent from 'helpers/vue_mount_component_helper';
import { mockNode, mockNodeDetails } from '../../mock_data';
const MOCK_VERSION_TEXT = `${mockNodeDetails.version} (${mockNodeDetails.revision})`;
......
import Vue from 'vue';
import NodeDetailsSectionOtherComponent from 'ee/geo_nodes/components/node_detail_sections/node_details_section_other.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import { mockNode, mockNodeDetails } from 'ee_spec/geo_nodes/mock_data';
import mountComponent from 'helpers/vue_mount_component_helper';
import { mockNode, mockNodeDetails } from '../../mock_data';
import { numberToHumanSize } from '~/lib/utils/number_utils';
const createComponent = (
......
import Vue from 'vue';
import NodeDetailsSectionSyncComponent from 'ee/geo_nodes/components/node_detail_sections/node_details_section_sync.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import { mockNodeDetails } from 'ee_spec/geo_nodes/mock_data';
import mountComponent from 'helpers/vue_mount_component_helper';
import { mockNodeDetails } from '../../mock_data';
const createComponent = (nodeDetails = Object.assign({}, mockNodeDetails)) => {
const Component = Vue.extend(NodeDetailsSectionSyncComponent);
......
import Vue from 'vue';
import NodeDetailsSectionVerificationComponent from 'ee/geo_nodes/components/node_detail_sections/node_details_section_verification.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import { mockNodeDetails } from 'ee_spec/geo_nodes/mock_data';
import mountComponent from 'helpers/vue_mount_component_helper';
import { mockNodeDetails } from '../../mock_data';
const createComponent = ({ nodeDetails = mockNodeDetails, nodeTypePrimary = false }) => {
const Component = Vue.extend(NodeDetailsSectionVerificationComponent);
......
import Vue from 'vue';
import SectionRevealButtonComponent from 'ee/geo_nodes/components/node_detail_sections/section_reveal_button.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
const createComponent = (buttonTitle = 'Foo button') => {
const Component = Vue.extend(SectionRevealButtonComponent);
......@@ -52,7 +52,7 @@ describe('SectionRevealButton', () => {
});
it('emits `toggleButton` event on component', () => {
spyOn(vm, '$emit');
jest.spyOn(vm, '$emit');
vm.onClickButton();
expect(vm.$emit).toHaveBeenCalledWith('toggleButton', vm.toggleState);
......
......@@ -3,7 +3,7 @@ import Vue from 'vue';
import DetailsSectionMixin from 'ee/geo_nodes/mixins/details_section_mixin';
import { STATUS_DELAY_THRESHOLD_MS } from 'ee/geo_nodes/constants';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import { mockNodeDetails } from '../mock_data';
const createComponent = (nodeDetails = mockNodeDetails) => {
......@@ -12,7 +12,9 @@ const createComponent = (nodeDetails = mockNodeDetails) => {
data() {
return { nodeDetails };
},
template: '<div></div>',
render(h) {
return h('div');
},
});
return mountComponent(Component);
......
......@@ -3,6 +3,8 @@ import axios from '~/lib/utils/axios_utils';
import { NODE_DETAILS_PATH } from '../mock_data';
jest.mock('axios');
describe('GeoNodesService', () => {
let service;
......@@ -12,7 +14,6 @@ describe('GeoNodesService', () => {
describe('getGeoNodes', () => {
it('returns axios instance for Geo nodes path', () => {
spyOn(axios, 'get').and.stub();
service.getGeoNodes();
expect(axios.get).toHaveBeenCalledWith(service.geoNodesPath);
......@@ -21,7 +22,6 @@ describe('GeoNodesService', () => {
describe('getGeoNodeDetails', () => {
it('returns axios instance for Geo node details path', () => {
spyOn(axios, 'get').and.stub();
service.getGeoNodeDetails(2);
expect(axios.get).toHaveBeenCalled();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment