summaryrefslogtreecommitdiff
path: root/spec/javascripts/serverless/components/functions_spec.js
blob: 85cfe71281ff8730b60fd5dbd085b983f525d179 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import Vue from 'vue';

import functionsComponent from '~/serverless/components/functions.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import ServerlessStore from '~/serverless/stores/serverless_store';

import { mockServerlessFunctions } from '../mock_data';

const createComponent = (
  functions,
  installed = true,
  loadingData = true,
  hasFunctionData = true,
) => {
  const component = Vue.extend(functionsComponent);

  return mountComponent(component, {
    functions,
    installed,
    clustersPath: '/testClusterPath',
    helpPath: '/helpPath',
    loadingData,
    hasFunctionData,
  });
};

describe('functionsComponent', () => {
  it('should render empty state when Knative is not installed', () => {
    const vm = createComponent({}, false);

    expect(vm.$el.querySelector('div.row').classList.contains('js-empty-state')).toBe(true);
    expect(vm.$el.querySelector('h4.state-title').innerHTML.trim()).toEqual(
      'Getting started with serverless',
    );

    vm.$destroy();
  });

  it('should render a loading component', () => {
    const vm = createComponent({});

    expect(vm.$el.querySelector('.gl-responsive-table-row')).not.toBe(null);
    expect(vm.$el.querySelector('div.animation-container')).not.toBe(null);
  });

  it('should render empty state when there is no function data', () => {
    const vm = createComponent({}, true, false, false);

    expect(
      vm.$el.querySelector('.empty-state, .js-empty-state').classList.contains('js-empty-state'),
    ).toBe(true);

    expect(vm.$el.querySelector('h4.state-title').innerHTML.trim()).toEqual(
      'No functions available',
    );

    vm.$destroy();
  });

  it('should render the functions list', () => {
    const store = new ServerlessStore(false, '/cluster_path', 'help_path');
    store.updateFunctionsFromServer(mockServerlessFunctions);
    const vm = createComponent(store.state.functions, true, false);

    expect(vm.$el.querySelector('div.groups-list-tree-container')).not.toBe(null);
    expect(vm.$el.querySelector('#env-global').classList.contains('has-children')).toBe(true);
  });
});