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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
import { createLocalVue, shallowMount } from '@vue/test-utils';
import Vuex from 'vuex';
import functionDetailsComponent from '~/serverless/components/function_details.vue';
import { createStore } from '~/serverless/store';
describe('functionDetailsComponent', () => {
let localVue;
let component;
let store;
beforeEach(() => {
localVue = createLocalVue();
localVue.use(Vuex);
store = createStore({ clustersPath: '/clusters', helpPath: '/help' });
});
afterEach(() => {
component.vm.$destroy();
});
describe('Verify base functionality', () => {
const serviceStub = {
name: 'test',
description: 'a description',
environment: '*',
url: 'http://service.com/test',
namespace: 'test-ns',
podcount: 0,
metricsUrl: '/metrics',
};
it('has a name, description, URL, and no pods loaded', () => {
component = shallowMount(functionDetailsComponent, {
localVue,
store,
propsData: {
func: serviceStub,
hasPrometheus: false,
},
});
expect(
component.vm.$el.querySelector('.serverless-function-name').innerHTML.trim(),
).toContain('test');
expect(
component.vm.$el.querySelector('.serverless-function-description').innerHTML.trim(),
).toContain('a description');
expect(component.vm.$el.querySelector('p').innerHTML.trim()).toContain(
'No pods loaded at this time.',
);
});
it('has a pods loaded', () => {
serviceStub.podcount = 1;
component = shallowMount(functionDetailsComponent, {
localVue,
store,
propsData: {
func: serviceStub,
hasPrometheus: false,
},
});
expect(component.vm.$el.querySelector('p').innerHTML.trim()).toContain('1 pod in use');
});
it('has multiple pods loaded', () => {
serviceStub.podcount = 3;
component = shallowMount(functionDetailsComponent, {
localVue,
store,
propsData: {
func: serviceStub,
hasPrometheus: false,
},
});
expect(component.vm.$el.querySelector('p').innerHTML.trim()).toContain('3 pods in use');
});
it('can support a missing description', () => {
serviceStub.description = null;
component = shallowMount(functionDetailsComponent, {
localVue,
store,
propsData: {
func: serviceStub,
hasPrometheus: false,
},
});
expect(
component.vm.$el.querySelector('.serverless-function-description').querySelector('div')
.innerHTML.length,
).toEqual(0);
});
});
});
|