Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mct7367-tests #7387

Merged
merged 38 commits into from
Jan 23, 2024
Merged
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
68edf79
refactor(ExportAsJSONAction): use private methods
ozyx Jan 10, 2024
b07a73e
refactor: remove unnecessary webpack alias
ozyx Jan 10, 2024
a0b71f4
refactor: lint
ozyx Jan 10, 2024
95ac152
fix: tests for `ExportAsJSONAction`
ozyx Jan 11, 2024
44fac67
test: stabilize `InspectorStylesSpec` tests
ozyx Jan 11, 2024
81b6b97
docs: fix jsdocs
ozyx Jan 11, 2024
9a1437a
chore: remove dead / redundant code
ozyx Jan 11, 2024
4f8403a
refactor(LocalStorageObjectProvider): use `getItem()` and `setItem()`
ozyx Jan 12, 2024
7378351
refactor(ExportAsJSONAction): use `Promise.all` where applicable
ozyx Jan 12, 2024
201deea
refactor(MenuAPI): one-liner
ozyx Jan 12, 2024
9f85a0b
feat: add percentage ProgressBar to ExportAsJSONAction
ozyx Jan 12, 2024
975ef25
fix(ProgressBar.vue): v-if conditionals
ozyx Jan 12, 2024
3a0c975
test(fix): update mockLocalStorage
ozyx Jan 12, 2024
24b80e3
test: fix locators
ozyx Jan 17, 2024
b88c849
test: remove unneeded awaits
ozyx Jan 17, 2024
d5b02b0
fix: example imagery urls (moved after NASA wordpress migration)
ozyx Jan 17, 2024
0de6640
Revert "refactor(LocalStorageObjectProvider): use `getItem()` and `se…
ozyx Jan 17, 2024
cb3d408
test(e2e): fix logPlot test
ozyx Jan 18, 2024
ef64b0d
Revert "Revert "refactor(LocalStorageObjectProvider): use `getItem()`…
ozyx Jan 18, 2024
b47ceff
test(e2e): remove waitForNavigations
ozyx Jan 18, 2024
fecd1ae
driveby and fixes
unlikelyzero Jan 18, 2024
590e2ea
aria improvement
unlikelyzero Jan 18, 2024
31bb25d
getting tests back oline
unlikelyzero Jan 18, 2024
c05e22d
more tests
unlikelyzero Jan 18, 2024
84caca1
Merge branch 'master' of https://github.com/nasa/openmct into mct7367…
unlikelyzero Jan 18, 2024
4901bf7
add last test
unlikelyzero Jan 18, 2024
0e9b667
Merge branch 'master' of https://github.com/nasa/openmct into mct7367…
unlikelyzero Jan 19, 2024
c26f124
Add a11y
unlikelyzero Jan 23, 2024
496b6c6
lint
unlikelyzero Jan 23, 2024
615face
lint
unlikelyzero Jan 23, 2024
406a94d
driveby
unlikelyzero Jan 23, 2024
7a4ee18
review comments
unlikelyzero Jan 23, 2024
16dd00c
driveby rename
unlikelyzero Jan 23, 2024
94b690a
fix selectors and break up test suites
unlikelyzero Jan 23, 2024
af95399
add test for snapshot in header
unlikelyzero Jan 23, 2024
ab01db9
last lint fixes
unlikelyzero Jan 23, 2024
f235d50
stable
unlikelyzero Jan 23, 2024
84597e8
comment
unlikelyzero Jan 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
This test suite is dedicated to tests which verify the basic operations surrounding exportAsJSON.
*/

import fs from 'fs';
import fs from 'fs/promises';

import {
createDomainObjectWithDefaults,
Expand All @@ -33,24 +33,21 @@ import {
import { expect, test } from '../../../../baseFixtures.js';

test.describe('ExportAsJSON', () => {
test('Create a basic object and verify that it can be exported as JSON from Tree', async ({
page,
browser
}) => {
// // Set up a download path
// const context = await browser.newContext({
// acceptDownloads: true
// });
// const page = await context.newPage();

// Navigate to the page
await page.goto('./');

let folder;
test.beforeEach(async ({ page }) => {
// Go to baseURL
await page.goto('./', { waitUntil: 'networkidle' });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

networkidle?

// Perform actions to create the domain object
const folder = await createDomainObjectWithDefaults(page, {
folder = await createDomainObjectWithDefaults(page, {
type: 'Folder',
name: 'e2e folder'
});
});
test('Create a basic object and verify that it can be exported as JSON from Tree', async ({
page
}) => {
// Navigate to the page
await page.goto(folder.url);

// Open context menu and initiate download
await openObjectTreeContextMenu(page, folder.url);
Expand All @@ -62,33 +59,105 @@ test.describe('ExportAsJSON', () => {
// Wait for the download process to complete
const path = await download.path();

// Read the contents of the downloaded file
const fileContents = await fs.promises.readFile(path, 'utf8');
// Read the contents of the downloaded file using readFile from fs/promises
const fileContents = await fs.readFile(path, 'utf8');
const jsonData = JSON.parse(fileContents);

// Verify the contents of the file (this is just an example, adjust as needed)
expect(fileContents).toContain('"name": "e2e folder"');
expect(fileContents).toContain('"type": "Folder"');
// Use the function to retrieve the key
const key = getFirstKeyFromOpenMctJson(jsonData);

// Clean up: Close the page and context
await page.close();
// Verify the contents of the JSON file
expect(jsonData.openmct[key]).toHaveProperty('name', 'e2e folder');
expect(jsonData.openmct[key]).toHaveProperty('type', 'folder');
});
test.fixme(
'Create a basic object and verify that it can be exported as JSON from 3 dot menu',
async ({ page }) => {
//Create domain object
//Save Domain Object
//Verify that the newly created domain object can be exported as JSON from the 3 dot menu
}
);
test.fixme('Verify that a nested Object can be exported as JSON', async ({ page }) => {
// Create 2 objects with hierarchy
// Export as JSON
// Verify Hierarchy
test('Create a basic object and verify that it can be exported as JSON from 3 dot menu', async ({
page
}) => {
// Navigate to the page
await page.goto(folder.url);
//3 dot menu
await page.getByLabel('More actions').click();
// Open context menu and initiate download
const [download] = await Promise.all([
page.waitForEvent('download'), // Waits for the download event
page.getByLabel('Export as JSON').click() // Triggers the download
]);

// Read the contents of the downloaded file using readFile from fs/promises
const fileContents = await fs.readFile(await download.path(), 'utf8');
const jsonData = JSON.parse(fileContents);

// Use the function to retrieve the key
const key = getFirstKeyFromOpenMctJson(jsonData);

// Verify the contents of the JSON file
expect(jsonData.openmct[key]).toHaveProperty('name', 'e2e folder');
expect(jsonData.openmct[key]).toHaveProperty('type', 'folder');
});
test('Verify that a nested Object can be exported as JSON', async ({ page }) => {
const timer = await createDomainObjectWithDefaults(page, {
type: 'Timer',
name: 'timer',
parent: folder.uuid
});
// Navigate to the page
await page.goto(timer.url);

//do this against parent folder.url, NOT timer.url child
await openObjectTreeContextMenu(page, folder.url);
// Open context menu and initiate download
const [download] = await Promise.all([
page.waitForEvent('download'), // Waits for the download event
page.getByLabel('Export as JSON').click() // Triggers the download
]);

// Read the contents of the downloaded file
const fileContents = await fs.readFile(await download.path(), 'utf8');
const jsonData = JSON.parse(fileContents);

// Retrieve the keys for folder and timer
const folderKey = getFirstKeyFromOpenMctJson(jsonData);
const timerKey = jsonData.openmct[folderKey].composition[0].key;

// Verify the folder properties
expect(jsonData.openmct[folderKey]).toHaveProperty('name', 'e2e folder');
expect(jsonData.openmct[folderKey]).toHaveProperty('type', 'folder');

// Verify the timer properties
expect(jsonData.openmct[timerKey]).toHaveProperty('name', 'timer');
expect(jsonData.openmct[timerKey]).toHaveProperty('type', 'timer');

// Verify the composition of the folder includes the timer
expect(jsonData.openmct[folderKey].composition).toEqual(
expect.arrayContaining([expect.objectContaining({ key: timerKey })])
);
});
});
test.describe('ExportAsJSON Disabled Actions', () => {
test.fixme(
'Verify that the ExportAsJSON dropdown does not appear for the item X',
async ({ page }) => {
// Other than non-persistable objects
}
);
});

/**
* Retrieves the first key from the 'openmct' property of the provided JSON object.
*
* @param {Object} jsonData - The JSON object containing the 'openmct' property.
* @returns {string} The first key found in the 'openmct' object.
* @throws {Error} If no keys are found in the 'openmct' object.
*/
function getFirstKeyFromOpenMctJson(jsonData) {
if (!jsonData.openmct) {
throw new Error("The provided JSON object does not have an 'openmct' property.");
}

const keys = Object.keys(jsonData.openmct);
if (keys.length === 0) {
throw new Error('No keys found in the openmct object');
}

return keys[0];
}