2022-09-20 22:43:48 +00:00
|
|
|
/*****************************************************************************
|
2024-01-09 21:31:51 +00:00
|
|
|
* Open MCT, Copyright (c) 2014-2024, United States Government
|
2022-09-20 22:43:48 +00:00
|
|
|
* 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.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2024-01-02 15:24:22 +00:00
|
|
|
import { createDomainObjectWithDefaults } from '../appActions.js';
|
2022-11-07 23:50:33 +00:00
|
|
|
|
2022-09-20 22:43:48 +00:00
|
|
|
const NOTEBOOK_DROP_AREA = '.c-notebook__drag-area';
|
2023-08-12 00:18:08 +00:00
|
|
|
const CUSTOM_NAME = 'CUSTOM_NAME';
|
2024-01-02 15:24:22 +00:00
|
|
|
import { fileURLToPath } from 'url';
|
2022-09-20 22:43:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {import('@playwright/test').Page} page
|
2024-04-16 20:54:40 +00:00
|
|
|
* @param {string} text
|
2022-09-20 22:43:48 +00:00
|
|
|
*/
|
|
|
|
async function enterTextEntry(page, text) {
|
2024-04-16 20:54:40 +00:00
|
|
|
await addNotebookEntry(page);
|
|
|
|
await enterTextInLastEntry(page, text);
|
|
|
|
await commitEntry(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {import('@playwright/test').Page} page
|
|
|
|
*/
|
|
|
|
async function addNotebookEntry(page) {
|
2023-05-18 21:54:46 +00:00
|
|
|
await page.locator(NOTEBOOK_DROP_AREA).click();
|
2024-04-16 20:54:40 +00:00
|
|
|
}
|
2022-09-20 22:43:48 +00:00
|
|
|
|
2024-04-16 20:54:40 +00:00
|
|
|
/**
|
|
|
|
* @param {import('@playwright/test').Page} page
|
|
|
|
*/
|
|
|
|
async function enterTextInLastEntry(page, text) {
|
2023-10-02 22:28:02 +00:00
|
|
|
await page.getByLabel('Notebook Entry Input').last().fill(text);
|
2022-09-20 22:43:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {import('@playwright/test').Page} page
|
|
|
|
*/
|
2022-11-07 23:50:33 +00:00
|
|
|
async function dragAndDropEmbed(page, notebookObject) {
|
2023-05-18 21:54:46 +00:00
|
|
|
// Create example telemetry object
|
|
|
|
const swg = await createDomainObjectWithDefaults(page, {
|
|
|
|
type: 'Sine Wave Generator'
|
|
|
|
});
|
|
|
|
// Navigate to notebook
|
|
|
|
await page.goto(notebookObject.url);
|
|
|
|
// Expand the tree to reveal the notebook
|
2024-01-23 05:41:56 +00:00
|
|
|
await page.getByLabel('Show selected item in tree').click();
|
2023-05-18 21:54:46 +00:00
|
|
|
// Drag and drop the SWG into the notebook
|
2024-08-07 21:36:14 +00:00
|
|
|
await page.getByLabel(`Navigate to ${swg.name}`).dragTo(page.locator(NOTEBOOK_DROP_AREA));
|
2023-10-12 05:34:32 +00:00
|
|
|
await commitEntry(page);
|
2023-03-10 19:00:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @param {import('@playwright/test').Page} page
|
|
|
|
*/
|
|
|
|
async function commitEntry(page) {
|
2023-05-18 21:54:46 +00:00
|
|
|
//Click the Commit Entry button
|
|
|
|
await page.locator('.c-ne__save-button > button').click();
|
2022-09-20 22:43:48 +00:00
|
|
|
}
|
|
|
|
|
2023-08-12 00:18:08 +00:00
|
|
|
/**
|
|
|
|
* @param {import('@playwright/test').Page} page
|
|
|
|
*/
|
|
|
|
async function startAndAddRestrictedNotebookObject(page) {
|
2024-01-02 15:24:22 +00:00
|
|
|
await page.addInitScript({
|
|
|
|
path: fileURLToPath(new URL('./addInitRestrictedNotebook.js', import.meta.url))
|
|
|
|
});
|
2023-08-12 00:18:08 +00:00
|
|
|
await page.goto('./', { waitUntil: 'domcontentloaded' });
|
2024-08-07 21:36:14 +00:00
|
|
|
await page.waitForURL('**/browse/mine?**');
|
2023-08-12 00:18:08 +00:00
|
|
|
|
|
|
|
return createDomainObjectWithDefaults(page, {
|
|
|
|
type: CUSTOM_NAME,
|
|
|
|
name: 'Restricted Test Notebook'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {import('@playwright/test').Page} page
|
|
|
|
*/
|
|
|
|
async function lockPage(page) {
|
2024-08-07 21:36:14 +00:00
|
|
|
// Click the Commit Entries button
|
|
|
|
await page.getByLabel('Commit Entries').click();
|
|
|
|
// Wait until Lock Banner is visible
|
2023-08-12 00:18:08 +00:00
|
|
|
await page.locator('text=Lock Page').click();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a notebook object and adds an entry.
|
|
|
|
* @param {import('@playwright/test').Page} - page to load
|
|
|
|
* @param {number} [iterations = 1] - the number of entries to create
|
|
|
|
*/
|
|
|
|
async function createNotebookAndEntry(page, iterations = 1) {
|
|
|
|
const notebook = createDomainObjectWithDefaults(page, { type: 'Notebook' });
|
|
|
|
|
|
|
|
for (let iteration = 0; iteration < iterations; iteration++) {
|
|
|
|
await enterTextEntry(page, `Entry ${iteration}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
return notebook;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a notebook object, adds an entry, and adds a tag.
|
|
|
|
* @param {import('@playwright/test').Page} page
|
|
|
|
* @param {number} [iterations = 1] - the number of entries (and tags) to create
|
|
|
|
*/
|
|
|
|
async function createNotebookEntryAndTags(page, iterations = 1) {
|
|
|
|
const notebook = await createNotebookAndEntry(page, iterations);
|
2023-09-11 23:33:46 +00:00
|
|
|
await page.getByRole('tab', { name: 'Annotations' }).click();
|
2023-08-12 00:18:08 +00:00
|
|
|
|
|
|
|
for (let iteration = 0; iteration < iterations; iteration++) {
|
|
|
|
// Hover and click "Add Tag" button
|
|
|
|
// Hover is needed here to "slow down" the actions while running in headless mode
|
|
|
|
await page.locator(`[aria-label="Notebook Entry"] >> nth = ${iteration}`).click();
|
|
|
|
await page.hover(`button:has-text("Add Tag")`);
|
|
|
|
await page.locator(`button:has-text("Add Tag")`).click();
|
|
|
|
|
|
|
|
// Click inside the tag search input
|
|
|
|
await page.locator('[placeholder="Type to select tag"]').click();
|
|
|
|
// Select the "Driving" tag
|
|
|
|
await page.locator('[aria-label="Autocomplete Options"] >> text=Driving').click();
|
|
|
|
|
|
|
|
// Hover and click "Add Tag" button
|
|
|
|
// Hover is needed here to "slow down" the actions while running in headless mode
|
|
|
|
await page.hover(`button:has-text("Add Tag")`);
|
|
|
|
await page.locator(`button:has-text("Add Tag")`).click();
|
|
|
|
// Click inside the tag search input
|
|
|
|
await page.locator('[placeholder="Type to select tag"]').click();
|
|
|
|
// Select the "Science" tag
|
|
|
|
await page.locator('[aria-label="Autocomplete Options"] >> text=Science').click();
|
|
|
|
}
|
|
|
|
|
|
|
|
return notebook;
|
|
|
|
}
|
|
|
|
|
2024-01-02 15:24:22 +00:00
|
|
|
export {
|
2024-04-16 20:54:40 +00:00
|
|
|
addNotebookEntry,
|
|
|
|
commitEntry,
|
2024-01-02 15:24:22 +00:00
|
|
|
createNotebookAndEntry,
|
|
|
|
createNotebookEntryAndTags,
|
2023-08-12 00:18:08 +00:00
|
|
|
dragAndDropEmbed,
|
2024-01-02 15:24:22 +00:00
|
|
|
enterTextEntry,
|
2024-04-16 20:54:40 +00:00
|
|
|
enterTextInLastEntry,
|
2023-08-12 00:18:08 +00:00
|
|
|
lockPage,
|
2024-01-02 15:24:22 +00:00
|
|
|
startAndAddRestrictedNotebookObject
|
2022-09-20 22:43:48 +00:00
|
|
|
};
|