2022-05-18 16:25:11 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* Open MCT, Copyright (c) 2014-2023, 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.
|
|
|
|
*****************************************************************************/
|
2024-01-02 15:24:22 +00:00
|
|
|
|
2022-05-18 16:25:11 +00:00
|
|
|
/*
|
2022-07-27 21:31:18 +00:00
|
|
|
This test suite is dedicated to tests which verify form functionality in isolation
|
2022-05-18 16:25:11 +00:00
|
|
|
*/
|
|
|
|
|
2024-01-02 15:24:22 +00:00
|
|
|
import { fileURLToPath } from 'url';
|
|
|
|
import { v4 as genUuid } from 'uuid';
|
|
|
|
|
|
|
|
import { createDomainObjectWithDefaults } from '../../appActions.js';
|
|
|
|
import { expect, test } from '../../pluginFixtures.js';
|
2022-05-18 16:25:11 +00:00
|
|
|
|
|
|
|
const TEST_FOLDER = 'test folder';
|
2023-01-17 20:25:18 +00:00
|
|
|
const jsonFilePath = 'e2e/test-data/ExampleLayouts.json';
|
|
|
|
const imageFilePath = 'e2e/test-data/rick.jpg';
|
2022-05-18 16:25:11 +00:00
|
|
|
|
2022-07-27 21:31:18 +00:00
|
|
|
test.describe('Form Validation Behavior', () => {
|
|
|
|
test('Required Field indicators appear if title is empty and can be corrected', async ({
|
|
|
|
page
|
|
|
|
}) => {
|
2022-05-18 16:25:11 +00:00
|
|
|
//Go to baseURL
|
2023-04-18 22:32:29 +00:00
|
|
|
await page.goto('./', { waitUntil: 'domcontentloaded' });
|
2023-05-18 21:54:46 +00:00
|
|
|
|
2022-05-18 16:25:11 +00:00
|
|
|
await page.click('button:has-text("Create")');
|
2023-07-19 18:22:23 +00:00
|
|
|
await page.getByRole('menuitem', { name: ' Folder' }).click();
|
2023-05-18 21:54:46 +00:00
|
|
|
|
2022-07-27 21:31:18 +00:00
|
|
|
// Fill in empty string into title and trigger validation with 'Tab'
|
2022-05-18 16:25:11 +00:00
|
|
|
await page.click('text=Properties Title Notes >> input[type="text"]');
|
|
|
|
await page.fill('text=Properties Title Notes >> input[type="text"]', '');
|
|
|
|
await page.press('text=Properties Title Notes >> input[type="text"]', 'Tab');
|
2023-05-18 21:54:46 +00:00
|
|
|
|
2022-07-27 21:31:18 +00:00
|
|
|
//Required Field Form Validation
|
2022-11-07 23:50:33 +00:00
|
|
|
await expect(page.locator('button:has-text("OK")')).toBeDisabled();
|
2022-05-18 16:25:11 +00:00
|
|
|
await expect(page.locator('.c-form-row__state-indicator').first()).toHaveClass(/invalid/);
|
2023-05-18 21:54:46 +00:00
|
|
|
|
2022-07-27 21:31:18 +00:00
|
|
|
//Correct Form Validation for missing title and trigger validation with 'Tab'
|
2022-05-18 16:25:11 +00:00
|
|
|
await page.click('text=Properties Title Notes >> input[type="text"]');
|
|
|
|
await page.fill('text=Properties Title Notes >> input[type="text"]', TEST_FOLDER);
|
|
|
|
await page.press('text=Properties Title Notes >> input[type="text"]', 'Tab');
|
2023-05-18 21:54:46 +00:00
|
|
|
|
2022-07-27 21:31:18 +00:00
|
|
|
//Required Field Form Validation is corrected
|
2022-11-07 23:50:33 +00:00
|
|
|
await expect(page.locator('button:has-text("OK")')).toBeEnabled();
|
2022-05-18 16:25:11 +00:00
|
|
|
await expect(page.locator('.c-form-row__state-indicator').first()).not.toHaveClass(/invalid/);
|
2023-05-18 21:54:46 +00:00
|
|
|
|
2022-07-27 21:31:18 +00:00
|
|
|
//Finish Creating Domain Object
|
2022-11-07 23:50:33 +00:00
|
|
|
await Promise.all([page.waitForNavigation(), page.click('button:has-text("OK")')]);
|
2023-05-18 21:54:46 +00:00
|
|
|
|
2022-07-27 21:31:18 +00:00
|
|
|
//Verify that the Domain Object has been created with the corrected title property
|
2022-05-18 16:25:11 +00:00
|
|
|
await expect(page.locator('.l-browse-bar__object-name')).toContainText(TEST_FOLDER);
|
|
|
|
});
|
2022-07-27 21:31:18 +00:00
|
|
|
});
|
|
|
|
|
2023-01-17 20:25:18 +00:00
|
|
|
test.describe('Form File Input Behavior', () => {
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
|
|
await page.addInitScript({
|
2024-01-02 15:24:22 +00:00
|
|
|
path: fileURLToPath(new URL('../../helper/addInitFileInputObject.js', import.meta.url))
|
2023-01-17 20:25:18 +00:00
|
|
|
});
|
2023-05-18 21:54:46 +00:00
|
|
|
});
|
2023-01-17 20:25:18 +00:00
|
|
|
|
|
|
|
test('Can select a JSON file type', async ({ page }) => {
|
2023-04-18 22:32:29 +00:00
|
|
|
await page.goto('./', { waitUntil: 'domcontentloaded' });
|
2023-01-17 20:25:18 +00:00
|
|
|
|
|
|
|
await page.getByRole('button', { name: ' Create ' }).click();
|
|
|
|
await page.getByRole('menuitem', { name: 'JSON File Input Object' }).click();
|
|
|
|
|
|
|
|
await page.setInputFiles('#fileElem', jsonFilePath);
|
|
|
|
|
|
|
|
await page.getByRole('button', { name: 'Save' }).click();
|
|
|
|
|
|
|
|
const type = await page.locator('#file-input-type').textContent();
|
|
|
|
await expect(type).toBe(`"string"`);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Can select an image file type', async ({ page }) => {
|
2023-04-18 22:32:29 +00:00
|
|
|
await page.goto('./', { waitUntil: 'domcontentloaded' });
|
2023-01-17 20:25:18 +00:00
|
|
|
|
|
|
|
await page.getByRole('button', { name: ' Create ' }).click();
|
|
|
|
await page.getByRole('menuitem', { name: 'Image File Input Object' }).click();
|
|
|
|
|
|
|
|
await page.setInputFiles('#fileElem', imageFilePath);
|
|
|
|
|
|
|
|
await page.getByRole('button', { name: 'Save' }).click();
|
|
|
|
|
|
|
|
const type = await page.locator('#file-input-type').textContent();
|
|
|
|
await expect(type).toBe(`"object"`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-07-27 21:31:18 +00:00
|
|
|
test.describe('Persistence operations @addInit', () => {
|
|
|
|
// add non persistable root item
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
|
|
await page.addInitScript({
|
2024-01-02 15:24:22 +00:00
|
|
|
path: fileURLToPath(new URL('../../helper/addNoneditableObject.js', import.meta.url))
|
2022-07-27 21:31:18 +00:00
|
|
|
});
|
2023-05-18 21:54:46 +00:00
|
|
|
});
|
2022-07-27 21:31:18 +00:00
|
|
|
|
|
|
|
test('Persistability should be respected in the create form location field', async ({ page }) => {
|
|
|
|
test.info().annotations.push({
|
|
|
|
type: 'issue',
|
|
|
|
description: 'https://github.com/nasa/openmct/issues/4323'
|
|
|
|
});
|
2023-04-18 22:32:29 +00:00
|
|
|
await page.goto('./', { waitUntil: 'domcontentloaded' });
|
2022-07-27 21:31:18 +00:00
|
|
|
|
|
|
|
await page.click('button:has-text("Create")');
|
|
|
|
|
|
|
|
await page.click('text=Condition Set');
|
|
|
|
|
|
|
|
await page.locator('form[name="mctForm"] >> text=Persistence Testing').click();
|
|
|
|
|
|
|
|
const okButton = page.locator('button:has-text("OK")');
|
|
|
|
await expect(okButton).toBeDisabled();
|
2022-05-18 16:25:11 +00:00
|
|
|
});
|
|
|
|
});
|
2022-07-27 21:31:18 +00:00
|
|
|
|
2022-11-08 00:04:02 +00:00
|
|
|
test.describe('Persistence operations @couchdb', () => {
|
|
|
|
test.use({ failOnConsoleError: false });
|
|
|
|
test('Editing object properties should generate a single persistence operation', async ({
|
2023-04-18 22:32:29 +00:00
|
|
|
page
|
|
|
|
}) => {
|
2022-11-08 00:04:02 +00:00
|
|
|
test.info().annotations.push({
|
|
|
|
type: 'issue',
|
|
|
|
description: 'https://github.com/nasa/openmct/issues/5616'
|
|
|
|
});
|
2023-05-18 21:54:46 +00:00
|
|
|
|
2023-04-05 13:24:57 +00:00
|
|
|
await page.goto('./', { waitUntil: 'domcontentloaded' });
|
2023-05-18 21:54:46 +00:00
|
|
|
|
2022-12-20 21:27:51 +00:00
|
|
|
// Create a new 'Clock' object with default settings
|
|
|
|
const clock = await createDomainObjectWithDefaults(page, {
|
|
|
|
type: 'Clock'
|
|
|
|
});
|
2023-05-18 21:54:46 +00:00
|
|
|
|
2022-11-08 00:04:02 +00:00
|
|
|
// Count all persistence operations (PUT requests) for this specific object
|
|
|
|
let putRequestCount = 0;
|
|
|
|
page.on('request', (req) => {
|
|
|
|
if (req.method() === 'PUT' && req.url().endsWith(clock.uuid)) {
|
|
|
|
putRequestCount += 1;
|
2023-05-18 21:54:46 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-11-08 00:04:02 +00:00
|
|
|
// Open the edit form for the clock object
|
2024-01-04 01:11:35 +00:00
|
|
|
await page.click('button[title="More actions"]');
|
2022-11-08 00:04:02 +00:00
|
|
|
await page.click('li[title="Edit properties of this object."]');
|
2023-05-18 21:54:46 +00:00
|
|
|
|
2022-11-08 00:04:02 +00:00
|
|
|
// Modify the display format from default 12hr -> 24hr and click 'Save'
|
|
|
|
await page
|
|
|
|
.locator('select[aria-label="12 or 24 hour clock"]')
|
|
|
|
.selectOption({ value: 'clock24' });
|
|
|
|
await page.click('button[aria-label="Save"]');
|
2023-05-18 21:54:46 +00:00
|
|
|
|
2022-11-08 00:04:02 +00:00
|
|
|
await expect
|
|
|
|
.poll(() => putRequestCount, {
|
|
|
|
message: 'Verify a single PUT request was made to persist the object',
|
|
|
|
timeout: 1000
|
2023-05-18 21:54:46 +00:00
|
|
|
})
|
2022-11-08 00:04:02 +00:00
|
|
|
.toEqual(1);
|
2023-05-18 21:54:46 +00:00
|
|
|
});
|
2023-04-05 13:24:57 +00:00
|
|
|
test('Can create an object after a conflict error @couchdb @2p', async ({
|
2023-05-18 21:54:46 +00:00
|
|
|
page,
|
2023-04-05 13:24:57 +00:00
|
|
|
openmctConfig
|
2023-05-18 21:54:46 +00:00
|
|
|
}) => {
|
2022-12-20 21:27:51 +00:00
|
|
|
test.info().annotations.push({
|
|
|
|
type: 'issue',
|
|
|
|
description: 'https://github.com/nasa/openmct/issues/5982'
|
2023-05-18 21:54:46 +00:00
|
|
|
});
|
2023-04-05 13:24:57 +00:00
|
|
|
const { myItemsFolderName } = openmctConfig;
|
|
|
|
// Instantiate a second page/tab
|
2022-12-20 21:27:51 +00:00
|
|
|
const page2 = await page.context().newPage();
|
2023-05-18 21:54:46 +00:00
|
|
|
|
2022-12-20 21:27:51 +00:00
|
|
|
// Both pages: Go to baseURL
|
|
|
|
await Promise.all([
|
|
|
|
page.goto('./', { waitUntil: 'networkidle' }),
|
|
|
|
page2.goto('./', { waitUntil: 'networkidle' })
|
2023-05-18 21:54:46 +00:00
|
|
|
]);
|
|
|
|
|
2023-04-05 13:24:57 +00:00
|
|
|
//Slow down the test a bit
|
2023-07-14 17:49:10 +00:00
|
|
|
await expect(
|
|
|
|
page.getByRole('button', { name: `Expand ${myItemsFolderName} folder` })
|
|
|
|
).toBeVisible();
|
|
|
|
await expect(
|
|
|
|
page2.getByRole('button', { name: `Expand ${myItemsFolderName} folder` })
|
|
|
|
).toBeVisible();
|
2023-05-18 21:54:46 +00:00
|
|
|
|
2022-12-20 21:27:51 +00:00
|
|
|
// Both pages: Click the Create button
|
|
|
|
await Promise.all([
|
|
|
|
page.click('button:has-text("Create")'),
|
|
|
|
page2.click('button:has-text("Create")')
|
2023-05-18 21:54:46 +00:00
|
|
|
]);
|
|
|
|
|
2022-12-20 21:27:51 +00:00
|
|
|
// Both pages: Click "Clock" in the Create menu
|
|
|
|
await Promise.all([
|
|
|
|
page.click(`li[role='menuitem']:text("Clock")`),
|
|
|
|
page2.click(`li[role='menuitem']:text("Clock")`)
|
2023-05-18 21:54:46 +00:00
|
|
|
]);
|
|
|
|
|
2022-12-20 21:27:51 +00:00
|
|
|
// Generate unique names for both objects
|
|
|
|
const nameInput = page.locator('form[name="mctForm"] .first input[type="text"]');
|
|
|
|
const nameInput2 = page2.locator('form[name="mctForm"] .first input[type="text"]');
|
2023-05-18 21:54:46 +00:00
|
|
|
|
2022-12-20 21:27:51 +00:00
|
|
|
// Both pages: Fill in the 'Name' form field.
|
|
|
|
await Promise.all([
|
|
|
|
nameInput.fill(''),
|
|
|
|
nameInput.fill(`Clock:${genUuid()}`),
|
|
|
|
nameInput2.fill(''),
|
|
|
|
nameInput2.fill(`Clock:${genUuid()}`)
|
2023-05-18 21:54:46 +00:00
|
|
|
]);
|
|
|
|
|
2022-12-20 21:27:51 +00:00
|
|
|
// Both pages: Fill the "Notes" section with information about the
|
|
|
|
// currently running test and its project.
|
|
|
|
const testNotes = page.testNotes;
|
|
|
|
const notesInput = page.locator('form[name="mctForm"] #notes-textarea');
|
|
|
|
const notesInput2 = page2.locator('form[name="mctForm"] #notes-textarea');
|
|
|
|
await Promise.all([notesInput.fill(testNotes), notesInput2.fill(testNotes)]);
|
2023-05-18 21:54:46 +00:00
|
|
|
|
2022-12-20 21:27:51 +00:00
|
|
|
// Page 2: Click "OK" to create the domain object and wait for navigation.
|
|
|
|
// This will update the composition of the parent folder, setting the
|
|
|
|
// conditions for a conflict error from the first page.
|
|
|
|
await Promise.all([
|
|
|
|
page2.waitForLoadState(),
|
|
|
|
page2.click('[aria-label="Save"]'),
|
|
|
|
// Wait for Save Banner to appear
|
|
|
|
page2.waitForSelector('.c-message-banner__message')
|
2023-05-18 21:54:46 +00:00
|
|
|
]);
|
|
|
|
|
2022-12-20 21:27:51 +00:00
|
|
|
// Close Page 2, we're done with it.
|
|
|
|
await page2.close();
|
2023-05-18 21:54:46 +00:00
|
|
|
|
2022-12-20 21:27:51 +00:00
|
|
|
// Page 1: Click "OK" to create the domain object and wait for navigation.
|
|
|
|
// This will trigger a conflict error upon attempting to update
|
|
|
|
// the composition of the parent folder.
|
|
|
|
await Promise.all([
|
|
|
|
page.waitForLoadState(),
|
|
|
|
page.click('[aria-label="Save"]'),
|
|
|
|
// Wait for Save Banner to appear
|
|
|
|
page.waitForSelector('.c-message-banner__message')
|
2023-05-18 21:54:46 +00:00
|
|
|
]);
|
|
|
|
|
2022-12-20 21:27:51 +00:00
|
|
|
// Page 1: Verify that the conflict has occurred and an error notification is displayed.
|
|
|
|
await expect(
|
|
|
|
page.locator('.c-message-banner__message', {
|
|
|
|
hasText: 'Conflict detected while saving mine'
|
2023-05-18 21:54:46 +00:00
|
|
|
})
|
2022-12-20 21:27:51 +00:00
|
|
|
).toBeVisible();
|
2023-05-18 21:54:46 +00:00
|
|
|
|
2022-12-20 21:27:51 +00:00
|
|
|
// Page 1: Start logging console errors from this point on
|
|
|
|
let errors = [];
|
|
|
|
page.on('console', (msg) => {
|
|
|
|
if (msg.type() === 'error') {
|
|
|
|
errors.push(msg.text());
|
2023-05-18 21:54:46 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-12-20 21:27:51 +00:00
|
|
|
// Page 1: Try to create a clock with the page that received the conflict.
|
|
|
|
const clockAfterConflict = await createDomainObjectWithDefaults(page, {
|
2022-11-08 00:04:02 +00:00
|
|
|
type: 'Clock'
|
2023-05-18 21:54:46 +00:00
|
|
|
});
|
|
|
|
|
2022-12-20 21:27:51 +00:00
|
|
|
// Page 1: Wait for save progress dialog to appear/disappear
|
2022-11-08 00:04:02 +00:00
|
|
|
await page
|
2022-12-20 21:27:51 +00:00
|
|
|
.locator('.c-message-banner__message', {
|
2023-05-18 21:54:46 +00:00
|
|
|
hasText:
|
2022-12-20 21:27:51 +00:00
|
|
|
'Do not navigate away from this page or close this browser tab while this message is displayed.',
|
|
|
|
state: 'visible'
|
2023-05-18 21:54:46 +00:00
|
|
|
})
|
2022-12-20 21:27:51 +00:00
|
|
|
.waitFor({ state: 'hidden' });
|
2023-05-18 21:54:46 +00:00
|
|
|
|
2022-12-20 21:27:51 +00:00
|
|
|
// Page 1: Navigate to 'My Items' and verify that the second clock was created
|
|
|
|
await page.goto('./#/browse/mine');
|
|
|
|
await expect(
|
|
|
|
page.locator(`.c-grid-item__name[title="${clockAfterConflict.name}"]`)
|
|
|
|
).toBeVisible();
|
2023-05-18 21:54:46 +00:00
|
|
|
|
2022-12-20 21:27:51 +00:00
|
|
|
// Verify no console errors occurred
|
|
|
|
expect(errors).toHaveLength(0);
|
2023-05-18 21:54:46 +00:00
|
|
|
});
|
2022-11-08 00:04:02 +00:00
|
|
|
});
|
|
|
|
|
2022-07-27 21:31:18 +00:00
|
|
|
test.describe('Form Correctness by Object Type', () => {
|
|
|
|
test.fixme('Verify correct behavior of number object (SWG)', async ({ page }) => {});
|
|
|
|
test.fixme('Verify correct behavior of number object Timer', async ({ page }) => {});
|
|
|
|
test.fixme('Verify correct behavior of number object Plan View', async ({ page }) => {});
|
|
|
|
test.fixme('Verify correct behavior of number object Clock', async ({ page }) => {});
|
|
|
|
test.fixme('Verify correct behavior of number object Hyperlink', async ({ page }) => {});
|
|
|
|
});
|