-
-
Notifications
You must be signed in to change notification settings - Fork 259
/
Copy pathScriptConfig_test.js
173 lines (133 loc) · 5.92 KB
/
ScriptConfig_test.js
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
'use strict';
import ScriptConfig from '@/admin/components/scripts-config/ScriptConfig';
import ScriptConfigForm from '@/admin/components/scripts-config/ScriptConfigForm';
import {mount} from '@vue/test-utils';
import Vuex from 'vuex';
import {attachToDocument, createScriptServerTestVue, vueTicks} from '../test_utils';
import {findField, setValueByUser} from './ParameterConfigForm_test';
const localVue = createScriptServerTestVue();
localVue.use(Vuex);
describe('Test ScriptConfig', function () {
let store;
let configComponent;
beforeEach(async function () {
store = new Vuex.Store({
modules: {
scriptConfig: {
namespaced: true,
state: {
scriptName: 'test_script',
scriptConfig: {'name': 'test_script', 'script_path': 'ping'}
},
actions: {
init({commit, state}, scriptName) {
},
save({dispatch, state}) {
}
}
}
}
});
configComponent = mount(ScriptConfig, {
store,
localVue,
attachTo: attachToDocument(),
propsData: {scriptName: 'script1'}
});
await vueTicks();
});
afterEach(async function () {
await vueTicks();
configComponent.destroy();
});
const _findField = (expectedName, failOnMissing = true) => {
const form = configComponent.find(ScriptConfigForm);
return findField(form.vm, expectedName, failOnMissing);
};
async function _setValueByUser(fieldName, value) {
const form = configComponent.find(ScriptConfigForm);
await setValueByUser(form.vm, fieldName, value);
}
describe('Test show config', function () {
it('Test show simple values', async function () {
store.state.scriptConfig.scriptConfig = {
'name': 's1',
'group': 'important',
'description': 'some desc',
'working_directory': '/home',
'requires_terminal': true,
'include': 'script.json',
'output_format': 'terminal'
};
await vueTicks();
expect(_findField('Script name').value).toBe('s1')
expect(_findField('Group').value).toBe('important')
expect(_findField('Description').value).toBe('some desc')
expect(_findField('Working directory').value).toBe('/home')
expect(_findField('Enable pseudo-terminal').value).toBe(true)
expect(_findField('Include config').value).toBe('script.json')
expect(_findField('Output format').value).toBe('terminal')
expect(configComponent.get('.path-textfield input').element.value).toBe('ping')
});
});
describe('Test edit config', function () {
it('Test edit group', async function () {
await _setValueByUser('Group', 'xyz');
expect(store.state.scriptConfig.scriptConfig.group).toBe('xyz')
});
});
describe('Test edit script', function () {
it('Test simple edit', async function () {
await configComponent.get('.path-textfield input').setValue('echo 123')
expect(store.state.scriptConfig.scriptConfig.script).toEqual({mode: 'new_path', path: 'echo 123'})
});
});
describe('Test edit allowed_users', function () {
it('Test edit allowed_users manually', async function () {
await _setValueByUser('Allow all', false);
await _setValueByUser('Allowed users', ['user A', 'user B']);
expect(store.state.scriptConfig.scriptConfig.allowed_users).toEqual(['user A', 'user B'])
});
});
describe('Test edit admin_users', function () {
it('Test edit admin_users manually', async function () {
await _setValueByUser('Any admin', false);
await _setValueByUser('Admin users', ['user A', 'user B']);
expect(store.state.scriptConfig.scriptConfig.admin_users).toEqual(['user A', 'user B'])
});
it('Test set any admin = false without any user, manually', async function () {
await _setValueByUser('Any admin', false);
expect(store.state.scriptConfig.scriptConfig.admin_users).toBeNil()
});
});
describe('Test edit output_format', function () {
it('Test edit output_format manually', async function () {
await _setValueByUser('Output format', 'html');
expect(store.state.scriptConfig.scriptConfig.output_format).toEqual('html')
});
});
describe('Test show shared instances access', function () {
it('Test show shared instances access unchecked', async function () {
store.state.scriptConfig.scriptConfig = {};
await vueTicks();
expect(_findField('Shared Script Instances').value).toBe(false);
});
it('Test show shared instances access checked', async function () {
store.state.scriptConfig.scriptConfig = {
'access': {'shared_access': {'type': 'ALL_USERS'}}
};
await vueTicks();
expect(_findField('Shared Script Instances').value).toBe(true);
});
});
describe('Test edit global_instances', function () {
it('Test update global_instances manually unchecked', async function () {
await _setValueByUser('Shared Script Instances', false);
expect(typeof store.state.scriptConfig.scriptConfig.access).toEqual('undefined');
});
it('Test update global_instances manually checked', async function () {
await _setValueByUser('Shared Script Instances', true);
expect(store.state.scriptConfig.scriptConfig.access).toEqual({'shared_access': {'type': 'ALL_USERS'}});
});
});
});