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

89 lines
2.9 KiB
JavaScript
Raw Normal View History

2019-09-04 21:01:54 +05:30
import { GlLoadingIcon } from '@gitlab/ui';
2020-01-01 13:55:28 +05:30
import { createLocalVue, shallowMount } from '@vue/test-utils';
2021-03-11 19:13:27 +05:30
import AxiosMockAdapter from 'axios-mock-adapter';
import Vuex from 'vuex';
2020-01-01 13:55:28 +05:30
import { TEST_HOST } from 'helpers/test_constants';
2019-07-07 11:18:12 +05:30
import axios from '~/lib/utils/axios_utils';
2019-09-04 21:01:54 +05:30
import EmptyState from '~/serverless/components/empty_state.vue';
import EnvironmentRow from '~/serverless/components/environment_row.vue';
2021-03-11 19:13:27 +05:30
import functionsComponent from '~/serverless/components/functions.vue';
import { createStore } from '~/serverless/store';
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);
2020-10-24 23:57:45 +05:30
store = createStore({});
2019-07-07 11:18:12 +05:30
});
afterEach(() => {
2020-10-24 23:57:45 +05:30
component.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 });
2020-10-24 23:57:45 +05:30
component = shallowMount(functionsComponent, { localVue, store });
2019-07-07 11:18:12 +05:30
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');
2020-10-24 23:57:45 +05:30
component = shallowMount(functionsComponent, { localVue, store });
2019-07-07 11:18:12 +05:30
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 });
2020-10-24 23:57:45 +05:30
component = shallowMount(functionsComponent, { localVue, store });
2019-07-07 11:18:12 +05:30
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',
});
2020-10-24 23:57:45 +05:30
component = shallowMount(functionsComponent, { localVue, store });
2019-09-04 21:01:54 +05:30
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', () => {
2020-10-24 23:57:45 +05:30
store = createStore({ clustersPath: 'clustersPath', helpPath: 'helpPath', statusPath });
component = shallowMount(functionsComponent, { localVue, store });
2019-07-07 11:18:12 +05:30
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
});
});
});