debian-mirror-gitlab/spec/frontend/serverless/components/functions_spec.js

131 lines
3.5 KiB
JavaScript
Raw Normal View History

2019-07-07 11:18:12 +05:30
import Vuex from 'vuex';
2019-09-04 21:01:54 +05:30
import { GlLoadingIcon } from '@gitlab/ui';
2019-07-07 11:18:12 +05:30
import AxiosMockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
import functionsComponent from '~/serverless/components/functions.vue';
import { createLocalVue, shallowMount } from '@vue/test-utils';
import { createStore } from '~/serverless/store';
2019-09-04 21:01:54 +05:30
import EmptyState from '~/serverless/components/empty_state.vue';
import EnvironmentRow from '~/serverless/components/environment_row.vue';
2019-07-31 22:56:46 +05:30
import { TEST_HOST } from 'helpers/test_constants';
2019-07-07 11:18:12 +05:30
import { mockServerlessFunctions } from '../mock_data';
describe('functionsComponent', () => {
2019-07-31 22:56:46 +05:30
const statusPath = `${TEST_HOST}/statusPath`;
2019-07-07 11:18:12 +05:30
let component;
let store;
let localVue;
2019-07-31 22:56:46 +05:30
let axiosMock;
2019-07-07 11:18:12 +05:30
beforeEach(() => {
2019-07-31 22:56:46 +05:30
axiosMock = new AxiosMockAdapter(axios);
axiosMock.onGet(statusPath).reply(200);
2019-07-07 11:18:12 +05:30
localVue = createLocalVue();
localVue.use(Vuex);
store = createStore();
});
afterEach(() => {
component.vm.$destroy();
2019-07-31 22:56:46 +05:30
axiosMock.restore();
2019-07-07 11:18:12 +05:30
});
it('should render empty state when Knative is not installed', () => {
2019-09-04 21:01:54 +05:30
store.dispatch('receiveFunctionsSuccess', { knative_installed: false });
2019-07-07 11:18:12 +05:30
component = shallowMount(functionsComponent, {
localVue,
store,
propsData: {
clustersPath: '',
helpPath: '',
statusPath: '',
},
sync: false,
});
2019-09-04 21:01:54 +05:30
expect(component.find(EmptyState).exists()).toBe(true);
2019-07-07 11:18:12 +05:30
});
it('should render a loading component', () => {
store.dispatch('requestFunctionsLoading');
component = shallowMount(functionsComponent, {
localVue,
store,
propsData: {
clustersPath: '',
helpPath: '',
statusPath: '',
},
sync: false,
});
2019-09-04 21:01:54 +05:30
expect(component.find(GlLoadingIcon).exists()).toBe(true);
2019-07-07 11:18:12 +05:30
});
it('should render empty state when there is no function data', () => {
2019-09-04 21:01:54 +05:30
store.dispatch('receiveFunctionsNoDataSuccess', { knative_installed: true });
2019-07-07 11:18:12 +05:30
component = shallowMount(functionsComponent, {
localVue,
store,
propsData: {
clustersPath: '',
helpPath: '',
statusPath: '',
},
sync: false,
});
expect(
component.vm.$el
.querySelector('.empty-state, .js-empty-state')
.classList.contains('js-empty-state'),
).toBe(true);
expect(component.vm.$el.querySelector('.state-title, .text-center').innerHTML.trim()).toEqual(
'No functions available',
);
});
2019-09-04 21:01:54 +05:30
it('should render functions and a loader when functions are partially fetched', () => {
store.dispatch('receiveFunctionsPartial', {
...mockServerlessFunctions,
knative_installed: 'checking',
});
component = shallowMount(functionsComponent, {
localVue,
store,
propsData: {
clustersPath: '',
helpPath: '',
statusPath: '',
},
sync: false,
});
expect(component.find('.js-functions-wrapper').exists()).toBe(true);
expect(component.find('.js-functions-loader').exists()).toBe(true);
});
2019-07-31 22:56:46 +05:30
it('should render the functions list', () => {
2019-07-07 11:18:12 +05:30
component = shallowMount(functionsComponent, {
localVue,
store,
propsData: {
clustersPath: 'clustersPath',
helpPath: 'helpPath',
statusPath,
},
sync: false,
});
component.vm.$store.dispatch('receiveFunctionsSuccess', mockServerlessFunctions);
return component.vm.$nextTick().then(() => {
2019-09-04 21:01:54 +05:30
expect(component.find(EnvironmentRow).exists()).toBe(true);
2019-07-07 11:18:12 +05:30
});
});
});