functions_spec.js 2.79 KB
Newer Older
1
import Vuex from 'vuex';
2 3
import AxiosMockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils';
4
import functionsComponent from '~/serverless/components/functions.vue';
5 6
import { createLocalVue, shallowMount } from '@vue/test-utils';
import { createStore } from '~/serverless/store';
7
import { TEST_HOST } from 'helpers/test_constants';
8 9
import { mockServerlessFunctions } from '../mock_data';

10
describe('functionsComponent', () => {
11 12
  const statusPath = `${TEST_HOST}/statusPath`;

13 14 15
  let component;
  let store;
  let localVue;
16
  let axiosMock;
17 18

  beforeEach(() => {
19 20 21
    axiosMock = new AxiosMockAdapter(axios);
    axiosMock.onGet(statusPath).reply(200);

22 23
    localVue = createLocalVue();
    localVue.use(Vuex);
24

25
    store = createStore();
26 27
  });

28 29
  afterEach(() => {
    component.vm.$destroy();
30
    axiosMock.restore();
31
  });
32

33 34 35 36 37 38 39 40 41 42 43 44
  it('should render empty state when Knative is not installed', () => {
    component = shallowMount(functionsComponent, {
      localVue,
      store,
      propsData: {
        installed: false,
        clustersPath: '',
        helpPath: '',
        statusPath: '',
      },
      sync: false,
    });
45

46
    expect(component.vm.$el.querySelector('emptystate-stub')).not.toBe(null);
47 48 49
  });

  it('should render a loading component', () => {
50 51 52 53 54 55 56 57 58 59 60 61
    store.dispatch('requestFunctionsLoading');
    component = shallowMount(functionsComponent, {
      localVue,
      store,
      propsData: {
        installed: true,
        clustersPath: '',
        helpPath: '',
        statusPath: '',
      },
      sync: false,
    });
62

63
    expect(component.vm.$el.querySelector('glloadingicon-stub')).not.toBe(null);
64 65 66
  });

  it('should render empty state when there is no function data', () => {
67 68 69 70 71 72 73 74 75 76 77 78
    store.dispatch('receiveFunctionsNoDataSuccess');
    component = shallowMount(functionsComponent, {
      localVue,
      store,
      propsData: {
        installed: true,
        clustersPath: '',
        helpPath: '',
        statusPath: '',
      },
      sync: false,
    });
79 80

    expect(
81 82 83
      component.vm.$el
        .querySelector('.empty-state, .js-empty-state')
        .classList.contains('js-empty-state'),
84 85
    ).toBe(true);

86
    expect(component.vm.$el.querySelector('.state-title, .text-center').innerHTML.trim()).toEqual(
87 88 89 90
      'No functions available',
    );
  });

91
  it('should render the functions list', () => {
92 93 94 95 96
    component = shallowMount(functionsComponent, {
      localVue,
      store,
      propsData: {
        installed: true,
97 98 99
        clustersPath: 'clustersPath',
        helpPath: 'helpPath',
        statusPath,
100 101 102 103 104
      },
      sync: false,
    });

    component.vm.$store.dispatch('receiveFunctionsSuccess', mockServerlessFunctions);
105

106 107 108
    return component.vm.$nextTick().then(() => {
      expect(component.vm.$el.querySelector('environmentrow-stub')).not.toBe(null);
    });
109 110
  });
});