2019-04-05 22:02:39 -04:00
|
|
|
import Vuex from 'vuex';
|
2019-04-06 23:00:28 -04:00
|
|
|
import AxiosMockAdapter from 'axios-mock-adapter';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2019-01-21 19:00:16 -05:00
|
|
|
import functionsComponent from '~/serverless/components/functions.vue';
|
2019-04-05 22:02:39 -04:00
|
|
|
import { createLocalVue, shallowMount } from '@vue/test-utils';
|
|
|
|
import { createStore } from '~/serverless/store';
|
2019-01-21 19:00:16 -05:00
|
|
|
import { mockServerlessFunctions } from '../mock_data';
|
|
|
|
|
2019-04-05 22:02:39 -04:00
|
|
|
describe('functionsComponent', () => {
|
|
|
|
let component;
|
|
|
|
let store;
|
|
|
|
let localVue;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
localVue = createLocalVue();
|
|
|
|
localVue.use(Vuex);
|
2019-01-21 19:00:16 -05:00
|
|
|
|
2019-04-05 22:02:39 -04:00
|
|
|
store = createStore();
|
2019-01-21 19:00:16 -05:00
|
|
|
});
|
|
|
|
|
2019-04-05 22:02:39 -04:00
|
|
|
afterEach(() => {
|
|
|
|
component.vm.$destroy();
|
|
|
|
});
|
2019-01-21 19:00:16 -05:00
|
|
|
|
2019-04-05 22:02:39 -04:00
|
|
|
it('should render empty state when Knative is not installed', () => {
|
|
|
|
component = shallowMount(functionsComponent, {
|
|
|
|
localVue,
|
|
|
|
store,
|
|
|
|
propsData: {
|
|
|
|
installed: false,
|
|
|
|
clustersPath: '',
|
|
|
|
helpPath: '',
|
|
|
|
statusPath: '',
|
|
|
|
},
|
|
|
|
sync: false,
|
|
|
|
});
|
2019-01-21 19:00:16 -05:00
|
|
|
|
2019-04-05 22:02:39 -04:00
|
|
|
expect(component.vm.$el.querySelector('emptystate-stub')).not.toBe(null);
|
2019-01-21 19:00:16 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render a loading component', () => {
|
2019-04-05 22:02:39 -04:00
|
|
|
store.dispatch('requestFunctionsLoading');
|
|
|
|
component = shallowMount(functionsComponent, {
|
|
|
|
localVue,
|
|
|
|
store,
|
|
|
|
propsData: {
|
|
|
|
installed: true,
|
|
|
|
clustersPath: '',
|
|
|
|
helpPath: '',
|
|
|
|
statusPath: '',
|
|
|
|
},
|
|
|
|
sync: false,
|
|
|
|
});
|
2019-01-21 19:00:16 -05:00
|
|
|
|
2019-04-05 22:02:39 -04:00
|
|
|
expect(component.vm.$el.querySelector('glloadingicon-stub')).not.toBe(null);
|
2019-01-21 19:00:16 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render empty state when there is no function data', () => {
|
2019-04-05 22:02:39 -04:00
|
|
|
store.dispatch('receiveFunctionsNoDataSuccess');
|
|
|
|
component = shallowMount(functionsComponent, {
|
|
|
|
localVue,
|
|
|
|
store,
|
|
|
|
propsData: {
|
|
|
|
installed: true,
|
|
|
|
clustersPath: '',
|
|
|
|
helpPath: '',
|
|
|
|
statusPath: '',
|
|
|
|
},
|
|
|
|
sync: false,
|
|
|
|
});
|
2019-01-21 19:00:16 -05:00
|
|
|
|
|
|
|
expect(
|
2019-04-05 22:02:39 -04:00
|
|
|
component.vm.$el
|
|
|
|
.querySelector('.empty-state, .js-empty-state')
|
|
|
|
.classList.contains('js-empty-state'),
|
2019-01-21 19:00:16 -05:00
|
|
|
).toBe(true);
|
|
|
|
|
2019-04-05 22:02:39 -04:00
|
|
|
expect(component.vm.$el.querySelector('.state-title, .text-center').innerHTML.trim()).toEqual(
|
2019-01-21 19:00:16 -05:00
|
|
|
'No functions available',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-04-06 23:00:28 -04:00
|
|
|
fit('should render the functions list', () => {
|
|
|
|
const statusPath = 'statusPath';
|
|
|
|
const axiosMock = new AxiosMockAdapter(axios);
|
|
|
|
axiosMock.onGet(statusPath).reply(200);
|
|
|
|
|
2019-04-05 22:02:39 -04:00
|
|
|
component = shallowMount(functionsComponent, {
|
|
|
|
localVue,
|
|
|
|
store,
|
|
|
|
propsData: {
|
|
|
|
installed: true,
|
2019-04-06 23:00:28 -04:00
|
|
|
clustersPath: 'clustersPath',
|
|
|
|
helpPath: 'helpPath',
|
|
|
|
statusPath,
|
2019-04-05 22:02:39 -04:00
|
|
|
},
|
|
|
|
sync: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
component.vm.$store.dispatch('receiveFunctionsSuccess', mockServerlessFunctions);
|
2019-01-21 19:00:16 -05:00
|
|
|
|
2019-04-05 22:02:39 -04:00
|
|
|
return component.vm.$nextTick().then(() => {
|
|
|
|
expect(component.vm.$el.querySelector('environmentrow-stub')).not.toBe(null);
|
|
|
|
});
|
2019-01-21 19:00:16 -05:00
|
|
|
});
|
|
|
|
});
|