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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

87 lines
2.8 KiB
JavaScript
Raw Normal View History

2022-04-04 11:22:00 +05:30
import { GlLoadingIcon, GlAlert, GlSprintf } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Vue, { nextTick } from 'vue';
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;
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);
2022-04-04 11:22:00 +05:30
Vue.use(Vuex);
2019-07-07 11:18:12 +05:30
2020-10-24 23:57:45 +05:30
store = createStore({});
2022-04-04 11:22:00 +05:30
component = shallowMount(functionsComponent, { store, stubs: { GlSprintf } });
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
});
2022-04-04 11:22:00 +05:30
it('should render deprecation notice', () => {
expect(component.findComponent(GlAlert).text()).toBe(
'Serverless was deprecated in GitLab 14.3.',
);
});
it('should render empty state when Knative is not installed', async () => {
await store.dispatch('receiveFunctionsSuccess', { knative_installed: false });
2019-07-07 11:18:12 +05:30
2022-04-04 11:22:00 +05:30
expect(component.findComponent(EmptyState).exists()).toBe(true);
2019-07-07 11:18:12 +05:30
});
2022-04-04 11:22:00 +05:30
it('should render a loading component', async () => {
await store.dispatch('requestFunctionsLoading');
2019-07-07 11:18:12 +05:30
2022-04-04 11:22:00 +05:30
expect(component.findComponent(GlLoadingIcon).exists()).toBe(true);
2019-07-07 11:18:12 +05:30
});
2022-04-04 11:22:00 +05:30
it('should render empty state when there is no function data', async () => {
await store.dispatch('receiveFunctionsNoDataSuccess', { knative_installed: true });
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',
);
});
2022-04-04 11:22:00 +05:30
it('should render functions and a loader when functions are partially fetched', async () => {
await store.dispatch('receiveFunctionsPartial', {
2019-09-04 21:01:54 +05:30
...mockServerlessFunctions,
knative_installed: 'checking',
});
2020-10-24 23:57:45 +05:30
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);
});
2022-04-04 11:22:00 +05:30
it('should render the functions list', async () => {
2020-10-24 23:57:45 +05:30
store = createStore({ clustersPath: 'clustersPath', helpPath: 'helpPath', statusPath });
2022-04-04 11:22:00 +05:30
await component.vm.$store.dispatch('receiveFunctionsSuccess', mockServerlessFunctions);
2019-07-07 11:18:12 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
expect(component.findComponent(EnvironmentRow).exists()).toBe(true);
2019-07-07 11:18:12 +05:30
});
});