/*
* ============LICENSE_START=======================================================
* Copyright (C) 2020-2021 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
const mod = require('../ApexPolicyTab');
const ApexUtils = require('../ApexUtils');
afterEach(() => {
document.body.innerHTML = '';
});
test('Test policyTab_activate', () => {
document.body.innerHTML = '
';
const data = {
useHttps: 'useHttps',
hostname: 'hostname',
port: 'port',
username: 'username',
password: 'password',
messages: {
message: [
'{' +
' "apexPolicy": {' +
' "policyKey": {' +
' "name": "name1",' +
' "version": "version1"' +
' },' +
' "template": "template1",' +
' "firstState": "key11",' +
' "state": {' +
' "entry": [' +
' {' +
' "key": "key1",' +
' "value": {' +
' "trigger": {' +
' "name": "name2",' +
' "version": "version2"' +
' },' +
' "taskReferences": {' +
' "entry": [' +
' {' +
' "key": {' +
' "name": "name3",' +
' "version": "version3"' +
' },' +
' "version": "version2",' +
' "value": {' +
' "outputType": "outputType1",' +
' "output": {' +
' "localName": "localName1"' +
' }' +
' }' +
' }' +
' ]' +
' },' +
' "defaultTask": {' +
' "name": "name4",' +
' "version": "version4"' +
' },' +
' "taskSelectionLogic": {' +
' "logicFlavour": "logicFlavour1"' +
' },' +
' "stateOutputs": {' +
' "entry": [' +
' {' +
' "key": "key2",' +
' "value": {' +
' "nextState": {' +
' "localName": "localName2"' +
' },' +
' "outgoingEvent": {' +
' "name": "name4",' +
' "version": "version4"' +
' }' +
' }' +
' }' +
' ]' +
' },' +
' "stateFinalizerLogicMap": {' +
' "entry": [' +
' {' +
' "key": "key3",' +
' "value": {' +
' "logicFlavour": "logicFlavour2"' +
' }' +
' }' +
' ]' +
' },' +
' "contextAlbumReference": [' +
' {' +
' "name": "name5",' +
' "version": "version5"' +
' }' +
' ]' +
' }' +
' },' +
' {' +
' "key": "key11",' +
' "value": {' +
' "trigger": {' +
' "name": "name12",' +
' "version": "version12"' +
' },' +
' "taskReferences": {' +
' "entry": [' +
' {' +
' "key": {' +
' "name": "name13",' +
' "version": "version13"' +
' },' +
' "version": "version12",' +
' "value": {' +
' "outputType": "outputType11",' +
' "output": {' +
' "localName": "localName11"' +
' }' +
' }' +
' }' +
' ]' +
' },' +
' "defaultTask": {' +
' "name": "name14",' +
' "version": "version14"' +
' },' +
' "taskSelectionLogic": {' +
' "logicFlavour": "logicFlavour11"' +
' },' +
' "stateOutputs": {' +
' "entry": [' +
' {' +
' "key": "key12",' +
' "value": {' +
' "nextState": {' +
' "localName": "localName12"' +
' },' +
' "outgoingEvent": {' +
' "name": "name14",' +
' "version": "version14"' +
' }' +
' }' +
' }' +
' ]' +
' },' +
' "stateFinalizerLogicMap": {' +
' "entry": [' +
' {' +
' "key": "key13",' +
' "value": {' +
' "logicFlavour": "logicFlavour12"' +
' }' +
' }' +
' ]' +
' },' +
' "contextAlbumReference": [' +
' {' +
' "name": "name15",' +
' "version": "version15"' +
' }' +
' ]' +
' }' +
' }' +
' ]' +
' }' +
' }' +
'}'
]
},
content: ['01', '02'],
result: 'ok',
ok: true
};
$.ajax = jest.fn().mockImplementation((args) => {
args.success(data, null, null);
});
const expected = '' +
'' +
'' +
'name1:version1 | ' +
'template1 | ' +
'key11 | ' +
'' +
'key11 | ' +
'name12:version12 | ' +
'' +
'name13:version13 | ' +
'outputType11 | ' +
'localName11 | ' +
'
| ' +
'name14:version14 | ' +
'logicFlavour11 | ' +
'' +
'key12 | ' +
'localName12 | ' +
'name14:version14 | ' +
'
| ' +
' | ' +
' | ' +
' ' +
'key1 | ' +
'name2:version2 | ' +
'' +
'name3:version3 | ' +
'outputType1 | ' +
'localName1 | ' +
'
| ' +
'name4:version4 | ' +
'logicFlavour1 | ' +
'' +
'' +
'key2 | ' +
'localName2 | ' +
'name4:version4 | ' +
' | ' +
' | ' +
' | ' +
'
|
';
mod.policyTab_activate();
expect(document.body.innerHTML).toBe(expected);
});
test('Test policyTab_deactivate', (done) => {
ApexUtils.apexUtils_removeElement = jest.fn(id => {
expect(id).toBe('policyTabContent');
done();
});
mod.policyTab_deactivate();
});
test('Test policyTab_create policyTabContent exists', () => {
document.body.innerHTML = '';
mod.policyTab_create();
expect(document.body.innerHTML).toBe('');
});
test('Test policyTab_create policiesTab does not exists', () => {
document.body.innerHTML = '';
mod.policyTab_create();
expect(document.body.innerHTML).toBe('');
});
test('Test policyTab_create', () => {
document.body.innerHTML = '';
const expected = '';
mod.policyTab_create();
expect(document.body.innerHTML).toBe(expected);
});