Welcome to mirror list, hosted at ThFree Co, Russian Federation.

pluginSpec.js « timeConductor « plugins « src - github.com/nasa/openmct.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d394784135d20422d00cbd3ef0ff05fd0f56f293 (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
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
/*****************************************************************************
 * Open MCT, Copyright (c) 2014-2022, United States Government
 * as represented by the Administrator of the National Aeronautics and Space
 * Administration. All rights reserved.
 *
 * Open MCT is 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.
 *
 * Open MCT includes source code licensed under additional open source
 * licenses. See the Open Source Licenses file (LICENSES.md) included with
 * this source code distribution or the Licensing information page available
 * at runtime from the About dialog for additional information.
 *****************************************************************************/

import {createMouseEvent, createOpenMct, resetApplicationState} from "utils/testing";
import {millisecondsToDHMS, getPreciseDuration} from "../../utils/duration";
import ConductorPlugin from "./plugin";
import Vue from 'vue';

const THIRTY_SECONDS = 30 * 1000;
const ONE_MINUTE = THIRTY_SECONDS * 2;
const FIVE_MINUTES = ONE_MINUTE * 5;
const FIFTEEN_MINUTES = FIVE_MINUTES * 3;
const THIRTY_MINUTES = FIFTEEN_MINUTES * 2;
const date = new Date(Date.UTC(78, 0, 20, 0, 0, 0)).getTime();

describe('time conductor', () => {
    let element;
    let child;
    let appHolder;
    let openmct;
    let config = {
        menuOptions: [
            {
                name: "FixedTimeRange",
                timeSystem: 'utc',
                bounds: {
                    start: date - THIRTY_MINUTES,
                    end: date
                },
                presets: [],
                records: 2
            },
            {
                name: "LocalClock",
                timeSystem: 'utc',
                clock: 'local',
                clockOffsets: {
                    start: -THIRTY_MINUTES,
                    end: THIRTY_SECONDS
                },
                presets: []
            }
        ]
    };

    beforeEach((done) => {
        openmct = createOpenMct();
        openmct.install(new ConductorPlugin(config));

        element = document.createElement('div');
        element.style.width = '640px';
        element.style.height = '480px';
        child = document.createElement('div');
        child.style.width = '640px';
        child.style.height = '480px';
        element.appendChild(child);

        openmct.on('start', () => {
            openmct.time.bounds({
                start: config.menuOptions[0].bounds.start,
                end: config.menuOptions[0].bounds.end
            });
            Vue.nextTick(() => {
                done();
            });
        });
        appHolder = document.createElement("div");
        openmct.start(appHolder);
    });

    afterEach(() => {
        appHolder = undefined;
        openmct = undefined;

        return resetApplicationState(openmct);
    });

    it('shows delta inputs in fixed mode', () => {
        const fixedModeEl = appHolder.querySelector('.is-fixed-mode');
        const dateTimeInputs = fixedModeEl.querySelectorAll('.c-input--datetime');
        expect(dateTimeInputs[0].value).toEqual('1978-01-19 23:30:00.000Z');
        expect(dateTimeInputs[1].value).toEqual('1978-01-20 00:00:00.000Z');
        expect(fixedModeEl.querySelector('.c-mode-button .c-button__label').innerHTML).toEqual('Fixed Timespan');
    });

    describe('shows delta inputs in realtime mode', () => {
        beforeEach((done) => {
            const switcher = appHolder.querySelector('.c-mode-button');
            const clickEvent = createMouseEvent("click");

            switcher.dispatchEvent(clickEvent);
            Vue.nextTick(() => {
                const clockItem = document.querySelectorAll('.c-conductor__mode-menu li')[1];
                clockItem.dispatchEvent(clickEvent);
                Vue.nextTick(() => {
                    done();
                });
            });
        });

        it('shows clock options', () => {
            const realtimeModeEl = appHolder.querySelector('.is-realtime-mode');
            const dateTimeInputs = realtimeModeEl.querySelectorAll('.c-conductor__delta-button');
            expect(dateTimeInputs[0].innerHTML.replace(/[^(\d|:)]/g, '')).toEqual('00:30:00');
            expect(dateTimeInputs[1].innerHTML.replace(/[^(\d|:)]/g, '')).toEqual('00:00:30');
            expect(realtimeModeEl.querySelector('.c-mode-button .c-button__label').innerHTML).toEqual('Local Clock');
        });
    });

});

describe('duration functions', () => {
    it('should transform milliseconds to DHMS', () => {
        const functionResults = [millisecondsToDHMS(0), millisecondsToDHMS(86400000),
            millisecondsToDHMS(129600000), millisecondsToDHMS(661824000)];
        const validResults = [' ', '+ 1d', '+ 1d 12h', '+ 7d 15h 50m 24s'];
        expect(validResults).toEqual(functionResults);
    });

    it('should get precise duration', () => {
        const functionResults = [getPreciseDuration(0), getPreciseDuration(643680000),
            getPreciseDuration(1605312000)];
        const validResults = ['00:00:00:00', '07:10:48:00', '18:13:55:12'];
        expect(validResults).toEqual(functionResults);
    });
});