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

missingPlotObj.e2e.spec.js « plot « plugins « tests « e2e - github.com/nasa/openmct.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e13b7862049ff362cc2e2a6c39d58500da4a8637 (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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*****************************************************************************
 * 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.
 *****************************************************************************/

/*
Tests to verify log plot functionality when objects are missing
*/

const { test } = require('../../../fixtures.js');
const { expect } = require('@playwright/test');

test.describe('Handle missing object for plots', () => {
    test('Displays empty div for missing stacked plot item', async ({ page }) => {
        const errorLogs = [];

        page.on("console", (message) => {
            if (message.type() === 'warning') {
                errorLogs.push(message.text());
            }
        });

        //Make stacked plot
        await makeStackedPlot(page);

        //Gets local storage and deletes the last sine wave generator in the stacked plot
        const localStorage = await page.evaluate(() => window.localStorage);
        const parsedData = JSON.parse(localStorage.mct);
        const keys = Object.keys(parsedData);
        const lastKey = keys[keys.length - 1];

        delete parsedData[lastKey];

        //Sets local storage with missing object
        await page.evaluate(
            `window.localStorage.setItem('mct', '${JSON.stringify(parsedData)}')`
        );

        //Reloads page and clicks on stacked plot
        await Promise.all([
            page.reload(),
            page.waitForLoadState('networkidle')
        ]);

        //Verify Main section is there on load
        await expect.soft(page.locator('.l-browse-bar__object-name')).toContainText('Unnamed Stacked Plot');

        await page.locator('text=Open MCT My Items >> span').nth(3).click();
        await Promise.all([
            page.waitForNavigation(),
            page.locator('text=Unnamed Stacked Plot').first().click()
        ]);

        //Check that there is only one stacked item plot with a plot, the missing one will be empty
        await expect(page.locator(".c-plot--stacked-container:has(.gl-plot)")).toHaveCount(1);
        //Verify that console.warn is thrown
        await expect(errorLogs).toHaveLength(1);
    });
});

/**
 * This is used the create a stacked plot object
 * @private
 */
async function makeStackedPlot(page) {
    // fresh page with time range from 2022-03-29 22:00:00.000Z to 2022-03-29 22:00:30.000Z
    await page.goto('/', { waitUntil: 'networkidle' });

    // create stacked plot
    await page.locator('button.c-create-button').click();
    await page.locator('li:has-text("Stacked Plot")').click();

    await Promise.all([
        page.waitForNavigation({ waitUntil: 'networkidle'}),
        page.locator('text=OK').click(),
        //Wait for Save Banner to appear
        page.waitForSelector('.c-message-banner__message')
    ]);

    //Wait until Save Banner is gone
    await page.locator('.c-message-banner__close-button').click();
    await page.waitForSelector('.c-message-banner__message', { state: 'detached'});

    // save the stacked plot
    await saveStackedPlot(page);

    // create a sinewave generator
    await createSineWaveGenerator(page);

    // click on stacked plot
    await page.locator('text=Open MCT My Items >> span').nth(3).click();
    await Promise.all([
        page.waitForNavigation(),
        page.locator('text=Unnamed Stacked Plot').first().click()
    ]);

    // create a second sinewave generator
    await createSineWaveGenerator(page);

    // click on stacked plot
    await page.locator('text=Open MCT My Items >> span').nth(3).click();
    await Promise.all([
        page.waitForNavigation(),
        page.locator('text=Unnamed Stacked Plot').first().click()
    ]);
}

/**
 * This is used to save a stacked plot object
 * @private
 */
async function saveStackedPlot(page) {
    // save stacked plot
    await page.locator('text=Snapshot Save and Finish Editing Save and Continue Editing >> button').nth(1).click();

    await Promise.all([
        page.locator('text=Save and Finish Editing').click(),
        //Wait for Save Banner to appear
        page.waitForSelector('.c-message-banner__message')
    ]);
    //Wait until Save Banner is gone
    await page.locator('.c-message-banner__close-button').click();
    await page.waitForSelector('.c-message-banner__message', { state: 'detached' });
}

/**
 * This is used to create a sine wave generator object
 * @private
 */
async function createSineWaveGenerator(page) {
    //Create sine wave generator
    await page.locator('button.c-create-button').click();
    await page.locator('li:has-text("Sine Wave Generator")').click();

    await Promise.all([
        page.waitForNavigation({ waitUntil: 'networkidle'}),
        page.locator('text=OK').click(),
        //Wait for Save Banner to appear
        page.waitForSelector('.c-message-banner__message')
    ]);
    //Wait until Save Banner is gone
    await page.locator('.c-message-banner__close-button').click();
    await page.waitForSelector('.c-message-banner__message', { state: 'detached'});
}