Compare commits
119 Commits
v2.1.1
...
refactor-c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d16c60aa7a | ||
|
|
3ae6290ec3 | ||
|
|
ba5ed27e74 | ||
|
|
ca737d8afa | ||
|
|
33a275e8bc | ||
|
|
60e808689c | ||
|
|
8847c862fa | ||
|
|
1b71a3bf33 | ||
|
|
9980aab18f | ||
|
|
5e530aa625 | ||
|
|
986c596d90 | ||
|
|
4d84b16d8b | ||
|
|
20c7b23a4f | ||
|
|
d1c7d133fc | ||
|
|
edbbebe329 | ||
|
|
f98a2cdd6b | ||
|
|
22621aaaf8 | ||
|
|
e0ca6200bb | ||
|
|
70074c52c8 | ||
|
|
d5adaf6e8c | ||
|
|
8125632728 | ||
|
|
14c9dd0a32 | ||
|
|
9ae58f8441 | ||
|
|
4889284335 | ||
|
|
c2183d4de2 | ||
|
|
902d80c214 | ||
|
|
22ce817443 | ||
|
|
cdb202d8ba | ||
|
|
905373f294 | ||
|
|
60c07ab506 | ||
|
|
7336abc111 | ||
|
|
8fe9da89a3 | ||
|
|
e6bdaa957a | ||
|
|
93b5519c4b | ||
|
|
04ef4b369c | ||
|
|
5424a62db5 | ||
|
|
9ed9e62202 | ||
|
|
327fc826c1 | ||
|
|
a9e3eca35c | ||
|
|
cbecd79f71 | ||
|
|
3deb2e3dc2 | ||
|
|
d6e80447ab | ||
|
|
1a4bd0fb55 | ||
|
|
80f89c7609 | ||
|
|
b82649772f | ||
|
|
7f2ed27106 | ||
|
|
57e02db6b5 | ||
|
|
d54335d21c | ||
|
|
e0ed0bb6e2 | ||
|
|
ed3fd8f965 | ||
|
|
e6d59c61d1 | ||
|
|
b74b27c464 | ||
|
|
d35e161701 | ||
|
|
653cb62f9c | ||
|
|
19b3232fa0 | ||
|
|
19892aab53 | ||
|
|
a168ce25cf | ||
|
|
189c58f952 | ||
|
|
0dfc028e1b | ||
|
|
77e93f1aee | ||
|
|
394fbbe61b | ||
|
|
40afb04f0c | ||
|
|
be73b0158a | ||
|
|
625205f24b | ||
|
|
a706a8b73e | ||
|
|
1ddf5e5137 | ||
|
|
a79646a915 | ||
|
|
d5266e7ac7 | ||
|
|
05de7ee2e0 | ||
|
|
dad88112c4 | ||
|
|
202d6d8c5d | ||
|
|
e70bcc414c | ||
|
|
7bb4a136d7 | ||
|
|
8af3b4309f | ||
|
|
bed3d83fd7 | ||
|
|
efda42cf6d | ||
|
|
e8ee5b3fc9 | ||
|
|
393cb9767f | ||
|
|
8b5daad65c | ||
|
|
fabfecdb3e | ||
|
|
a2d8b13204 | ||
|
|
4b14d2d6d2 | ||
|
|
d545124942 | ||
|
|
6abdbfdff0 | ||
|
|
500e655476 | ||
|
|
5e1f026db2 | ||
|
|
d9efae98c8 | ||
|
|
091f6406a8 | ||
|
|
42a0e503cc | ||
|
|
4697352f60 | ||
|
|
015c764ab3 | ||
|
|
8fe465d9fc | ||
|
|
9c1368885a | ||
|
|
391c0b2e7c | ||
|
|
2ae061dbcd | ||
|
|
41fc502564 | ||
|
|
b4554d2fc1 | ||
|
|
feba5f6d3b | ||
|
|
4357d35f4a | ||
|
|
5041f80e5b | ||
|
|
9e23f79bc8 | ||
|
|
bd1e869f6a | ||
|
|
e4a36532e7 | ||
|
|
2bc2316613 | ||
|
|
2fa36b2176 | ||
|
|
efa38d779e | ||
|
|
951cc6ec0d | ||
|
|
ef4b8a9934 | ||
|
|
c14b48917e | ||
|
|
26165d0a99 | ||
|
|
f7cf3f72c2 | ||
|
|
cb8e09c9f9 | ||
|
|
026eb86f5f | ||
|
|
866859a937 | ||
|
|
afc54f41f6 | ||
|
|
72c980f991 | ||
|
|
9bf39a9cd4 | ||
|
|
33fd95cb2b | ||
|
|
8c92178895 |
@@ -2,7 +2,7 @@ version: 2.1
|
|||||||
executors:
|
executors:
|
||||||
pw-focal-development:
|
pw-focal-development:
|
||||||
docker:
|
docker:
|
||||||
- image: mcr.microsoft.com/playwright:v1.25.2-focal
|
- image: mcr.microsoft.com/playwright:v1.29.0-focal
|
||||||
environment:
|
environment:
|
||||||
NODE_ENV: development # Needed to ensure 'dist' folder created and devDependencies installed
|
NODE_ENV: development # Needed to ensure 'dist' folder created and devDependencies installed
|
||||||
PERCY_POSTINSTALL_BROWSER: 'true' # Needed to store the percy browser in cache deps
|
PERCY_POSTINSTALL_BROWSER: 'true' # Needed to store the percy browser in cache deps
|
||||||
|
|||||||
1
.github/codeql/codeql-config.yml
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
name: 'Custom CodeQL config'
|
||||||
12
.github/dependabot.yml
vendored
@@ -13,14 +13,18 @@ updates:
|
|||||||
- "pr:daveit"
|
- "pr:daveit"
|
||||||
- "pr:platform"
|
- "pr:platform"
|
||||||
ignore:
|
ignore:
|
||||||
#We have to source the container which is not detected by Dependabot
|
#We have to source the playwright container which is not detected by Dependabot
|
||||||
- dependency-name: "@playwright/test"
|
- dependency-name: "@playwright/test"
|
||||||
#Lots of noise in these type patch releases.
|
- dependency-name: "playwright-core"
|
||||||
|
#Lots of noise in these type patch releases.
|
||||||
- dependency-name: "@babel/eslint-parser"
|
- dependency-name: "@babel/eslint-parser"
|
||||||
update-types: ["version-update:semver-patch"]
|
update-types: ["version-update:semver-patch"]
|
||||||
- dependency-name: "eslint-plugin-vue"
|
- dependency-name: "eslint-plugin-vue"
|
||||||
update-types: ["version-update:semver-patch"]
|
update-types: ["version-update:semver-patch"]
|
||||||
|
- dependency-name: "babel-loader"
|
||||||
|
update-types: ["version-update:semver-patch"]
|
||||||
|
- dependency-name: "sinon"
|
||||||
|
update-types: ["version-update:semver-patch"]
|
||||||
- package-ecosystem: "github-actions"
|
- package-ecosystem: "github-actions"
|
||||||
directory: "/"
|
directory: "/"
|
||||||
schedule:
|
schedule:
|
||||||
|
|||||||
31
.github/workflows/codeql-analysis.yml
vendored
@@ -1,11 +1,10 @@
|
|||||||
|
name: 'CodeQL'
|
||||||
name: "CodeQL"
|
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
branches: [master, 'release/*']
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ master ]
|
branches: [master, 'release/*']
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- '**/*Spec.js'
|
- '**/*Spec.js'
|
||||||
- '**/*.md'
|
- '**/*.md'
|
||||||
@@ -27,17 +26,19 @@ jobs:
|
|||||||
security-events: write
|
security-events: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v2
|
uses: github/codeql-action/init@v2
|
||||||
with:
|
with:
|
||||||
languages: javascript
|
config-file: ./.github/codeql/codeql-config.yml
|
||||||
|
languages: javascript
|
||||||
|
queries: security-and-quality
|
||||||
|
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@v2
|
uses: github/codeql-action/autobuild@v2
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@v2
|
uses: github/codeql-action/analyze@v2
|
||||||
|
|||||||
2
.github/workflows/e2e-couchdb.yml
vendored
@@ -23,7 +23,7 @@ jobs:
|
|||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: '16'
|
node-version: '16'
|
||||||
- run: npx playwright@1.25.2 install
|
- run: npx playwright@1.29.0 install
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: sh src/plugins/persistence/couch/replace-localstorage-with-couchdb-indexhtml.sh
|
- run: sh src/plugins/persistence/couch/replace-localstorage-with-couchdb-indexhtml.sh
|
||||||
- run: npm run test:e2e:couchdb
|
- run: npm run test:e2e:couchdb
|
||||||
|
|||||||
2
.github/workflows/e2e-pr.yml
vendored
@@ -30,7 +30,7 @@ jobs:
|
|||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: '16'
|
node-version: '16'
|
||||||
- run: npx playwright@1.25.2 install
|
- run: npx playwright@1.29.0 install
|
||||||
- run: npx playwright install chrome-beta
|
- run: npx playwright install chrome-beta
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm run test:e2e:full
|
- run: npm run test:e2e:full
|
||||||
|
|||||||
98
.github/workflows/lighthouse.yml
vendored
@@ -1,98 +0,0 @@
|
|||||||
name: lighthouse
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
version:
|
|
||||||
description: 'Which branch do you want to test?' # Limited to branch for now
|
|
||||||
required: false
|
|
||||||
default: 'master'
|
|
||||||
pull_request:
|
|
||||||
types:
|
|
||||||
- labeled
|
|
||||||
jobs:
|
|
||||||
lighthouse-pr:
|
|
||||||
if: ${{ github.event.label.name == 'pr:lighthouse' }}
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout Master for Baseline
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
ref: master #explicitly checkout master for baseline
|
|
||||||
- name: Install Node 16
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
with:
|
|
||||||
node-version: '16'
|
|
||||||
- name: Cache node modules
|
|
||||||
uses: actions/cache@v2
|
|
||||||
env:
|
|
||||||
cache-name: cache-node-modules
|
|
||||||
with:
|
|
||||||
path: ~/.npm
|
|
||||||
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}
|
|
||||||
- name: npm install with lighthouse cli
|
|
||||||
run: npm install && npm install -g @lhci/cli
|
|
||||||
- name: Run lhci against master to generate baseline and ignore exit codes
|
|
||||||
run: lhci autorun || true
|
|
||||||
- name: Perform clean checkout of PR
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
clean: true
|
|
||||||
- name: Install Node version which is compatible with PR
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
- name: npm install with lighthouse cli
|
|
||||||
run: npm install && npm install -g @lhci/cli
|
|
||||||
- name: Run lhci with PR
|
|
||||||
run: lhci autorun
|
|
||||||
env:
|
|
||||||
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
|
|
||||||
lighthouse-nightly:
|
|
||||||
if: ${{ github.event.schedule }}
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: Install Node 16
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
with:
|
|
||||||
node-version: '16'
|
|
||||||
- name: Cache node modules
|
|
||||||
uses: actions/cache@v2
|
|
||||||
env:
|
|
||||||
cache-name: cache-node-modules
|
|
||||||
with:
|
|
||||||
path: ~/.npm
|
|
||||||
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}
|
|
||||||
- name: npm install with lighthouse cli
|
|
||||||
run: npm install && npm install -g @lhci/cli
|
|
||||||
- name: Run lhci against master to generate baseline
|
|
||||||
run: lhci autorun
|
|
||||||
env:
|
|
||||||
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
|
|
||||||
lighthouse-dispatch:
|
|
||||||
if: ${{ github.event.workflow_dispatch }}
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
ref: ${{ github.event.inputs.version }}
|
|
||||||
- name: Install Node 14
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
with:
|
|
||||||
node-version: '16'
|
|
||||||
- name: Cache node modules
|
|
||||||
uses: actions/cache@v3
|
|
||||||
env:
|
|
||||||
cache-name: cache-node-modules
|
|
||||||
with:
|
|
||||||
path: ~/.npm
|
|
||||||
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}
|
|
||||||
- name: npm install with lighthouse cli
|
|
||||||
run: npm install && npm install -g @lhci/cli
|
|
||||||
- name: Run lhci against master to generate baseline
|
|
||||||
run: lhci autorun
|
|
||||||
|
|
||||||
8
.github/workflows/npm-prerelease.yml
vendored
@@ -16,7 +16,11 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
node-version: 16
|
node-version: 16
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm test
|
- run: |
|
||||||
|
echo "//registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN" >> ~/.npmrc
|
||||||
|
npm whoami
|
||||||
|
npm publish --access=public --tag unstable openmct
|
||||||
|
# - run: npm test
|
||||||
|
|
||||||
publish-npm-prerelease:
|
publish-npm-prerelease:
|
||||||
needs: build
|
needs: build
|
||||||
@@ -28,6 +32,6 @@ jobs:
|
|||||||
node-version: 16
|
node-version: 16
|
||||||
registry-url: https://registry.npmjs.org/
|
registry-url: https://registry.npmjs.org/
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm publish --access public --tag unstable
|
- run: npm publish --access=public --tag unstable
|
||||||
env:
|
env:
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
|||||||
@@ -21,4 +21,10 @@
|
|||||||
!copyright-notice.html
|
!copyright-notice.html
|
||||||
!index.html
|
!index.html
|
||||||
!openmct.js
|
!openmct.js
|
||||||
!SECURITY.md
|
!SECURITY.md
|
||||||
|
|
||||||
|
# Add e2e tests to npm package
|
||||||
|
!/e2e/**/*
|
||||||
|
|
||||||
|
# ... except our test-data folder files.
|
||||||
|
/e2e/test-data/*.json
|
||||||
|
|||||||
176
.webpack/webpack.common.js
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
/* global __dirname module */
|
||||||
|
|
||||||
|
/*
|
||||||
|
This is the OpenMCT common webpack file. It is imported by the other three webpack configurations:
|
||||||
|
- webpack.prod.js - the production configuration for OpenMCT (default)
|
||||||
|
- webpack.dev.js - the development configuration for OpenMCT
|
||||||
|
- webpack.coverage.js - imports webpack.dev.js and adds code coverage
|
||||||
|
There are separate npm scripts to use these configurations, though simply running `npm install`
|
||||||
|
will use the default production configuration.
|
||||||
|
*/
|
||||||
|
const path = require("path");
|
||||||
|
const packageDefinition = require("../package.json");
|
||||||
|
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
||||||
|
const webpack = require("webpack");
|
||||||
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
||||||
|
|
||||||
|
const { VueLoaderPlugin } = require("vue-loader");
|
||||||
|
let gitRevision = "error-retrieving-revision";
|
||||||
|
let gitBranch = "error-retrieving-branch";
|
||||||
|
|
||||||
|
try {
|
||||||
|
gitRevision = require("child_process")
|
||||||
|
.execSync("git rev-parse HEAD")
|
||||||
|
.toString()
|
||||||
|
.trim();
|
||||||
|
gitBranch = require("child_process")
|
||||||
|
.execSync("git rev-parse --abbrev-ref HEAD")
|
||||||
|
.toString()
|
||||||
|
.trim();
|
||||||
|
} catch (err) {
|
||||||
|
console.warn(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
const projectRootDir = path.resolve(__dirname, "..");
|
||||||
|
|
||||||
|
/** @type {import('webpack').Configuration} */
|
||||||
|
const config = {
|
||||||
|
context: projectRootDir,
|
||||||
|
entry: {
|
||||||
|
openmct: "./openmct.js",
|
||||||
|
generatorWorker: "./example/generator/generatorWorker.js",
|
||||||
|
couchDBChangesFeed:
|
||||||
|
"./src/plugins/persistence/couch/CouchChangesFeed.js",
|
||||||
|
inMemorySearchWorker: "./src/api/objects/InMemorySearchWorker.js",
|
||||||
|
espressoTheme: "./src/plugins/themes/espresso-theme.scss",
|
||||||
|
snowTheme: "./src/plugins/themes/snow-theme.scss"
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
globalObject: "this",
|
||||||
|
filename: "[name].js",
|
||||||
|
path: path.resolve(projectRootDir, "dist"),
|
||||||
|
library: "openmct",
|
||||||
|
libraryTarget: "umd",
|
||||||
|
publicPath: "",
|
||||||
|
hashFunction: "xxhash64",
|
||||||
|
clean: true
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
"@": path.join(projectRootDir, "src"),
|
||||||
|
legacyRegistry: path.join(projectRootDir, "src/legacyRegistry"),
|
||||||
|
saveAs: "file-saver/src/FileSaver.js",
|
||||||
|
csv: "comma-separated-values",
|
||||||
|
EventEmitter: "eventemitter3",
|
||||||
|
bourbon: "bourbon.scss",
|
||||||
|
"plotly-basic": "plotly.js-basic-dist",
|
||||||
|
"plotly-gl2d": "plotly.js-gl2d-dist",
|
||||||
|
"d3-scale": path.join(
|
||||||
|
projectRootDir,
|
||||||
|
"node_modules/d3-scale/dist/d3-scale.min.js"
|
||||||
|
),
|
||||||
|
printj: path.join(
|
||||||
|
projectRootDir,
|
||||||
|
"node_modules/printj/dist/printj.min.js"
|
||||||
|
),
|
||||||
|
styles: path.join(projectRootDir, "src/styles"),
|
||||||
|
MCT: path.join(projectRootDir, "src/MCT"),
|
||||||
|
testUtils: path.join(projectRootDir, "src/utils/testUtils.js"),
|
||||||
|
objectUtils: path.join(
|
||||||
|
projectRootDir,
|
||||||
|
"src/api/objects/object-utils.js"
|
||||||
|
),
|
||||||
|
"kdbush": path.join(projectRootDir, "node_modules/kdbush/kdbush.min.js"),
|
||||||
|
utils: path.join(projectRootDir, "src/utils")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new webpack.DefinePlugin({
|
||||||
|
__OPENMCT_VERSION__: `'${packageDefinition.version}'`,
|
||||||
|
__OPENMCT_BUILD_DATE__: `'${new Date()}'`,
|
||||||
|
__OPENMCT_REVISION__: `'${gitRevision}'`,
|
||||||
|
__OPENMCT_BUILD_BRANCH__: `'${gitBranch}'`
|
||||||
|
}),
|
||||||
|
new VueLoaderPlugin(),
|
||||||
|
new CopyWebpackPlugin({
|
||||||
|
patterns: [
|
||||||
|
{
|
||||||
|
from: "src/images/favicons",
|
||||||
|
to: "favicons"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
from: "./index.html",
|
||||||
|
transform: function (content) {
|
||||||
|
return content.toString().replace(/dist\//g, "");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
from: "src/plugins/imagery/layers",
|
||||||
|
to: "imagery"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}),
|
||||||
|
new MiniCssExtractPlugin({
|
||||||
|
filename: "[name].css",
|
||||||
|
chunkFilename: "[name].css"
|
||||||
|
})
|
||||||
|
],
|
||||||
|
module: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
test: /\.(sc|sa|c)ss$/,
|
||||||
|
use: [
|
||||||
|
MiniCssExtractPlugin.loader,
|
||||||
|
{
|
||||||
|
loader: "css-loader"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
loader: "resolve-url-loader"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
loader: "sass-loader",
|
||||||
|
options: { sourceMap: true }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.vue$/,
|
||||||
|
use: "vue-loader"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.html$/,
|
||||||
|
type: "asset/source"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.(jpg|jpeg|png|svg)$/,
|
||||||
|
type: "asset/resource",
|
||||||
|
generator: {
|
||||||
|
filename: "images/[name][ext]"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.ico$/,
|
||||||
|
type: "asset/resource",
|
||||||
|
generator: {
|
||||||
|
filename: "icons/[name][ext]"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.(woff|woff2?|eot|ttf)$/,
|
||||||
|
type: "asset/resource",
|
||||||
|
generator: {
|
||||||
|
filename: "fonts/[name][ext]"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
stats: "errors-warnings",
|
||||||
|
performance: {
|
||||||
|
// We should eventually consider chunking to decrease
|
||||||
|
// these values
|
||||||
|
maxEntrypointSize: 27000000,
|
||||||
|
maxAssetSize: 27000000
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = config;
|
||||||
@@ -6,9 +6,9 @@ OpenMCT Continuous Integration servers use this configuration to add code covera
|
|||||||
information to pull requests.
|
information to pull requests.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const config = require('./webpack.dev');
|
const config = require("./webpack.dev");
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
const CI = process.env.CI === 'true';
|
const CI = process.env.CI === "true";
|
||||||
|
|
||||||
config.devtool = CI ? false : undefined;
|
config.devtool = CI ? false : undefined;
|
||||||
|
|
||||||
@@ -18,13 +18,18 @@ config.module.rules.push({
|
|||||||
test: /\.js$/,
|
test: /\.js$/,
|
||||||
exclude: /(Spec\.js$)|(node_modules)/,
|
exclude: /(Spec\.js$)|(node_modules)/,
|
||||||
use: {
|
use: {
|
||||||
loader: 'babel-loader',
|
loader: "babel-loader",
|
||||||
options: {
|
options: {
|
||||||
retainLines: true,
|
retainLines: true,
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
plugins: [['babel-plugin-istanbul', {
|
plugins: [
|
||||||
extension: ['.js', '.vue']
|
[
|
||||||
}]]
|
"babel-plugin-istanbul",
|
||||||
|
{
|
||||||
|
extension: [".js", ".vue"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
59
.webpack/webpack.dev.js
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
/* global __dirname module */
|
||||||
|
|
||||||
|
/*
|
||||||
|
This configuration should be used for development purposes. It contains full source map, a
|
||||||
|
devServer (which be invoked using by `npm start`), and a non-minified Vue.js distribution.
|
||||||
|
If OpenMCT is to be used for a production server, use webpack.prod.js instead.
|
||||||
|
*/
|
||||||
|
const path = require("path");
|
||||||
|
const webpack = require("webpack");
|
||||||
|
const { merge } = require("webpack-merge");
|
||||||
|
|
||||||
|
const common = require("./webpack.common");
|
||||||
|
const projectRootDir = path.resolve(__dirname, "..");
|
||||||
|
|
||||||
|
module.exports = merge(common, {
|
||||||
|
mode: "development",
|
||||||
|
watchOptions: {
|
||||||
|
// Since we use require.context, webpack is watching the entire directory.
|
||||||
|
// We need to exclude any files we don't want webpack to watch.
|
||||||
|
// See: https://webpack.js.org/configuration/watch/#watchoptions-exclude
|
||||||
|
ignored: [
|
||||||
|
"**/{node_modules,dist,docs,e2e}", // All files in node_modules, dist, docs, e2e,
|
||||||
|
"**/{*.yml,Procfile,webpack*.js,babel*.js,package*.json,tsconfig.json}", // Config files
|
||||||
|
"**/*.{sh,md,png,ttf,woff,svg}", // Non source files
|
||||||
|
"**/.*" // dotfiles and dotfolders
|
||||||
|
]
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
vue: path.join(projectRootDir, "node_modules/vue/dist/vue.js")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new webpack.DefinePlugin({
|
||||||
|
__OPENMCT_ROOT_RELATIVE__: '"dist/"'
|
||||||
|
})
|
||||||
|
],
|
||||||
|
devtool: "eval-source-map",
|
||||||
|
devServer: {
|
||||||
|
devMiddleware: {
|
||||||
|
writeToDisk: (filePathString) => {
|
||||||
|
const filePath = path.parse(filePathString);
|
||||||
|
const shouldWrite = !filePath.base.includes("hot-update");
|
||||||
|
|
||||||
|
return shouldWrite;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watchFiles: ["**/*.css"],
|
||||||
|
static: {
|
||||||
|
directory: path.join(__dirname, "..", "/dist"),
|
||||||
|
publicPath: "/dist",
|
||||||
|
watch: false
|
||||||
|
},
|
||||||
|
client: {
|
||||||
|
progress: true,
|
||||||
|
overlay: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -4,17 +4,18 @@
|
|||||||
This configuration should be used for production installs.
|
This configuration should be used for production installs.
|
||||||
It is the default webpack configuration.
|
It is the default webpack configuration.
|
||||||
*/
|
*/
|
||||||
const { merge } = require('webpack-merge');
|
const path = require("path");
|
||||||
const common = require('./webpack.common');
|
const webpack = require("webpack");
|
||||||
|
const { merge } = require("webpack-merge");
|
||||||
|
|
||||||
const path = require('path');
|
const common = require("./webpack.common");
|
||||||
const webpack = require('webpack');
|
const projectRootDir = path.resolve(__dirname, "..");
|
||||||
|
|
||||||
module.exports = merge(common, {
|
module.exports = merge(common, {
|
||||||
mode: 'production',
|
mode: "production",
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
"vue": path.join(__dirname, "node_modules/vue/dist/vue.min.js")
|
vue: path.join(projectRootDir, "node_modules/vue/dist/vue.min.js")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
@@ -22,5 +23,5 @@ module.exports = merge(common, {
|
|||||||
__OPENMCT_ROOT_RELATIVE__: '""'
|
__OPENMCT_ROOT_RELATIVE__: '""'
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
devtool: 'eval-source-map'
|
devtool: "source-map"
|
||||||
});
|
});
|
||||||
@@ -10,7 +10,7 @@ accept changes from external contributors.
|
|||||||
|
|
||||||
The short version:
|
The short version:
|
||||||
|
|
||||||
1. Write your contribution or describe your idea in the form of an [GitHub issue](https://github.com/nasa/openmct/issues/new/choose) or [Starting a GitHub Discussion](https://github.com/nasa/openmct/discussions)
|
1. Write your contribution or describe your idea in the form of a [GitHub issue](https://github.com/nasa/openmct/issues/new/choose) or [start a GitHub discussion](https://github.com/nasa/openmct/discussions).
|
||||||
2. Make sure your contribution meets code, test, and commit message
|
2. Make sure your contribution meets code, test, and commit message
|
||||||
standards as described below.
|
standards as described below.
|
||||||
3. Submit a pull request from a topic branch back to `master`. Include a check
|
3. Submit a pull request from a topic branch back to `master`. Include a check
|
||||||
|
|||||||
@@ -6,10 +6,8 @@ Please visit our [Official Site](https://nasa.github.io/openmct/) and [Getting S
|
|||||||
|
|
||||||
Once you've created something amazing with Open MCT, showcase your work in our GitHub Discussions [Show and Tell](https://github.com/nasa/openmct/discussions/categories/show-and-tell) section. We love seeing unique and wonderful implementations of Open MCT!
|
Once you've created something amazing with Open MCT, showcase your work in our GitHub Discussions [Show and Tell](https://github.com/nasa/openmct/discussions/categories/show-and-tell) section. We love seeing unique and wonderful implementations of Open MCT!
|
||||||
|
|
||||||
## See Open MCT in Action
|

|
||||||
|
|
||||||
Try Open MCT now with our [live demo](https://openmct-demo.herokuapp.com/).
|
|
||||||

|
|
||||||
|
|
||||||
## Building and Running Open MCT Locally
|
## Building and Running Open MCT Locally
|
||||||
|
|
||||||
@@ -100,7 +98,7 @@ To run the performance tests:
|
|||||||
The test suite is configured to all tests localed in `e2e/tests/` ending in `*.e2e.spec.js`. For more about the e2e test suite, please see the [README](./e2e/README.md)
|
The test suite is configured to all tests localed in `e2e/tests/` ending in `*.e2e.spec.js`. For more about the e2e test suite, please see the [README](./e2e/README.md)
|
||||||
|
|
||||||
### Security Tests
|
### Security Tests
|
||||||
Each commit is analyzed for known security vulnerabilities using [CodeQL](https://codeql.github.com/docs/codeql-language-guides/codeql-library-for-javascript/) and our overall security report is available on [LGTM](https://lgtm.com/projects/g/nasa/openmct/)
|
Each commit is analyzed for known security vulnerabilities using [CodeQL](https://codeql.github.com/docs/codeql-language-guides/codeql-library-for-javascript/) and our overall security report is available on [LGTM](https://lgtm.com/projects/g/nasa/openmct/). The list of CWE coverage items is avaiable in the [CodeQL docs](https://codeql.github.com/codeql-query-help/javascript-cwe/). The CodeQL workflow is specified in the [CodeQL analysis file](./.github/workflows/codeql-analysis.yml) and the custom [CodeQL config](./.github/codeql/codeql-config.yml).
|
||||||
|
|
||||||
### Test Reporting and Code Coverage
|
### Test Reporting and Code Coverage
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ This document is designed to capture on the What, Why, and How's of writing and
|
|||||||
|
|
||||||
1. [Getting Started](#getting-started)
|
1. [Getting Started](#getting-started)
|
||||||
2. [Types of Testing](#types-of-e2e-testing)
|
2. [Types of Testing](#types-of-e2e-testing)
|
||||||
3. [Architecture](#architecture)
|
3. [Architecture](#test-architecture-and-ci)
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
@@ -276,14 +276,36 @@ Skipping based on browser version (Rarely used): <https://github.com/microsoft/p
|
|||||||
- Leverage `await page.goto('./', { waitUntil: 'networkidle' });`
|
- Leverage `await page.goto('./', { waitUntil: 'networkidle' });`
|
||||||
- Avoid repeated setup to test to test a single assertion. Write longer tests with multiple soft assertions.
|
- Avoid repeated setup to test to test a single assertion. Write longer tests with multiple soft assertions.
|
||||||
|
|
||||||
### How to write a great test (TODO)
|
### How to write a great test (WIP)
|
||||||
|
|
||||||
|
- Use our [App Actions](./appActions.js) for performing common actions whenever applicable.
|
||||||
|
- If you create an object outside of using the `createDomainObjectWithDefaults` App Action, make sure to fill in the 'Notes' section of your object with `page.testNotes`:
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Fill the "Notes" section with information about the
|
||||||
|
// currently running test and its project.
|
||||||
|
const { testNotes } = page;
|
||||||
|
const notesInput = page.locator('form[name="mctForm"] #notes-textarea');
|
||||||
|
await notesInput.fill(testNotes);
|
||||||
|
```
|
||||||
|
|
||||||
#### How to write a great visual test (TODO)
|
#### How to write a great visual test (TODO)
|
||||||
|
|
||||||
|
#### How to write a great network test
|
||||||
|
|
||||||
|
- Where possible, it is best to mock out third-party network activity to ensure we are testing application behavior of Open MCT.
|
||||||
|
- It is best to be as specific as possible about the expected network request/response structures in creating your mocks.
|
||||||
|
- Make sure to only mock requests which are relevant to the specific behavior being tested.
|
||||||
|
- Where possible, network requests and responses should be treated in an order-agnostic manner, as the order in which certain requests/responses happen is dynamic and subject to change.
|
||||||
|
|
||||||
|
Some examples of mocking network responses in regards to CouchDB can be found in our [couchdb.e2e.spec.js](./tests/functional/couchdb.e2e.spec.js) test file.
|
||||||
|
|
||||||
### Best Practices
|
### Best Practices
|
||||||
|
|
||||||
For now, our best practices exist as self-tested, living documentation in our [exampleTemplate.e2e.spec.js](./tests/framework/exampleTemplate.e2e.spec.js) file.
|
For now, our best practices exist as self-tested, living documentation in our [exampleTemplate.e2e.spec.js](./tests/framework/exampleTemplate.e2e.spec.js) file.
|
||||||
|
|
||||||
|
For best practices with regards to mocking network responses, see our [couchdb.e2e.spec.js](./tests/functional/couchdb.e2e.spec.js) file.
|
||||||
|
|
||||||
### Tips & Tricks (TODO)
|
### Tips & Tricks (TODO)
|
||||||
|
|
||||||
The following contains a list of tips and tricks which don't exactly fit into a FAQ or Best Practices doc.
|
The following contains a list of tips and tricks which don't exactly fit into a FAQ or Best Practices doc.
|
||||||
@@ -378,3 +400,23 @@ A single e2e test in Open MCT is extended to run:
|
|||||||
- Tests won't start because 'Error: <http://localhost:8080/># is already used...'
|
- Tests won't start because 'Error: <http://localhost:8080/># is already used...'
|
||||||
This error will appear when running the tests locally. Sometimes, the webserver is left in an orphaned state and needs to be cleaned up. To clear up the orphaned webserver, execute the following from your Terminal:
|
This error will appear when running the tests locally. Sometimes, the webserver is left in an orphaned state and needs to be cleaned up. To clear up the orphaned webserver, execute the following from your Terminal:
|
||||||
```lsof -n -i4TCP:8080 | awk '{print$2}' | tail -1 | xargs kill -9```
|
```lsof -n -i4TCP:8080 | awk '{print$2}' | tail -1 | xargs kill -9```
|
||||||
|
|
||||||
|
### Upgrading Playwright
|
||||||
|
|
||||||
|
In order to upgrade from one version of Playwright to another, the version should be updated in several places in both `openmct` and `openmct-yamcs` repos. An easy way to identify these locations is to search for the current version in all files and find/replace.
|
||||||
|
|
||||||
|
For reference, all of the locations where the version should be updated are listed below:
|
||||||
|
|
||||||
|
#### **In `openmct`:**
|
||||||
|
|
||||||
|
- `package.json`
|
||||||
|
- Both packages `@playwright/test` and `playwright-core` should be updated to the same target version.
|
||||||
|
- `.circleci/config.yml`
|
||||||
|
- `.github/workflows/e2e-couchdb.yml`
|
||||||
|
- `.github/workflows/e2e-pr.yml`
|
||||||
|
|
||||||
|
#### **In `openmct-yamcs`:**
|
||||||
|
|
||||||
|
- `package.json`
|
||||||
|
- `@playwright/test` should be updated to the target version.
|
||||||
|
- `.github/workflows/yamcs-quickstart-e2e.yml`
|
||||||
|
|||||||
@@ -45,7 +45,16 @@
|
|||||||
* @property {string} url the relative url to the object (for use with `page.goto()`)
|
* @property {string} url the relative url to the object (for use with `page.goto()`)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines parameters to be used in the creation of a notification.
|
||||||
|
* @typedef {Object} CreateNotificationOptions
|
||||||
|
* @property {string} message the message
|
||||||
|
* @property {'info' | 'alert' | 'error'} severity the severity
|
||||||
|
* @property {import('../src/api/notifications/NotificationAPI').NotificationOptions} [notificationOptions] additional options
|
||||||
|
*/
|
||||||
|
|
||||||
const Buffer = require('buffer').Buffer;
|
const Buffer = require('buffer').Buffer;
|
||||||
|
const genUuid = require('uuid').v4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This common function creates a domain object with the default options. It is the preferred way of creating objects
|
* This common function creates a domain object with the default options. It is the preferred way of creating objects
|
||||||
@@ -56,6 +65,10 @@ const Buffer = require('buffer').Buffer;
|
|||||||
* @returns {Promise<CreatedObjectInfo>} An object containing information about the newly created domain object.
|
* @returns {Promise<CreatedObjectInfo>} An object containing information about the newly created domain object.
|
||||||
*/
|
*/
|
||||||
async function createDomainObjectWithDefaults(page, { type, name, parent = 'mine' }) {
|
async function createDomainObjectWithDefaults(page, { type, name, parent = 'mine' }) {
|
||||||
|
if (!name) {
|
||||||
|
name = `${type}:${genUuid()}`;
|
||||||
|
}
|
||||||
|
|
||||||
const parentUrl = await getHashUrlToDomainObject(page, parent);
|
const parentUrl = await getHashUrlToDomainObject(page, parent);
|
||||||
|
|
||||||
// Navigate to the parent object. This is necessary to create the object
|
// Navigate to the parent object. This is necessary to create the object
|
||||||
@@ -67,13 +80,18 @@ async function createDomainObjectWithDefaults(page, { type, name, parent = 'mine
|
|||||||
await page.click('button:has-text("Create")');
|
await page.click('button:has-text("Create")');
|
||||||
|
|
||||||
// Click the object specified by 'type'
|
// Click the object specified by 'type'
|
||||||
await page.click(`li:text("${type}")`);
|
await page.click(`li[role='menuitem']:text("${type}")`);
|
||||||
|
|
||||||
// Modify the name input field of the domain object to accept 'name'
|
// Modify the name input field of the domain object to accept 'name'
|
||||||
if (name) {
|
const nameInput = page.locator('form[name="mctForm"] .first input[type="text"]');
|
||||||
const nameInput = page.locator('form[name="mctForm"] .first input[type="text"]');
|
await nameInput.fill("");
|
||||||
await nameInput.fill("");
|
await nameInput.fill(name);
|
||||||
await nameInput.fill(name);
|
|
||||||
|
if (page.testNotes) {
|
||||||
|
// Fill the "Notes" section with information about the
|
||||||
|
// currently running test and its project.
|
||||||
|
const notesInput = page.locator('form[name="mctForm"] #notes-textarea');
|
||||||
|
await notesInput.fill(page.testNotes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Click OK button and wait for Navigate event
|
// Click OK button and wait for Navigate event
|
||||||
@@ -96,12 +114,31 @@ async function createDomainObjectWithDefaults(page, { type, name, parent = 'mine
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: name || `Unnamed ${type}`,
|
name,
|
||||||
uuid: uuid,
|
uuid,
|
||||||
url: objectUrl
|
url: objectUrl
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a notification with the given options.
|
||||||
|
* @param {import('@playwright/test').Page} page
|
||||||
|
* @param {CreateNotificationOptions} createNotificationOptions
|
||||||
|
*/
|
||||||
|
async function createNotification(page, createNotificationOptions) {
|
||||||
|
await page.evaluate((_createNotificationOptions) => {
|
||||||
|
const { message, severity, options } = _createNotificationOptions;
|
||||||
|
const notificationApi = window.openmct.notifications;
|
||||||
|
if (severity === 'info') {
|
||||||
|
notificationApi.info(message, options);
|
||||||
|
} else if (severity === 'alert') {
|
||||||
|
notificationApi.alert(message, options);
|
||||||
|
} else {
|
||||||
|
notificationApi.error(message, options);
|
||||||
|
}
|
||||||
|
}, createNotificationOptions);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {import('@playwright/test').Page} page
|
* @param {import('@playwright/test').Page} page
|
||||||
* @param {string} name
|
* @param {string} name
|
||||||
@@ -225,15 +262,14 @@ async function getHashUrlToDomainObject(page, uuid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilizes the OpenMCT API to detect if the given object has an active transaction (is in Edit mode).
|
* Utilizes the OpenMCT API to detect if the UI is in Edit mode.
|
||||||
* @private
|
* @private
|
||||||
* @param {import('@playwright/test').Page} page
|
* @param {import('@playwright/test').Page} page
|
||||||
* @param {string | import('../src/api/objects/ObjectAPI').Identifier} identifier
|
* @return {Promise<boolean>} true if the Open MCT is in Edit Mode
|
||||||
* @return {Promise<boolean>} true if the object has an active transaction, false otherwise
|
|
||||||
*/
|
*/
|
||||||
async function _isInEditMode(page, identifier) {
|
async function _isInEditMode(page, identifier) {
|
||||||
// eslint-disable-next-line no-return-await
|
// eslint-disable-next-line no-return-await
|
||||||
return await page.evaluate((objectIdentifier) => window.openmct.objects.isTransactionActive(objectIdentifier), identifier);
|
return await page.evaluate(() => window.openmct.editor.isEditing());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -324,6 +360,7 @@ async function setEndOffset(page, offset) {
|
|||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
module.exports = {
|
module.exports = {
|
||||||
createDomainObjectWithDefaults,
|
createDomainObjectWithDefaults,
|
||||||
|
createNotification,
|
||||||
expandTreePaneItemByName,
|
expandTreePaneItemByName,
|
||||||
createPlanFromJSON,
|
createPlanFromJSON,
|
||||||
openObjectTreeContextMenu,
|
openObjectTreeContextMenu,
|
||||||
|
|||||||
27
e2e/helper/addInitExampleUser.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* 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.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
// This should be used to install the Example User
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
const openmct = window.openmct;
|
||||||
|
openmct.install(openmct.plugins.example.ExampleUser());
|
||||||
|
});
|
||||||
76
e2e/helper/addInitFileInputObject.js
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
class DomainObjectViewProvider {
|
||||||
|
constructor(openmct) {
|
||||||
|
this.key = 'doViewProvider';
|
||||||
|
this.name = 'Domain Object View Provider';
|
||||||
|
this.openmct = openmct;
|
||||||
|
}
|
||||||
|
|
||||||
|
canView(domainObject) {
|
||||||
|
return domainObject.type === 'imageFileInput'
|
||||||
|
|| domainObject.type === 'jsonFileInput';
|
||||||
|
}
|
||||||
|
|
||||||
|
view(domainObject, objectPath) {
|
||||||
|
let content;
|
||||||
|
|
||||||
|
return {
|
||||||
|
show: function (element) {
|
||||||
|
const body = domainObject.selectFile.body;
|
||||||
|
const type = typeof body;
|
||||||
|
|
||||||
|
content = document.createElement('div');
|
||||||
|
content.id = 'file-input-type';
|
||||||
|
content.textContent = JSON.stringify(type);
|
||||||
|
element.appendChild(content);
|
||||||
|
},
|
||||||
|
destroy: function (element) {
|
||||||
|
element.removeChild(content);
|
||||||
|
content = undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
const openmct = window.openmct;
|
||||||
|
|
||||||
|
openmct.types.addType('jsonFileInput', {
|
||||||
|
key: 'jsonFileInput',
|
||||||
|
name: "JSON File Input Object",
|
||||||
|
creatable: true,
|
||||||
|
form: [
|
||||||
|
{
|
||||||
|
name: 'Upload File',
|
||||||
|
key: 'selectFile',
|
||||||
|
control: 'file-input',
|
||||||
|
required: true,
|
||||||
|
text: 'Select File...',
|
||||||
|
type: 'application/json',
|
||||||
|
property: [
|
||||||
|
"selectFile"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
openmct.types.addType('imageFileInput', {
|
||||||
|
key: 'imageFileInput',
|
||||||
|
name: "Image File Input Object",
|
||||||
|
creatable: true,
|
||||||
|
form: [
|
||||||
|
{
|
||||||
|
name: 'Upload File',
|
||||||
|
key: 'selectFile',
|
||||||
|
control: 'file-input',
|
||||||
|
required: true,
|
||||||
|
text: 'Select File...',
|
||||||
|
type: 'image/*',
|
||||||
|
property: [
|
||||||
|
"selectFile"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
openmct.objectViews.addProvider(new DomainObjectViewProvider(openmct));
|
||||||
|
});
|
||||||
27
e2e/helper/addInitOperatorStatus.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* 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.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
// This should be used to install the Operator Status
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
const openmct = window.openmct;
|
||||||
|
openmct.install(openmct.plugins.OperatorStatus());
|
||||||
|
});
|
||||||
@@ -20,6 +20,8 @@
|
|||||||
* at runtime from the About dialog for additional information.
|
* at runtime from the About dialog for additional information.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
|
const { createDomainObjectWithDefaults } = require('../appActions');
|
||||||
|
|
||||||
const NOTEBOOK_DROP_AREA = '.c-notebook__drag-area';
|
const NOTEBOOK_DROP_AREA = '.c-notebook__drag-area';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,24 +40,17 @@ async function enterTextEntry(page, text) {
|
|||||||
/**
|
/**
|
||||||
* @param {import('@playwright/test').Page} page
|
* @param {import('@playwright/test').Page} page
|
||||||
*/
|
*/
|
||||||
async function dragAndDropEmbed(page, myItemsFolderName) {
|
async function dragAndDropEmbed(page, notebookObject) {
|
||||||
// Click button:has-text("Create")
|
// Create example telemetry object
|
||||||
await page.locator('button:has-text("Create")').click();
|
const swg = await createDomainObjectWithDefaults(page, {
|
||||||
// Click li:has-text("Sine Wave Generator")
|
type: "Sine Wave Generator"
|
||||||
await page.locator('li:has-text("Sine Wave Generator")').click();
|
});
|
||||||
// Click form[name="mctForm"] >> text=My Items
|
// Navigate to notebook
|
||||||
await page.locator(`form[name="mctForm"] >> text=${myItemsFolderName}`).click();
|
await page.goto(notebookObject.url);
|
||||||
// Click text=OK
|
// Expand the tree to reveal the notebook
|
||||||
await page.locator('text=OK').click();
|
await page.click('button[title="Show selected item in tree"]');
|
||||||
// Click text=Open MCT My Items >> span >> nth=3
|
// Drag and drop the SWG into the notebook
|
||||||
await page.locator(`text=Open MCT ${myItemsFolderName} >> span`).nth(3).click();
|
await page.dragAndDrop(`text=${swg.name}`, NOTEBOOK_DROP_AREA);
|
||||||
// Click text=Unnamed CUSTOM_NAME
|
|
||||||
await Promise.all([
|
|
||||||
page.waitForNavigation(),
|
|
||||||
page.locator('text=Unnamed CUSTOM_NAME').click()
|
|
||||||
]);
|
|
||||||
|
|
||||||
await page.dragAndDrop('text=UNNAMED SINE WAVE GENERATOR', NOTEBOOK_DROP_AREA);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
|
|||||||
@@ -126,13 +126,21 @@ exports.test = test.extend({
|
|||||||
// This should follow in the Project's configuration. Can be set to 'snow' in playwright config.js
|
// This should follow in the Project's configuration. Can be set to 'snow' in playwright config.js
|
||||||
theme: [theme, { option: true }],
|
theme: [theme, { option: true }],
|
||||||
// eslint-disable-next-line no-shadow
|
// eslint-disable-next-line no-shadow
|
||||||
page: async ({ page, theme }, use) => {
|
page: async ({ page, theme }, use, testInfo) => {
|
||||||
// eslint-disable-next-line playwright/no-conditional-in-test
|
// eslint-disable-next-line playwright/no-conditional-in-test
|
||||||
if (theme === 'snow') {
|
if (theme === 'snow') {
|
||||||
//inject snow theme
|
//inject snow theme
|
||||||
await page.addInitScript({ path: path.join(__dirname, './helper', './useSnowTheme.js') });
|
await page.addInitScript({ path: path.join(__dirname, './helper', './useSnowTheme.js') });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Attach info about the currently running test and its project.
|
||||||
|
// This will be used by appActions to fill in the created
|
||||||
|
// domain object's notes.
|
||||||
|
page.testNotes = [
|
||||||
|
`${testInfo.titlePath.join('\n')}`,
|
||||||
|
`${testInfo.project.name}`
|
||||||
|
].join('\n');
|
||||||
|
|
||||||
await use(page);
|
await use(page);
|
||||||
},
|
},
|
||||||
myItemsFolderName: [myItemsFolderName, { option: true }],
|
myItemsFolderName: [myItemsFolderName, { option: true }],
|
||||||
@@ -140,22 +148,5 @@ exports.test = test.extend({
|
|||||||
openmctConfig: async ({ myItemsFolderName }, use) => {
|
openmctConfig: async ({ myItemsFolderName }, use) => {
|
||||||
await use({ myItemsFolderName });
|
await use({ myItemsFolderName });
|
||||||
}
|
}
|
||||||
// objectCreateOptions: [objectCreateOptions, {option: true}],
|
|
||||||
// eslint-disable-next-line no-shadow
|
|
||||||
// domainObject: [async ({ page, objectCreateOptions }, use) => {
|
|
||||||
// // FIXME: This is a false-positive caused by a bug in the eslint-plugin-playwright rule.
|
|
||||||
// // eslint-disable-next-line playwright/no-conditional-in-test
|
|
||||||
// if (objectCreateOptions === null) {
|
|
||||||
// await use(page);
|
|
||||||
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// //Go to baseURL
|
|
||||||
// await page.goto('./', { waitUntil: 'networkidle' });
|
|
||||||
|
|
||||||
// const uuid = await getOrCreateDomainObject(page, objectCreateOptions);
|
|
||||||
// await use({ uuid });
|
|
||||||
// }, { auto: true }]
|
|
||||||
});
|
});
|
||||||
exports.expect = expect;
|
exports.expect = expect;
|
||||||
|
|||||||
2207
e2e/test-data/ExampleLayouts.json
Normal file
BIN
e2e/test-data/rick.jpg
Normal file
|
After Width: | Height: | Size: 10 KiB |
@@ -20,8 +20,8 @@
|
|||||||
* at runtime from the About dialog for additional information.
|
* at runtime from the About dialog for additional information.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
const { test, expect } = require('../../baseFixtures.js');
|
const { test, expect } = require('../../pluginFixtures.js');
|
||||||
const { createDomainObjectWithDefaults } = require('../../appActions.js');
|
const { createDomainObjectWithDefaults, createNotification } = require('../../appActions.js');
|
||||||
|
|
||||||
test.describe('AppActions', () => {
|
test.describe('AppActions', () => {
|
||||||
test('createDomainObjectsWithDefaults', async ({ page }) => {
|
test('createDomainObjectsWithDefaults', async ({ page }) => {
|
||||||
@@ -49,12 +49,12 @@ test.describe('AppActions', () => {
|
|||||||
parent: e2eFolder.uuid
|
parent: e2eFolder.uuid
|
||||||
});
|
});
|
||||||
|
|
||||||
await page.goto(timer1.url, { waitUntil: 'networkidle' });
|
await page.goto(timer1.url);
|
||||||
await expect(page.locator('.l-browse-bar__object-name')).toHaveText('Timer Foo');
|
await expect(page.locator('.l-browse-bar__object-name')).toHaveText(timer1.name);
|
||||||
await page.goto(timer2.url, { waitUntil: 'networkidle' });
|
await page.goto(timer2.url);
|
||||||
await expect(page.locator('.l-browse-bar__object-name')).toHaveText('Timer Bar');
|
await expect(page.locator('.l-browse-bar__object-name')).toHaveText(timer2.name);
|
||||||
await page.goto(timer3.url, { waitUntil: 'networkidle' });
|
await page.goto(timer3.url);
|
||||||
await expect(page.locator('.l-browse-bar__object-name')).toHaveText('Timer Baz');
|
await expect(page.locator('.l-browse-bar__object-name')).toHaveText(timer3.name);
|
||||||
});
|
});
|
||||||
|
|
||||||
await test.step('Create multiple nested objects in a row', async () => {
|
await test.step('Create multiple nested objects in a row', async () => {
|
||||||
@@ -73,16 +73,40 @@ test.describe('AppActions', () => {
|
|||||||
name: 'Folder Baz',
|
name: 'Folder Baz',
|
||||||
parent: folder2.uuid
|
parent: folder2.uuid
|
||||||
});
|
});
|
||||||
await page.goto(folder1.url, { waitUntil: 'networkidle' });
|
await page.goto(folder1.url);
|
||||||
await expect(page.locator('.l-browse-bar__object-name')).toHaveText('Folder Foo');
|
await expect(page.locator('.l-browse-bar__object-name')).toHaveText(folder1.name);
|
||||||
await page.goto(folder2.url, { waitUntil: 'networkidle' });
|
await page.goto(folder2.url);
|
||||||
await expect(page.locator('.l-browse-bar__object-name')).toHaveText('Folder Bar');
|
await expect(page.locator('.l-browse-bar__object-name')).toHaveText(folder2.name);
|
||||||
await page.goto(folder3.url, { waitUntil: 'networkidle' });
|
await page.goto(folder3.url);
|
||||||
await expect(page.locator('.l-browse-bar__object-name')).toHaveText('Folder Baz');
|
await expect(page.locator('.l-browse-bar__object-name')).toHaveText(folder3.name);
|
||||||
|
|
||||||
expect(folder1.url).toBe(`${e2eFolder.url}/${folder1.uuid}`);
|
expect(folder1.url).toBe(`${e2eFolder.url}/${folder1.uuid}`);
|
||||||
expect(folder2.url).toBe(`${e2eFolder.url}/${folder1.uuid}/${folder2.uuid}`);
|
expect(folder2.url).toBe(`${e2eFolder.url}/${folder1.uuid}/${folder2.uuid}`);
|
||||||
expect(folder3.url).toBe(`${e2eFolder.url}/${folder1.uuid}/${folder2.uuid}/${folder3.uuid}`);
|
expect(folder3.url).toBe(`${e2eFolder.url}/${folder1.uuid}/${folder2.uuid}/${folder3.uuid}`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
test("createNotification", async ({ page }) => {
|
||||||
|
await page.goto('./', { waitUntil: 'networkidle' });
|
||||||
|
await createNotification(page, {
|
||||||
|
message: 'Test info notification',
|
||||||
|
severity: 'info'
|
||||||
|
});
|
||||||
|
await expect(page.locator('.c-message-banner__message')).toHaveText('Test info notification');
|
||||||
|
await expect(page.locator('.c-message-banner')).toHaveClass(/info/);
|
||||||
|
await page.locator('[aria-label="Dismiss"]').click();
|
||||||
|
await createNotification(page, {
|
||||||
|
message: 'Test alert notification',
|
||||||
|
severity: 'alert'
|
||||||
|
});
|
||||||
|
await expect(page.locator('.c-message-banner__message')).toHaveText('Test alert notification');
|
||||||
|
await expect(page.locator('.c-message-banner')).toHaveClass(/alert/);
|
||||||
|
await page.locator('[aria-label="Dismiss"]').click();
|
||||||
|
await createNotification(page, {
|
||||||
|
message: 'Test error notification',
|
||||||
|
severity: 'error'
|
||||||
|
});
|
||||||
|
await expect(page.locator('.c-message-banner__message')).toHaveText('Test error notification');
|
||||||
|
await expect(page.locator('.c-message-banner')).toHaveClass(/error/);
|
||||||
|
await page.locator('[aria-label="Dismiss"]').click();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Structure: Some standard Imports. Please update the required pathing.
|
// Structure: Some standard Imports. Please update the required pathing.
|
||||||
const { test, expect } = require('../../baseFixtures');
|
const { test, expect } = require('../../pluginFixtures');
|
||||||
const { createDomainObjectWithDefaults } = require('../../appActions');
|
const { createDomainObjectWithDefaults } = require('../../appActions');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -144,5 +144,5 @@ async function renameTimerFrom3DotMenu(page, timerUrl, newNameForTimer) {
|
|||||||
await page.locator('text=Properties Title Notes >> input[type="text"]').fill(newNameForTimer);
|
await page.locator('text=Properties Title Notes >> input[type="text"]').fill(newNameForTimer);
|
||||||
|
|
||||||
// Click Ok button to Save
|
// Click Ok button to Save
|
||||||
await page.locator('text=OK').click();
|
await page.locator('button:has-text("OK")').click();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,14 +43,14 @@ test('Generate Visual Test Data @localStorage', async ({ page, context }) => {
|
|||||||
await page.locator('button:has-text("Create")').click();
|
await page.locator('button:has-text("Create")').click();
|
||||||
|
|
||||||
// add sine wave generator with defaults
|
// add sine wave generator with defaults
|
||||||
await page.locator('li:has-text("Sine Wave Generator")').click();
|
await page.locator('li[role="menuitem"]:has-text("Sine Wave Generator")').click();
|
||||||
|
|
||||||
//Add a 5000 ms Delay
|
//Add a 5000 ms Delay
|
||||||
await page.locator('[aria-label="Loading Delay \\(ms\\)"]').fill('5000');
|
await page.locator('[aria-label="Loading Delay \\(ms\\)"]').fill('5000');
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
page.waitForNavigation(),
|
page.waitForNavigation(),
|
||||||
page.locator('text=OK').click(),
|
page.locator('button:has-text("OK")').click(),
|
||||||
//Wait for Save Banner to appear
|
//Wait for Save Banner to appear
|
||||||
page.waitForSelector('.c-message-banner__message')
|
page.waitForSelector('.c-message-banner__message')
|
||||||
]);
|
]);
|
||||||
@@ -58,7 +58,7 @@ test('Generate Visual Test Data @localStorage', async ({ page, context }) => {
|
|||||||
// focus the overlay plot
|
// focus the overlay plot
|
||||||
await page.goto(overlayPlot.url);
|
await page.goto(overlayPlot.url);
|
||||||
|
|
||||||
await expect(page.locator('.l-browse-bar__object-name')).toContainText('Unnamed Overlay Plot');
|
await expect(page.locator('.l-browse-bar__object-name')).toContainText(overlayPlot.name);
|
||||||
//Save localStorage for future test execution
|
//Save localStorage for future test execution
|
||||||
await context.storageState({ path: './e2e/test-data/VisualTestData_storage.json' });
|
await context.storageState({ path: './e2e/test-data/VisualTestData_storage.json' });
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -25,9 +25,9 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const { test, expect } = require('../../baseFixtures');
|
const { test, expect } = require('../../pluginFixtures');
|
||||||
|
|
||||||
test.describe("CouchDB Status Indicator @couchdb", () => {
|
test.describe("CouchDB Status Indicator with mocked responses @couchdb", () => {
|
||||||
test.use({ failOnConsoleError: false });
|
test.use({ failOnConsoleError: false });
|
||||||
//TODO BeforeAll Verify CouchDB Connectivity with APIContext
|
//TODO BeforeAll Verify CouchDB Connectivity with APIContext
|
||||||
test('Shows green if connected', async ({ page }) => {
|
test('Shows green if connected', async ({ page }) => {
|
||||||
@@ -71,38 +71,41 @@ test.describe("CouchDB Status Indicator @couchdb", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test.describe("CouchDB initialization @couchdb", () => {
|
test.describe("CouchDB initialization with mocked responses @couchdb", () => {
|
||||||
test.use({ failOnConsoleError: false });
|
test.use({ failOnConsoleError: false });
|
||||||
test("'My Items' folder is created if it doesn't exist", async ({ page }) => {
|
test("'My Items' folder is created if it doesn't exist", async ({ page }) => {
|
||||||
// Store any relevant PUT requests that happen on the page
|
const mockedMissingObjectResponsefromCouchDB = {
|
||||||
const createMineFolderRequests = [];
|
status: 404,
|
||||||
page.on('request', req => {
|
contentType: 'application/json',
|
||||||
// eslint-disable-next-line playwright/no-conditional-in-test
|
body: JSON.stringify({})
|
||||||
if (req.method() === 'PUT' && req.url().endsWith('openmct/mine')) {
|
};
|
||||||
createMineFolderRequests.push(req);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Override the first request to GET openmct/mine to return a 404
|
// Override the first request to GET openmct/mine to return a 404.
|
||||||
await page.route('**/openmct/mine', route => {
|
// This simulates the case of starting Open MCT with a fresh database
|
||||||
route.fulfill({
|
// and no "My Items" folder created yet.
|
||||||
status: 404,
|
await page.route('**/mine', route => {
|
||||||
contentType: 'application/json',
|
route.fulfill(mockedMissingObjectResponsefromCouchDB);
|
||||||
body: JSON.stringify({})
|
|
||||||
});
|
|
||||||
}, { times: 1 });
|
}, { times: 1 });
|
||||||
|
|
||||||
// Go to baseURL
|
// Set up promise to verify that a PUT request to create "My Items"
|
||||||
|
// folder was made.
|
||||||
|
const putMineFolderRequest = page.waitForRequest(req =>
|
||||||
|
req.url().endsWith('/mine')
|
||||||
|
&& req.method() === 'PUT');
|
||||||
|
|
||||||
|
// Set up promise to verify that a GET request to retrieve "My Items"
|
||||||
|
// folder was made.
|
||||||
|
const getMineFolderRequest = page.waitForRequest(req =>
|
||||||
|
req.url().endsWith('/mine')
|
||||||
|
&& req.method() === 'GET');
|
||||||
|
|
||||||
|
// Go to baseURL.
|
||||||
await page.goto('./', { waitUntil: 'networkidle' });
|
await page.goto('./', { waitUntil: 'networkidle' });
|
||||||
|
|
||||||
// Verify that error banner is displayed
|
// Wait for both requests to resolve.
|
||||||
const bannerMessage = await page.locator('.c-message-banner__message').innerText();
|
await Promise.all([
|
||||||
expect(bannerMessage).toEqual('Failed to retrieve object mine');
|
putMineFolderRequest,
|
||||||
|
getMineFolderRequest
|
||||||
// Verify that a PUT request to create "My Items" folder was made
|
]);
|
||||||
await expect.poll(() => createMineFolderRequests.length, {
|
|
||||||
message: 'Verify that PUT request to create "mine" folder was made',
|
|
||||||
timeout: 1000
|
|
||||||
}).toBeGreaterThanOrEqual(1);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
This test suite is dedicated to tests which verify the basic operations surrounding the example event generator.
|
This test suite is dedicated to tests which verify the basic operations surrounding the example event generator.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const { test, expect } = require('../../../baseFixtures');
|
const { test, expect } = require('../../../pluginFixtures');
|
||||||
const { createDomainObjectWithDefaults } = require('../../../appActions');
|
const { createDomainObjectWithDefaults } = require('../../../appActions');
|
||||||
|
|
||||||
test.describe('Example Event Generator CRUD Operations', () => {
|
test.describe('Example Event Generator CRUD Operations', () => {
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ test.describe('Sine Wave Generator', () => {
|
|||||||
//Click text=OK
|
//Click text=OK
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
page.waitForNavigation(),
|
page.waitForNavigation(),
|
||||||
page.click('text=OK')
|
page.click('button:has-text("OK")')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Verify that the Sine Wave Generator is displayed and correct
|
// Verify that the Sine Wave Generator is displayed and correct
|
||||||
|
|||||||
@@ -24,10 +24,14 @@
|
|||||||
This test suite is dedicated to tests which verify form functionality in isolation
|
This test suite is dedicated to tests which verify form functionality in isolation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const { test, expect } = require('../../baseFixtures');
|
const { test, expect } = require('../../pluginFixtures');
|
||||||
|
const { createDomainObjectWithDefaults } = require('../../appActions');
|
||||||
|
const genUuid = require('uuid').v4;
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const TEST_FOLDER = 'test folder';
|
const TEST_FOLDER = 'test folder';
|
||||||
|
const jsonFilePath = 'e2e/test-data/ExampleLayouts.json';
|
||||||
|
const imageFilePath = 'e2e/test-data/rick.jpg';
|
||||||
|
|
||||||
test.describe('Form Validation Behavior', () => {
|
test.describe('Form Validation Behavior', () => {
|
||||||
test('Required Field indicators appear if title is empty and can be corrected', async ({ page }) => {
|
test('Required Field indicators appear if title is empty and can be corrected', async ({ page }) => {
|
||||||
@@ -43,7 +47,7 @@ test.describe('Form Validation Behavior', () => {
|
|||||||
await page.press('text=Properties Title Notes >> input[type="text"]', 'Tab');
|
await page.press('text=Properties Title Notes >> input[type="text"]', 'Tab');
|
||||||
|
|
||||||
//Required Field Form Validation
|
//Required Field Form Validation
|
||||||
await expect(page.locator('text=OK')).toBeDisabled();
|
await expect(page.locator('button:has-text("OK")')).toBeDisabled();
|
||||||
await expect(page.locator('.c-form-row__state-indicator').first()).toHaveClass(/invalid/);
|
await expect(page.locator('.c-form-row__state-indicator').first()).toHaveClass(/invalid/);
|
||||||
|
|
||||||
//Correct Form Validation for missing title and trigger validation with 'Tab'
|
//Correct Form Validation for missing title and trigger validation with 'Tab'
|
||||||
@@ -52,13 +56,13 @@ test.describe('Form Validation Behavior', () => {
|
|||||||
await page.press('text=Properties Title Notes >> input[type="text"]', 'Tab');
|
await page.press('text=Properties Title Notes >> input[type="text"]', 'Tab');
|
||||||
|
|
||||||
//Required Field Form Validation is corrected
|
//Required Field Form Validation is corrected
|
||||||
await expect(page.locator('text=OK')).toBeEnabled();
|
await expect(page.locator('button:has-text("OK")')).toBeEnabled();
|
||||||
await expect(page.locator('.c-form-row__state-indicator').first()).not.toHaveClass(/invalid/);
|
await expect(page.locator('.c-form-row__state-indicator').first()).not.toHaveClass(/invalid/);
|
||||||
|
|
||||||
//Finish Creating Domain Object
|
//Finish Creating Domain Object
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
page.waitForNavigation(),
|
page.waitForNavigation(),
|
||||||
page.click('text=OK')
|
page.click('button:has-text("OK")')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
//Verify that the Domain Object has been created with the corrected title property
|
//Verify that the Domain Object has been created with the corrected title property
|
||||||
@@ -66,6 +70,41 @@ test.describe('Form Validation Behavior', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test.describe('Form File Input Behavior', () => {
|
||||||
|
test.beforeEach(async ({ page }) => {
|
||||||
|
// eslint-disable-next-line no-undef
|
||||||
|
await page.addInitScript({ path: path.join(__dirname, '../../helper', 'addInitFileInputObject.js') });
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Can select a JSON file type', async ({ page }) => {
|
||||||
|
await page.goto('./', { waitUntil: 'networkidle' });
|
||||||
|
|
||||||
|
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 }) => {
|
||||||
|
await page.goto('./', { waitUntil: 'networkidle' });
|
||||||
|
|
||||||
|
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"`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test.describe('Persistence operations @addInit', () => {
|
test.describe('Persistence operations @addInit', () => {
|
||||||
// add non persistable root item
|
// add non persistable root item
|
||||||
test.beforeEach(async ({ page }) => {
|
test.beforeEach(async ({ page }) => {
|
||||||
@@ -91,6 +130,146 @@ test.describe('Persistence operations @addInit', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test.describe('Persistence operations @couchdb', () => {
|
||||||
|
test.use({ failOnConsoleError: false });
|
||||||
|
test('Editing object properties should generate a single persistence operation', async ({ page }) => {
|
||||||
|
test.info().annotations.push({
|
||||||
|
type: 'issue',
|
||||||
|
description: 'https://github.com/nasa/openmct/issues/5616'
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.goto('./', { waitUntil: 'networkidle' });
|
||||||
|
|
||||||
|
// Create a new 'Clock' object with default settings
|
||||||
|
const clock = await createDomainObjectWithDefaults(page, {
|
||||||
|
type: 'Clock'
|
||||||
|
});
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Open the edit form for the clock object
|
||||||
|
await page.click('button[title="More options"]');
|
||||||
|
await page.click('li[title="Edit properties of this object."]');
|
||||||
|
|
||||||
|
// 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"]');
|
||||||
|
|
||||||
|
await expect.poll(() => putRequestCount, {
|
||||||
|
message: 'Verify a single PUT request was made to persist the object',
|
||||||
|
timeout: 1000
|
||||||
|
}).toEqual(1);
|
||||||
|
});
|
||||||
|
test('Can create an object after a conflict error @couchdb @2p', async ({ page }) => {
|
||||||
|
test.info().annotations.push({
|
||||||
|
type: 'issue',
|
||||||
|
description: 'https://github.com/nasa/openmct/issues/5982'
|
||||||
|
});
|
||||||
|
|
||||||
|
const page2 = await page.context().newPage();
|
||||||
|
|
||||||
|
// Both pages: Go to baseURL
|
||||||
|
await Promise.all([
|
||||||
|
page.goto('./', { waitUntil: 'networkidle' }),
|
||||||
|
page2.goto('./', { waitUntil: 'networkidle' })
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Both pages: Click the Create button
|
||||||
|
await Promise.all([
|
||||||
|
page.click('button:has-text("Create")'),
|
||||||
|
page2.click('button:has-text("Create")')
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 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")`)
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 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"]');
|
||||||
|
|
||||||
|
// Both pages: Fill in the 'Name' form field.
|
||||||
|
await Promise.all([
|
||||||
|
nameInput.fill(""),
|
||||||
|
nameInput.fill(`Clock:${genUuid()}`),
|
||||||
|
nameInput2.fill(""),
|
||||||
|
nameInput2.fill(`Clock:${genUuid()}`)
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 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')
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Close Page 2, we're done with it.
|
||||||
|
await page2.close();
|
||||||
|
|
||||||
|
// 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')
|
||||||
|
]);
|
||||||
|
|
||||||
|
// 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"
|
||||||
|
})).toBeVisible();
|
||||||
|
|
||||||
|
// Page 1: Start logging console errors from this point on
|
||||||
|
let errors = [];
|
||||||
|
page.on('console', (msg) => {
|
||||||
|
if (msg.type() === 'error') {
|
||||||
|
errors.push(msg.text());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Page 1: Try to create a clock with the page that received the conflict.
|
||||||
|
const clockAfterConflict = await createDomainObjectWithDefaults(page, {
|
||||||
|
type: 'Clock'
|
||||||
|
});
|
||||||
|
|
||||||
|
// Page 1: Wait for save progress dialog to appear/disappear
|
||||||
|
await page.locator('.c-message-banner__message', {
|
||||||
|
hasText: 'Do not navigate away from this page or close this browser tab while this message is displayed.',
|
||||||
|
state: 'visible'
|
||||||
|
}).waitFor({ state: 'hidden' });
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
// Verify no console errors occurred
|
||||||
|
expect(errors).toHaveLength(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test.describe('Form Correctness by Object Type', () => {
|
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 (SWG)', async ({page}) => {});
|
||||||
test.fixme('Verify correct behavior of number object Timer', async ({page}) => {});
|
test.fixme('Verify correct behavior of number object Timer', async ({page}) => {});
|
||||||
|
|||||||
@@ -43,48 +43,76 @@ test.describe('Move & link item tests', () => {
|
|||||||
name: 'Child Folder',
|
name: 'Child Folder',
|
||||||
parent: parentFolder.uuid
|
parent: parentFolder.uuid
|
||||||
});
|
});
|
||||||
await createDomainObjectWithDefaults(page, {
|
const grandchildFolder = await createDomainObjectWithDefaults(page, {
|
||||||
type: 'Folder',
|
type: 'Folder',
|
||||||
name: 'Grandchild Folder',
|
name: 'Grandchild Folder',
|
||||||
parent: childFolder.uuid
|
parent: childFolder.uuid
|
||||||
});
|
});
|
||||||
|
|
||||||
// Attempt to move parent to its own grandparent
|
// Attempt to move parent to its own grandparent
|
||||||
await page.locator(`text=Open MCT ${myItemsFolderName} >> span`).nth(3).click();
|
await page.locator('button[title="Show selected item in tree"]').click();
|
||||||
await page.locator('.c-disclosure-triangle >> nth=0').click();
|
|
||||||
|
|
||||||
await page.locator(`a:has-text("Parent Folder") >> nth=0`).click({
|
const treePane = page.locator('#tree-pane');
|
||||||
|
await treePane.getByRole('treeitem', {
|
||||||
|
name: 'Parent Folder'
|
||||||
|
}).click({
|
||||||
button: 'right'
|
button: 'right'
|
||||||
});
|
});
|
||||||
|
|
||||||
await page.locator('li.icon-move').click();
|
await page.getByRole('menuitem', {
|
||||||
await page.locator('form[name="mctForm"] >> .c-disclosure-triangle >> nth=0').click();
|
name: /Move/
|
||||||
await page.locator('form[name="mctForm"] >> text=Parent Folder').click();
|
}).click();
|
||||||
|
|
||||||
|
const locatorTree = page.locator('#locator-tree');
|
||||||
|
const myItemsLocatorTreeItem = locatorTree.getByRole('treeitem', {
|
||||||
|
name: myItemsFolderName
|
||||||
|
});
|
||||||
|
await myItemsLocatorTreeItem.locator('.c-disclosure-triangle').click();
|
||||||
|
await myItemsLocatorTreeItem.click();
|
||||||
|
|
||||||
|
const parentFolderLocatorTreeItem = locatorTree.getByRole('treeitem', {
|
||||||
|
name: parentFolder.name
|
||||||
|
});
|
||||||
|
await parentFolderLocatorTreeItem.locator('.c-disclosure-triangle').click();
|
||||||
|
await parentFolderLocatorTreeItem.click();
|
||||||
await expect(page.locator('[aria-label="Save"]')).toBeDisabled();
|
await expect(page.locator('[aria-label="Save"]')).toBeDisabled();
|
||||||
await page.locator('form[name="mctForm"] >> .c-disclosure-triangle >> nth=1').click();
|
|
||||||
await page.locator('form[name="mctForm"] >> text=Child Folder').click();
|
const childFolderLocatorTreeItem = locatorTree.getByRole('treeitem', {
|
||||||
|
name: new RegExp(childFolder.name)
|
||||||
|
});
|
||||||
|
await childFolderLocatorTreeItem.locator('.c-disclosure-triangle').click();
|
||||||
|
await childFolderLocatorTreeItem.click();
|
||||||
await expect(page.locator('[aria-label="Save"]')).toBeDisabled();
|
await expect(page.locator('[aria-label="Save"]')).toBeDisabled();
|
||||||
await page.locator('form[name="mctForm"] >> .c-disclosure-triangle >> nth=2').click();
|
|
||||||
await page.locator('form[name="mctForm"] >> text=Grandchild Folder').click();
|
const grandchildFolderLocatorTreeItem = locatorTree.getByRole('treeitem', {
|
||||||
|
name: grandchildFolder.name
|
||||||
|
});
|
||||||
|
await grandchildFolderLocatorTreeItem.locator('.c-disclosure-triangle').click();
|
||||||
|
await grandchildFolderLocatorTreeItem.click();
|
||||||
await expect(page.locator('[aria-label="Save"]')).toBeDisabled();
|
await expect(page.locator('[aria-label="Save"]')).toBeDisabled();
|
||||||
await page.locator('form[name="mctForm"] >> text=Parent Folder').click();
|
|
||||||
|
await parentFolderLocatorTreeItem.click();
|
||||||
await expect(page.locator('[aria-label="Save"]')).toBeDisabled();
|
await expect(page.locator('[aria-label="Save"]')).toBeDisabled();
|
||||||
await page.locator('[aria-label="Cancel"]').click();
|
await page.locator('[aria-label="Cancel"]').click();
|
||||||
|
|
||||||
// Move Child Folder from Parent Folder to My Items
|
// Move Child Folder from Parent Folder to My Items
|
||||||
await page.locator('.c-disclosure-triangle >> nth=0').click();
|
await treePane.getByRole('treeitem', {
|
||||||
await page.locator('.c-disclosure-triangle >> nth=1').click();
|
name: new RegExp(childFolder.name)
|
||||||
|
}).click({
|
||||||
await page.locator(`a:has-text("Child Folder") >> nth=0`).click({
|
|
||||||
button: 'right'
|
button: 'right'
|
||||||
});
|
});
|
||||||
await page.locator('li.icon-move').click();
|
await page.getByRole('menuitem', {
|
||||||
await page.locator(`form[name="mctForm"] >> text=${myItemsFolderName}`).click();
|
name: /Move/
|
||||||
|
}).click();
|
||||||
|
await myItemsLocatorTreeItem.click();
|
||||||
|
|
||||||
await page.locator('text=OK').click();
|
await page.locator('[aria-label="Save"]').click();
|
||||||
|
const myItemsPaneTreeItem = treePane.getByRole('treeitem', {
|
||||||
|
name: myItemsFolderName
|
||||||
|
});
|
||||||
|
|
||||||
// Expect that Child Folder is in My Items, the root folder
|
// Expect that Child Folder is in My Items, the root folder
|
||||||
expect(page.locator(`text=${myItemsFolderName} >> nth=0:has(text=Child Folder)`)).toBeTruthy();
|
expect(myItemsPaneTreeItem.locator('nth=0:has(text=Child Folder)')).toBeTruthy();
|
||||||
});
|
});
|
||||||
test('Create a basic object and verify that it cannot be moved to telemetry object without Composition Provider', async ({ page, openmctConfig }) => {
|
test('Create a basic object and verify that it cannot be moved to telemetry object without Composition Provider', async ({ page, openmctConfig }) => {
|
||||||
const { myItemsFolderName } = openmctConfig;
|
const { myItemsFolderName } = openmctConfig;
|
||||||
@@ -95,11 +123,11 @@ test.describe('Move & link item tests', () => {
|
|||||||
// Create Telemetry Table
|
// Create Telemetry Table
|
||||||
let telemetryTable = 'Test Telemetry Table';
|
let telemetryTable = 'Test Telemetry Table';
|
||||||
await page.locator('button:has-text("Create")').click();
|
await page.locator('button:has-text("Create")').click();
|
||||||
await page.locator('li:has-text("Telemetry Table")').click();
|
await page.locator('li[role="menuitem"]:has-text("Telemetry Table")').click();
|
||||||
await page.locator('text=Properties Title Notes >> input[type="text"]').click();
|
await page.locator('text=Properties Title Notes >> input[type="text"]').click();
|
||||||
await page.locator('text=Properties Title Notes >> input[type="text"]').fill(telemetryTable);
|
await page.locator('text=Properties Title Notes >> input[type="text"]').fill(telemetryTable);
|
||||||
|
|
||||||
await page.locator('text=OK').click();
|
await page.locator('button:has-text("OK")').click();
|
||||||
|
|
||||||
// Finish editing and save Telemetry Table
|
// Finish editing and save Telemetry Table
|
||||||
await page.locator('.c-button--menu.c-button--major.icon-save').click();
|
await page.locator('.c-button--menu.c-button--major.icon-save').click();
|
||||||
@@ -108,19 +136,19 @@ test.describe('Move & link item tests', () => {
|
|||||||
// Create New Folder Basic Domain Object
|
// Create New Folder Basic Domain Object
|
||||||
let folder = 'Test Folder';
|
let folder = 'Test Folder';
|
||||||
await page.locator('button:has-text("Create")').click();
|
await page.locator('button:has-text("Create")').click();
|
||||||
await page.locator('li:has-text("Folder")').click();
|
await page.locator('li[role="menuitem"]:has-text("Folder")').click();
|
||||||
await page.locator('text=Properties Title Notes >> input[type="text"]').click();
|
await page.locator('text=Properties Title Notes >> input[type="text"]').click();
|
||||||
await page.locator('text=Properties Title Notes >> input[type="text"]').fill(folder);
|
await page.locator('text=Properties Title Notes >> input[type="text"]').fill(folder);
|
||||||
|
|
||||||
// See if it's possible to put the folder in the Telemetry object during creation (Soft Assert)
|
// See if it's possible to put the folder in the Telemetry object during creation (Soft Assert)
|
||||||
await page.locator(`form[name="mctForm"] >> text=${telemetryTable}`).click();
|
await page.locator(`form[name="mctForm"] >> text=${telemetryTable}`).click();
|
||||||
let okButton = await page.locator('button.c-button.c-button--major:has-text("OK")');
|
let okButton = page.locator('button.c-button.c-button--major:has-text("OK")');
|
||||||
let okButtonStateDisabled = await okButton.isDisabled();
|
let okButtonStateDisabled = await okButton.isDisabled();
|
||||||
expect.soft(okButtonStateDisabled).toBeTruthy();
|
expect.soft(okButtonStateDisabled).toBeTruthy();
|
||||||
|
|
||||||
// Continue test regardless of assertion and create it in My Items
|
// Continue test regardless of assertion and create it in My Items
|
||||||
await page.locator(`form[name="mctForm"] >> text=${myItemsFolderName}`).click();
|
await page.locator(`form[name="mctForm"] >> text=${myItemsFolderName}`).click();
|
||||||
await page.locator('text=OK').click();
|
await page.locator('button:has-text("OK")').click();
|
||||||
|
|
||||||
// Open My Items
|
// Open My Items
|
||||||
await page.locator(`text=Open MCT ${myItemsFolderName} >> span`).nth(3).click();
|
await page.locator(`text=Open MCT ${myItemsFolderName} >> span`).nth(3).click();
|
||||||
@@ -138,7 +166,7 @@ test.describe('Move & link item tests', () => {
|
|||||||
// See if it's possible to put the folder in the Telemetry object after creation
|
// See if it's possible to put the folder in the Telemetry object after creation
|
||||||
await page.locator(`text=Location Open MCT ${myItemsFolderName} >> span`).nth(3).click();
|
await page.locator(`text=Location Open MCT ${myItemsFolderName} >> span`).nth(3).click();
|
||||||
await page.locator(`form[name="mctForm"] >> text=${telemetryTable}`).click();
|
await page.locator(`form[name="mctForm"] >> text=${telemetryTable}`).click();
|
||||||
let okButton2 = await page.locator('button.c-button.c-button--major:has-text("OK")');
|
let okButton2 = page.locator('button.c-button.c-button--major:has-text("OK")');
|
||||||
let okButtonStateDisabled2 = await okButton2.isDisabled();
|
let okButtonStateDisabled2 = await okButton2.isDisabled();
|
||||||
expect(okButtonStateDisabled2).toBeTruthy();
|
expect(okButtonStateDisabled2).toBeTruthy();
|
||||||
});
|
});
|
||||||
@@ -158,48 +186,76 @@ test.describe('Move & link item tests', () => {
|
|||||||
name: 'Child Folder',
|
name: 'Child Folder',
|
||||||
parent: parentFolder.uuid
|
parent: parentFolder.uuid
|
||||||
});
|
});
|
||||||
await createDomainObjectWithDefaults(page, {
|
const grandchildFolder = await createDomainObjectWithDefaults(page, {
|
||||||
type: 'Folder',
|
type: 'Folder',
|
||||||
name: 'Grandchild Folder',
|
name: 'Grandchild Folder',
|
||||||
parent: childFolder.uuid
|
parent: childFolder.uuid
|
||||||
});
|
});
|
||||||
|
|
||||||
// Attempt to link parent to its own grandparent
|
// Attempt to move parent to its own grandparent
|
||||||
await page.locator(`text=Open MCT ${myItemsFolderName} >> span`).nth(3).click();
|
await page.locator('button[title="Show selected item in tree"]').click();
|
||||||
await page.locator('.c-disclosure-triangle >> nth=0').click();
|
|
||||||
|
|
||||||
await page.locator(`a:has-text("Parent Folder") >> nth=0`).click({
|
const treePane = page.locator('#tree-pane');
|
||||||
|
await treePane.getByRole('treeitem', {
|
||||||
|
name: 'Parent Folder'
|
||||||
|
}).click({
|
||||||
button: 'right'
|
button: 'right'
|
||||||
});
|
});
|
||||||
|
|
||||||
await page.locator('li.icon-link').click();
|
await page.getByRole('menuitem', {
|
||||||
await page.locator('form[name="mctForm"] >> .c-disclosure-triangle >> nth=0').click();
|
name: /Move/
|
||||||
await page.locator('form[name="mctForm"] >> text=Parent Folder').click();
|
}).click();
|
||||||
|
|
||||||
|
const locatorTree = page.locator('#locator-tree');
|
||||||
|
const myItemsLocatorTreeItem = locatorTree.getByRole('treeitem', {
|
||||||
|
name: myItemsFolderName
|
||||||
|
});
|
||||||
|
await myItemsLocatorTreeItem.locator('.c-disclosure-triangle').click();
|
||||||
|
await myItemsLocatorTreeItem.click();
|
||||||
|
|
||||||
|
const parentFolderLocatorTreeItem = locatorTree.getByRole('treeitem', {
|
||||||
|
name: parentFolder.name
|
||||||
|
});
|
||||||
|
await parentFolderLocatorTreeItem.locator('.c-disclosure-triangle').click();
|
||||||
|
await parentFolderLocatorTreeItem.click();
|
||||||
await expect(page.locator('[aria-label="Save"]')).toBeDisabled();
|
await expect(page.locator('[aria-label="Save"]')).toBeDisabled();
|
||||||
await page.locator('form[name="mctForm"] >> .c-disclosure-triangle >> nth=1').click();
|
|
||||||
await page.locator('form[name="mctForm"] >> text=Child Folder').click();
|
const childFolderLocatorTreeItem = locatorTree.getByRole('treeitem', {
|
||||||
|
name: new RegExp(childFolder.name)
|
||||||
|
});
|
||||||
|
await childFolderLocatorTreeItem.locator('.c-disclosure-triangle').click();
|
||||||
|
await childFolderLocatorTreeItem.click();
|
||||||
await expect(page.locator('[aria-label="Save"]')).toBeDisabled();
|
await expect(page.locator('[aria-label="Save"]')).toBeDisabled();
|
||||||
await page.locator('form[name="mctForm"] >> .c-disclosure-triangle >> nth=2').click();
|
|
||||||
await page.locator('form[name="mctForm"] >> text=Grandchild Folder').click();
|
const grandchildFolderLocatorTreeItem = locatorTree.getByRole('treeitem', {
|
||||||
|
name: grandchildFolder.name
|
||||||
|
});
|
||||||
|
await grandchildFolderLocatorTreeItem.locator('.c-disclosure-triangle').click();
|
||||||
|
await grandchildFolderLocatorTreeItem.click();
|
||||||
await expect(page.locator('[aria-label="Save"]')).toBeDisabled();
|
await expect(page.locator('[aria-label="Save"]')).toBeDisabled();
|
||||||
await page.locator('form[name="mctForm"] >> text=Parent Folder').click();
|
|
||||||
|
await parentFolderLocatorTreeItem.click();
|
||||||
await expect(page.locator('[aria-label="Save"]')).toBeDisabled();
|
await expect(page.locator('[aria-label="Save"]')).toBeDisabled();
|
||||||
await page.locator('[aria-label="Cancel"]').click();
|
await page.locator('[aria-label="Cancel"]').click();
|
||||||
|
|
||||||
// Link Child Folder from Parent Folder to My Items
|
// Move Child Folder from Parent Folder to My Items
|
||||||
await page.locator('.c-disclosure-triangle >> nth=0').click();
|
await treePane.getByRole('treeitem', {
|
||||||
await page.locator('.c-disclosure-triangle >> nth=1').click();
|
name: new RegExp(childFolder.name)
|
||||||
|
}).click({
|
||||||
await page.locator(`a:has-text("Child Folder") >> nth=0`).click({
|
|
||||||
button: 'right'
|
button: 'right'
|
||||||
});
|
});
|
||||||
await page.locator('li.icon-link').click();
|
await page.getByRole('menuitem', {
|
||||||
await page.locator(`form[name="mctForm"] >> text=${myItemsFolderName}`).click();
|
name: /Link/
|
||||||
|
}).click();
|
||||||
|
await myItemsLocatorTreeItem.click();
|
||||||
|
|
||||||
await page.locator('text=OK').click();
|
await page.locator('[aria-label="Save"]').click();
|
||||||
|
const myItemsPaneTreeItem = treePane.getByRole('treeitem', {
|
||||||
|
name: myItemsFolderName
|
||||||
|
});
|
||||||
|
|
||||||
// Expect that Child Folder is in My Items, the root folder
|
// Expect that Child Folder is in My Items, the root folder
|
||||||
expect(page.locator(`text=${myItemsFolderName} >> nth=0:has(text=Child Folder)`)).toBeTruthy();
|
expect(myItemsPaneTreeItem.locator('nth=0:has(text=Child Folder)')).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
79
e2e/tests/functional/notification.e2e.spec.js
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* 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.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
This test suite is dedicated to tests which verify Open MCT's Notification functionality
|
||||||
|
*/
|
||||||
|
|
||||||
|
// FIXME: Remove this eslint exception once tests are implemented
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
const { createDomainObjectWithDefaults } = require('../../appActions');
|
||||||
|
const { test, expect } = require('../../pluginFixtures');
|
||||||
|
|
||||||
|
test.describe('Notifications List', () => {
|
||||||
|
test.fixme('Notifications can be dismissed individually', async ({ page }) => {
|
||||||
|
// Create some persistent notifications
|
||||||
|
// Verify that they are present in the notifications list
|
||||||
|
// Dismiss one of the notifications
|
||||||
|
// Verify that it is no longer present in the notifications list
|
||||||
|
// Verify that the other notifications are still present in the notifications list
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test.describe('Notification Overlay', () => {
|
||||||
|
test('Closing notification list after notification banner disappeared does not cause it to open automatically', async ({ page }) => {
|
||||||
|
test.info().annotations.push({
|
||||||
|
type: 'issue',
|
||||||
|
description: 'https://github.com/nasa/openmct/issues/6130'
|
||||||
|
});
|
||||||
|
|
||||||
|
// Go to baseURL
|
||||||
|
await page.goto('./', { waitUntil: 'networkidle' });
|
||||||
|
|
||||||
|
// Create a new Display Layout object
|
||||||
|
await createDomainObjectWithDefaults(page, { type: 'Display Layout' });
|
||||||
|
|
||||||
|
// Click on the button "Review 1 Notification"
|
||||||
|
await page.click('button[aria-label="Review 1 Notification"]');
|
||||||
|
|
||||||
|
// Verify that Notification List is open
|
||||||
|
expect(await page.locator('div[role="dialog"]').isVisible()).toBe(true);
|
||||||
|
|
||||||
|
// Wait until there is no Notification Banner
|
||||||
|
await page.waitForSelector('div[role="alert"]', { state: 'detached'});
|
||||||
|
|
||||||
|
// Click on the "Close" button of the Notification List
|
||||||
|
await page.click('button[aria-label="Close"]');
|
||||||
|
|
||||||
|
// On the Display Layout object, click on the "Edit" button
|
||||||
|
await page.click('button[title="Edit"]');
|
||||||
|
|
||||||
|
// Click on the "Save" button
|
||||||
|
await page.click('button[title="Save"]');
|
||||||
|
|
||||||
|
// Click on the "Save and Finish Editing" option
|
||||||
|
await page.click('li[title="Save and Finish Editing"]');
|
||||||
|
|
||||||
|
// Verify that Notification List is NOT open
|
||||||
|
expect(await page.locator('div[role="dialog"]').isVisible()).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -40,11 +40,11 @@ test.describe.serial('Condition Set CRUD Operations on @localStorage', () => {
|
|||||||
await page.goto('./', { waitUntil: 'networkidle' });
|
await page.goto('./', { waitUntil: 'networkidle' });
|
||||||
await page.click('button:has-text("Create")');
|
await page.click('button:has-text("Create")');
|
||||||
|
|
||||||
await page.locator('li:has-text("Condition Set")').click();
|
await page.locator('li[role="menuitem"]:has-text("Condition Set")').click();
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
page.waitForNavigation(),
|
page.waitForNavigation(),
|
||||||
page.click('text=OK')
|
page.click('button:has-text("OK")')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
//Save localStorage for future test execution
|
//Save localStorage for future test execution
|
||||||
@@ -98,8 +98,8 @@ test.describe.serial('Condition Set CRUD Operations on @localStorage', () => {
|
|||||||
await page.locator('text=Conditions View Snapshot >> button').nth(3).click();
|
await page.locator('text=Conditions View Snapshot >> button').nth(3).click();
|
||||||
|
|
||||||
//Edit Condition Set Name from main view
|
//Edit Condition Set Name from main view
|
||||||
await page.locator('text=Unnamed Condition Set').first().fill('Renamed Condition Set');
|
await page.locator('.l-browse-bar__object-name').filter({ hasText: 'Unnamed Condition Set' }).first().fill('Renamed Condition Set');
|
||||||
await page.locator('text=Renamed Condition Set').first().press('Enter');
|
await page.locator('.l-browse-bar__object-name').filter({ hasText: 'Renamed Condition Set' }).first().press('Enter');
|
||||||
// Click Save Button
|
// Click Save Button
|
||||||
await page.locator('text=Snapshot Save and Finish Editing Save and Continue Editing >> button').nth(1).click();
|
await page.locator('text=Snapshot Save and Finish Editing Save and Continue Editing >> button').nth(1).click();
|
||||||
// Click Save and Finish Editing Option
|
// Click Save and Finish Editing Option
|
||||||
@@ -163,9 +163,9 @@ test.describe.serial('Condition Set CRUD Operations on @localStorage', () => {
|
|||||||
// Click hamburger button
|
// Click hamburger button
|
||||||
await page.locator('[title="More options"]').click();
|
await page.locator('[title="More options"]').click();
|
||||||
|
|
||||||
// Click text=Remove
|
// Click 'Remove' and press OK
|
||||||
await page.locator('text=Remove').click();
|
await page.locator('li[role="menuitem"]:has-text("Remove")').click();
|
||||||
await page.locator('text=OK').click();
|
await page.locator('button:has-text("OK")').click();
|
||||||
|
|
||||||
//Expect Unnamed Condition Set to be removed in Main View
|
//Expect Unnamed Condition Set to be removed in Main View
|
||||||
const numberOfConditionSetsAtEnd = await page.locator('a:has-text("Unnamed Condition Set Condition Set")').count();
|
const numberOfConditionSetsAtEnd = await page.locator('a:has-text("Unnamed Condition Set Condition Set")').count();
|
||||||
|
|||||||
@@ -23,7 +23,8 @@
|
|||||||
const { test, expect } = require('../../../../pluginFixtures');
|
const { test, expect } = require('../../../../pluginFixtures');
|
||||||
const { createDomainObjectWithDefaults, setStartOffset, setFixedTimeMode, setRealTimeMode } = require('../../../../appActions');
|
const { createDomainObjectWithDefaults, setStartOffset, setFixedTimeMode, setRealTimeMode } = require('../../../../appActions');
|
||||||
|
|
||||||
test.describe('Testing Display Layout @unstable', () => {
|
test.describe('Display Layout', () => {
|
||||||
|
/** @type {import('../../../../appActions').CreatedObjectInfo} */
|
||||||
let sineWaveObject;
|
let sineWaveObject;
|
||||||
test.beforeEach(async ({ page }) => {
|
test.beforeEach(async ({ page }) => {
|
||||||
await page.goto('./', { waitUntil: 'networkidle' });
|
await page.goto('./', { waitUntil: 'networkidle' });
|
||||||
@@ -31,8 +32,7 @@ test.describe('Testing Display Layout @unstable', () => {
|
|||||||
|
|
||||||
// Create Sine Wave Generator
|
// Create Sine Wave Generator
|
||||||
sineWaveObject = await createDomainObjectWithDefaults(page, {
|
sineWaveObject = await createDomainObjectWithDefaults(page, {
|
||||||
type: 'Sine Wave Generator',
|
type: 'Sine Wave Generator'
|
||||||
name: "Test Sine Wave Generator"
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('alpha-numeric widget telemetry value exactly matches latest telemetry value received in real time', async ({ page }) => {
|
test('alpha-numeric widget telemetry value exactly matches latest telemetry value received in real time', async ({ page }) => {
|
||||||
@@ -47,7 +47,12 @@ test.describe('Testing Display Layout @unstable', () => {
|
|||||||
// Expand the 'My Items' folder in the left tree
|
// Expand the 'My Items' folder in the left tree
|
||||||
await page.locator('.c-tree__item__view-control.c-disclosure-triangle').click();
|
await page.locator('.c-tree__item__view-control.c-disclosure-triangle').click();
|
||||||
// Add the Sine Wave Generator to the Display Layout and save changes
|
// Add the Sine Wave Generator to the Display Layout and save changes
|
||||||
await page.dragAndDrop('text=Test Sine Wave Generator', '.l-layout__grid-holder');
|
const treePane = page.locator('#tree-pane');
|
||||||
|
const sineWaveGeneratorTreeItem = treePane.getByRole('treeitem', {
|
||||||
|
name: new RegExp(sineWaveObject.name)
|
||||||
|
});
|
||||||
|
const layoutGridHolder = page.locator('.l-layout__grid-holder');
|
||||||
|
await sineWaveGeneratorTreeItem.dragTo(layoutGridHolder);
|
||||||
await page.locator('button[title="Save"]').click();
|
await page.locator('button[title="Save"]').click();
|
||||||
await page.locator('text=Save and Finish Editing').click();
|
await page.locator('text=Save and Finish Editing').click();
|
||||||
|
|
||||||
@@ -55,12 +60,12 @@ test.describe('Testing Display Layout @unstable', () => {
|
|||||||
// On getting data, check if the value found in the Display Layout is the most recent value
|
// On getting data, check if the value found in the Display Layout is the most recent value
|
||||||
// from the Sine Wave Generator
|
// from the Sine Wave Generator
|
||||||
const getTelemValuePromise = await subscribeToTelemetry(page, sineWaveObject.uuid);
|
const getTelemValuePromise = await subscribeToTelemetry(page, sineWaveObject.uuid);
|
||||||
const formattedTelemetryValue = await getTelemValuePromise;
|
const formattedTelemetryValue = getTelemValuePromise;
|
||||||
const displayLayoutValuePromise = await page.waitForSelector(`text="${formattedTelemetryValue}"`);
|
const displayLayoutValuePromise = await page.waitForSelector(`text="${formattedTelemetryValue}"`);
|
||||||
const displayLayoutValue = await displayLayoutValuePromise.textContent();
|
const displayLayoutValue = await displayLayoutValuePromise.textContent();
|
||||||
const trimmedDisplayValue = displayLayoutValue.trim();
|
const trimmedDisplayValue = displayLayoutValue.trim();
|
||||||
|
|
||||||
await expect(trimmedDisplayValue).toBe(formattedTelemetryValue);
|
expect(trimmedDisplayValue).toBe(formattedTelemetryValue);
|
||||||
});
|
});
|
||||||
test('alpha-numeric widget telemetry value exactly matches latest telemetry value received in fixed time', async ({ page }) => {
|
test('alpha-numeric widget telemetry value exactly matches latest telemetry value received in fixed time', async ({ page }) => {
|
||||||
// Create a Display Layout
|
// Create a Display Layout
|
||||||
@@ -74,7 +79,12 @@ test.describe('Testing Display Layout @unstable', () => {
|
|||||||
// Expand the 'My Items' folder in the left tree
|
// Expand the 'My Items' folder in the left tree
|
||||||
await page.locator('.c-tree__item__view-control.c-disclosure-triangle').click();
|
await page.locator('.c-tree__item__view-control.c-disclosure-triangle').click();
|
||||||
// Add the Sine Wave Generator to the Display Layout and save changes
|
// Add the Sine Wave Generator to the Display Layout and save changes
|
||||||
await page.dragAndDrop('text=Test Sine Wave Generator', '.l-layout__grid-holder');
|
const treePane = page.locator('#tree-pane');
|
||||||
|
const sineWaveGeneratorTreeItem = treePane.getByRole('treeitem', {
|
||||||
|
name: new RegExp(sineWaveObject.name)
|
||||||
|
});
|
||||||
|
const layoutGridHolder = page.locator('.l-layout__grid-holder');
|
||||||
|
await sineWaveGeneratorTreeItem.dragTo(layoutGridHolder);
|
||||||
await page.locator('button[title="Save"]').click();
|
await page.locator('button[title="Save"]').click();
|
||||||
await page.locator('text=Save and Finish Editing').click();
|
await page.locator('text=Save and Finish Editing').click();
|
||||||
|
|
||||||
@@ -86,12 +96,12 @@ test.describe('Testing Display Layout @unstable', () => {
|
|||||||
|
|
||||||
// On getting data, check if the value found in the Display Layout is the most recent value
|
// On getting data, check if the value found in the Display Layout is the most recent value
|
||||||
// from the Sine Wave Generator
|
// from the Sine Wave Generator
|
||||||
const formattedTelemetryValue = await getTelemValuePromise;
|
const formattedTelemetryValue = getTelemValuePromise;
|
||||||
const displayLayoutValuePromise = await page.waitForSelector(`text="${formattedTelemetryValue}"`);
|
const displayLayoutValuePromise = await page.waitForSelector(`text="${formattedTelemetryValue}"`);
|
||||||
const displayLayoutValue = await displayLayoutValuePromise.textContent();
|
const displayLayoutValue = await displayLayoutValuePromise.textContent();
|
||||||
const trimmedDisplayValue = displayLayoutValue.trim();
|
const trimmedDisplayValue = displayLayoutValue.trim();
|
||||||
|
|
||||||
await expect(trimmedDisplayValue).toBe(formattedTelemetryValue);
|
expect(trimmedDisplayValue).toBe(formattedTelemetryValue);
|
||||||
});
|
});
|
||||||
test('items in a display layout can be removed with object tree context menu when viewing the display layout', async ({ page }) => {
|
test('items in a display layout can be removed with object tree context menu when viewing the display layout', async ({ page }) => {
|
||||||
// Create a Display Layout
|
// Create a Display Layout
|
||||||
@@ -105,7 +115,12 @@ test.describe('Testing Display Layout @unstable', () => {
|
|||||||
// Expand the 'My Items' folder in the left tree
|
// Expand the 'My Items' folder in the left tree
|
||||||
await page.locator('.c-tree__item__view-control.c-disclosure-triangle').click();
|
await page.locator('.c-tree__item__view-control.c-disclosure-triangle').click();
|
||||||
// Add the Sine Wave Generator to the Display Layout and save changes
|
// Add the Sine Wave Generator to the Display Layout and save changes
|
||||||
await page.dragAndDrop('text=Test Sine Wave Generator', '.l-layout__grid-holder');
|
const treePane = page.locator('#tree-pane');
|
||||||
|
const sineWaveGeneratorTreeItem = treePane.getByRole('treeitem', {
|
||||||
|
name: new RegExp(sineWaveObject.name)
|
||||||
|
});
|
||||||
|
const layoutGridHolder = page.locator('.l-layout__grid-holder');
|
||||||
|
await sineWaveGeneratorTreeItem.dragTo(layoutGridHolder);
|
||||||
await page.locator('button[title="Save"]').click();
|
await page.locator('button[title="Save"]').click();
|
||||||
await page.locator('text=Save and Finish Editing').click();
|
await page.locator('text=Save and Finish Editing').click();
|
||||||
|
|
||||||
@@ -115,19 +130,22 @@ test.describe('Testing Display Layout @unstable', () => {
|
|||||||
await page.locator('.c-tree__item.is-navigated-object .c-disclosure-triangle').click();
|
await page.locator('.c-tree__item.is-navigated-object .c-disclosure-triangle').click();
|
||||||
|
|
||||||
// Bring up context menu and remove
|
// Bring up context menu and remove
|
||||||
await page.locator('.c-tree__item.is-alias .c-tree__item__name:text("Test Sine Wave Generator")').first().click({ button: 'right' });
|
await sineWaveGeneratorTreeItem.nth(1).click({ button: 'right' });
|
||||||
await page.locator('text=Remove').click();
|
await page.locator('li[role="menuitem"]:has-text("Remove")').click();
|
||||||
await page.locator('text=OK').click();
|
await page.locator('button:has-text("OK")').click();
|
||||||
|
|
||||||
// delete
|
// delete
|
||||||
|
|
||||||
expect.soft(await page.locator('.l-layout .l-layout__frame').count()).toEqual(0);
|
expect(await page.locator('.l-layout .l-layout__frame').count()).toEqual(0);
|
||||||
});
|
});
|
||||||
test('items in a display layout can be removed with object tree context menu when viewing another item', async ({ page }) => {
|
test('items in a display layout can be removed with object tree context menu when viewing another item', async ({ page }) => {
|
||||||
|
test.info().annotations.push({
|
||||||
|
type: 'issue',
|
||||||
|
description: 'https://github.com/nasa/openmct/issues/3117'
|
||||||
|
});
|
||||||
// Create a Display Layout
|
// Create a Display Layout
|
||||||
await createDomainObjectWithDefaults(page, {
|
const displayLayout = await createDomainObjectWithDefaults(page, {
|
||||||
type: 'Display Layout',
|
type: 'Display Layout'
|
||||||
name: "Test Display Layout"
|
|
||||||
});
|
});
|
||||||
// Edit Display Layout
|
// Edit Display Layout
|
||||||
await page.locator('[title="Edit"]').click();
|
await page.locator('[title="Edit"]').click();
|
||||||
@@ -135,7 +153,12 @@ test.describe('Testing Display Layout @unstable', () => {
|
|||||||
// Expand the 'My Items' folder in the left tree
|
// Expand the 'My Items' folder in the left tree
|
||||||
await page.locator('.c-tree__item__view-control.c-disclosure-triangle').click();
|
await page.locator('.c-tree__item__view-control.c-disclosure-triangle').click();
|
||||||
// Add the Sine Wave Generator to the Display Layout and save changes
|
// Add the Sine Wave Generator to the Display Layout and save changes
|
||||||
await page.dragAndDrop('text=Test Sine Wave Generator', '.l-layout__grid-holder');
|
const treePane = page.locator('#tree-pane');
|
||||||
|
const sineWaveGeneratorTreeItem = treePane.getByRole('treeitem', {
|
||||||
|
name: new RegExp(sineWaveObject.name)
|
||||||
|
});
|
||||||
|
const layoutGridHolder = page.locator('.l-layout__grid-holder');
|
||||||
|
await sineWaveGeneratorTreeItem.dragTo(layoutGridHolder);
|
||||||
await page.locator('button[title="Save"]').click();
|
await page.locator('button[title="Save"]').click();
|
||||||
await page.locator('text=Save and Finish Editing').click();
|
await page.locator('text=Save and Finish Editing').click();
|
||||||
|
|
||||||
@@ -144,18 +167,18 @@ test.describe('Testing Display Layout @unstable', () => {
|
|||||||
// Expand the Display Layout so we can remove the sine wave generator
|
// Expand the Display Layout so we can remove the sine wave generator
|
||||||
await page.locator('.c-tree__item.is-navigated-object .c-disclosure-triangle').click();
|
await page.locator('.c-tree__item.is-navigated-object .c-disclosure-triangle').click();
|
||||||
|
|
||||||
// Click the original Sine Wave Generator to navigate away from the Display Layout
|
// Go to the original Sine Wave Generator to navigate away from the Display Layout
|
||||||
await page.locator('.c-tree__item .c-tree__item__name:text("Test Sine Wave Generator")').click();
|
await page.goto(sineWaveObject.url);
|
||||||
|
|
||||||
// Bring up context menu and remove
|
// Bring up context menu and remove
|
||||||
await page.locator('.c-tree__item.is-alias .c-tree__item__name:text("Test Sine Wave Generator")').click({ button: 'right' });
|
await sineWaveGeneratorTreeItem.first().click({ button: 'right' });
|
||||||
await page.locator('text=Remove').click();
|
await page.locator('li[role="menuitem"]:has-text("Remove")').click();
|
||||||
await page.locator('text=OK').click();
|
await page.locator('button:has-text("OK")').click();
|
||||||
|
|
||||||
// navigate back to the display layout to confirm it has been removed
|
// navigate back to the display layout to confirm it has been removed
|
||||||
await page.locator('.c-tree__item .c-tree__item__name:text("Test Display Layout")').click();
|
await page.goto(displayLayout.url);
|
||||||
|
|
||||||
expect.soft(await page.locator('.l-layout .l-layout__frame').count()).toEqual(0);
|
expect(await page.locator('.l-layout .l-layout__frame').count()).toEqual(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -23,27 +23,33 @@
|
|||||||
const { test, expect } = require('../../../../pluginFixtures');
|
const { test, expect } = require('../../../../pluginFixtures');
|
||||||
const { createDomainObjectWithDefaults } = require('../../../../appActions');
|
const { createDomainObjectWithDefaults } = require('../../../../appActions');
|
||||||
|
|
||||||
test.describe('Testing Flexible Layout @unstable', () => {
|
test.describe('Flexible Layout', () => {
|
||||||
|
let sineWaveObject;
|
||||||
|
let clockObject;
|
||||||
test.beforeEach(async ({ page }) => {
|
test.beforeEach(async ({ page }) => {
|
||||||
await page.goto('./', { waitUntil: 'networkidle' });
|
await page.goto('./', { waitUntil: 'networkidle' });
|
||||||
|
|
||||||
// Create Sine Wave Generator
|
// Create Sine Wave Generator
|
||||||
await createDomainObjectWithDefaults(page, {
|
sineWaveObject = await createDomainObjectWithDefaults(page, {
|
||||||
type: 'Sine Wave Generator',
|
type: 'Sine Wave Generator'
|
||||||
name: "Test Sine Wave Generator"
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create Clock Object
|
// Create Clock Object
|
||||||
await createDomainObjectWithDefaults(page, {
|
clockObject = await createDomainObjectWithDefaults(page, {
|
||||||
type: 'Clock',
|
type: 'Clock'
|
||||||
name: "Test Clock"
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('panes have the appropriate draggable attribute while in Edit and Browse modes', async ({ page }) => {
|
test('panes have the appropriate draggable attribute while in Edit and Browse modes', async ({ page }) => {
|
||||||
|
const treePane = page.locator('#tree-pane');
|
||||||
|
const sineWaveGeneratorTreeItem = treePane.getByRole('treeitem', {
|
||||||
|
name: new RegExp(sineWaveObject.name)
|
||||||
|
});
|
||||||
|
const clockTreeItem = treePane.getByRole('treeitem', {
|
||||||
|
name: new RegExp(clockObject.name)
|
||||||
|
});
|
||||||
// Create a Flexible Layout
|
// Create a Flexible Layout
|
||||||
await createDomainObjectWithDefaults(page, {
|
await createDomainObjectWithDefaults(page, {
|
||||||
type: 'Flexible Layout',
|
type: 'Flexible Layout'
|
||||||
name: "Test Flexible Layout"
|
|
||||||
});
|
});
|
||||||
// Edit Flexible Layout
|
// Edit Flexible Layout
|
||||||
await page.locator('[title="Edit"]').click();
|
await page.locator('[title="Edit"]').click();
|
||||||
@@ -51,16 +57,91 @@ test.describe('Testing Flexible Layout @unstable', () => {
|
|||||||
// Expand the 'My Items' folder in the left tree
|
// Expand the 'My Items' folder in the left tree
|
||||||
await page.locator('.c-tree__item__view-control.c-disclosure-triangle').first().click();
|
await page.locator('.c-tree__item__view-control.c-disclosure-triangle').first().click();
|
||||||
// Add the Sine Wave Generator and Clock to the Flexible Layout
|
// Add the Sine Wave Generator and Clock to the Flexible Layout
|
||||||
await page.dragAndDrop('text=Test Sine Wave Generator', '.c-fl__container.is-empty');
|
await sineWaveGeneratorTreeItem.dragTo(page.locator('.c-fl__container.is-empty').first());
|
||||||
await page.dragAndDrop('text=Test Clock', '.c-fl__container.is-empty');
|
await clockTreeItem.dragTo(page.locator('.c-fl__container.is-empty'));
|
||||||
// Check that panes can be dragged while Flexible Layout is in Edit mode
|
// Check that panes can be dragged while Flexible Layout is in Edit mode
|
||||||
let dragWrapper = await page.locator('.c-fl-container__frames-holder .c-fl-frame__drag-wrapper').first();
|
let dragWrapper = page.locator('.c-fl-container__frames-holder .c-fl-frame__drag-wrapper').first();
|
||||||
await expect(dragWrapper).toHaveAttribute('draggable', 'true');
|
await expect(dragWrapper).toHaveAttribute('draggable', 'true');
|
||||||
// Save Flexible Layout
|
// Save Flexible Layout
|
||||||
await page.locator('button[title="Save"]').click();
|
await page.locator('button[title="Save"]').click();
|
||||||
await page.locator('text=Save and Finish Editing').click();
|
await page.locator('text=Save and Finish Editing').click();
|
||||||
// Check that panes are not draggable while Flexible Layout is in Browse mode
|
// Check that panes are not draggable while Flexible Layout is in Browse mode
|
||||||
dragWrapper = await page.locator('.c-fl-container__frames-holder .c-fl-frame__drag-wrapper').first();
|
dragWrapper = page.locator('.c-fl-container__frames-holder .c-fl-frame__drag-wrapper').first();
|
||||||
await expect(dragWrapper).toHaveAttribute('draggable', 'false');
|
await expect(dragWrapper).toHaveAttribute('draggable', 'false');
|
||||||
});
|
});
|
||||||
|
test('items in a flexible layout can be removed with object tree context menu when viewing the flexible layout', async ({ page }) => {
|
||||||
|
const treePane = page.locator('#tree-pane');
|
||||||
|
const sineWaveGeneratorTreeItem = treePane.getByRole('treeitem', {
|
||||||
|
name: new RegExp(sineWaveObject.name)
|
||||||
|
});
|
||||||
|
// Create a Display Layout
|
||||||
|
await createDomainObjectWithDefaults(page, {
|
||||||
|
type: 'Flexible Layout'
|
||||||
|
});
|
||||||
|
// Edit Flexible Layout
|
||||||
|
await page.locator('[title="Edit"]').click();
|
||||||
|
|
||||||
|
// Expand the 'My Items' folder in the left tree
|
||||||
|
await page.locator('.c-tree__item__view-control.c-disclosure-triangle').first().click();
|
||||||
|
// Add the Sine Wave Generator to the Flexible Layout and save changes
|
||||||
|
await sineWaveGeneratorTreeItem.dragTo(page.locator('.c-fl__container.is-empty').first());
|
||||||
|
await page.locator('button[title="Save"]').click();
|
||||||
|
await page.locator('text=Save and Finish Editing').click();
|
||||||
|
|
||||||
|
expect.soft(await page.locator('.c-fl-container__frame').count()).toEqual(1);
|
||||||
|
|
||||||
|
// Expand the Flexible Layout so we can remove the sine wave generator
|
||||||
|
await page.locator('.c-tree__item.is-navigated-object .c-disclosure-triangle').click();
|
||||||
|
|
||||||
|
// Bring up context menu and remove
|
||||||
|
await sineWaveGeneratorTreeItem.first().click({ button: 'right' });
|
||||||
|
await page.locator('li[role="menuitem"]:has-text("Remove")').click();
|
||||||
|
await page.locator('button:has-text("OK")').click();
|
||||||
|
|
||||||
|
// Verify that the item has been removed from the layout
|
||||||
|
expect(await page.locator('.c-fl-container__frame').count()).toEqual(0);
|
||||||
|
});
|
||||||
|
test('items in a flexible layout can be removed with object tree context menu when viewing another item', async ({ page }) => {
|
||||||
|
test.info().annotations.push({
|
||||||
|
type: 'issue',
|
||||||
|
description: 'https://github.com/nasa/openmct/issues/3117'
|
||||||
|
});
|
||||||
|
const treePane = page.locator('#tree-pane');
|
||||||
|
const sineWaveGeneratorTreeItem = treePane.getByRole('treeitem', {
|
||||||
|
name: new RegExp(sineWaveObject.name)
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create a Flexible Layout
|
||||||
|
const flexibleLayout = await createDomainObjectWithDefaults(page, {
|
||||||
|
type: 'Flexible Layout'
|
||||||
|
});
|
||||||
|
// Edit Flexible Layout
|
||||||
|
await page.locator('[title="Edit"]').click();
|
||||||
|
|
||||||
|
// Expand the 'My Items' folder in the left tree
|
||||||
|
await page.locator('.c-tree__item__view-control.c-disclosure-triangle').click();
|
||||||
|
// Add the Sine Wave Generator to the Flexible Layout and save changes
|
||||||
|
await sineWaveGeneratorTreeItem.dragTo(page.locator('.c-fl__container.is-empty').first());
|
||||||
|
await page.locator('button[title="Save"]').click();
|
||||||
|
await page.locator('text=Save and Finish Editing').click();
|
||||||
|
|
||||||
|
expect.soft(await page.locator('.c-fl-container__frame').count()).toEqual(1);
|
||||||
|
|
||||||
|
// Expand the Flexible Layout so we can remove the sine wave generator
|
||||||
|
await page.locator('.c-tree__item.is-navigated-object .c-disclosure-triangle').click();
|
||||||
|
|
||||||
|
// Go to the original Sine Wave Generator to navigate away from the Flexible Layout
|
||||||
|
await page.goto(sineWaveObject.url);
|
||||||
|
|
||||||
|
// Bring up context menu and remove
|
||||||
|
await sineWaveGeneratorTreeItem.first().click({ button: 'right' });
|
||||||
|
await page.locator('li[role="menuitem"]:has-text("Remove")').click();
|
||||||
|
await page.locator('button:has-text("OK")').click();
|
||||||
|
|
||||||
|
// navigate back to the display layout to confirm it has been removed
|
||||||
|
await page.goto(flexibleLayout.url);
|
||||||
|
|
||||||
|
// Verify that the item has been removed from the layout
|
||||||
|
expect(await page.locator('.c-fl-container__frame').count()).toEqual(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
124
e2e/tests/functional/plugins/gauge/gauge.e2e.spec.js
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* 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.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This test suite is dedicated to testing the Gauge component.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const { test, expect } = require('../../../../pluginFixtures');
|
||||||
|
const { createDomainObjectWithDefaults } = require('../../../../appActions');
|
||||||
|
const uuid = require('uuid').v4;
|
||||||
|
|
||||||
|
test.describe('Gauge', () => {
|
||||||
|
test.beforeEach(async ({ page }) => {
|
||||||
|
// Open a browser, navigate to the main page, and wait until all networkevents to resolve
|
||||||
|
await page.goto('./', { waitUntil: 'networkidle' });
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Can add and remove telemetry sources @unstable', async ({ page }) => {
|
||||||
|
// Create the gauge with defaults
|
||||||
|
const gauge = await createDomainObjectWithDefaults(page, { type: 'Gauge' });
|
||||||
|
const editButtonLocator = page.locator('button[title="Edit"]');
|
||||||
|
const saveButtonLocator = page.locator('button[title="Save"]');
|
||||||
|
|
||||||
|
// Create a sine wave generator within the gauge
|
||||||
|
const swg1 = await createDomainObjectWithDefaults(page, {
|
||||||
|
type: 'Sine Wave Generator',
|
||||||
|
name: `swg-${uuid()}`,
|
||||||
|
parent: gauge.uuid
|
||||||
|
});
|
||||||
|
|
||||||
|
// Navigate to the gauge and verify that
|
||||||
|
// the SWG appears in the elements pool
|
||||||
|
await page.goto(gauge.url);
|
||||||
|
await editButtonLocator.click();
|
||||||
|
await expect.soft(page.locator(`#inspector-elements-tree >> text=${swg1.name}`)).toBeVisible();
|
||||||
|
await saveButtonLocator.click();
|
||||||
|
await page.locator('li[title="Save and Finish Editing"]').click();
|
||||||
|
|
||||||
|
// Create another sine wave generator within the gauge
|
||||||
|
const swg2 = await createDomainObjectWithDefaults(page, {
|
||||||
|
type: 'Sine Wave Generator',
|
||||||
|
name: `swg-${uuid()}`,
|
||||||
|
parent: gauge.uuid
|
||||||
|
});
|
||||||
|
|
||||||
|
// Verify that the 'Replace telemetry source' modal appears and accept it
|
||||||
|
await expect.soft(page.locator('text=This action will replace the current telemetry source. Do you want to continue?')).toBeVisible();
|
||||||
|
await page.click('text=Ok');
|
||||||
|
|
||||||
|
// Navigate to the gauge and verify that the new SWG
|
||||||
|
// appears in the elements pool and the old one is gone
|
||||||
|
await page.goto(gauge.url);
|
||||||
|
await editButtonLocator.click();
|
||||||
|
await expect.soft(page.locator(`#inspector-elements-tree >> text=${swg1.name}`)).toBeHidden();
|
||||||
|
await expect.soft(page.locator(`#inspector-elements-tree >> text=${swg2.name}`)).toBeVisible();
|
||||||
|
await saveButtonLocator.click();
|
||||||
|
|
||||||
|
// Right click on the new SWG in the elements pool and delete it
|
||||||
|
await page.locator(`#inspector-elements-tree >> text=${swg2.name}`).click({
|
||||||
|
button: 'right'
|
||||||
|
});
|
||||||
|
await page.locator('li[title="Remove this object from its containing object."]').click();
|
||||||
|
|
||||||
|
// Verify that the 'Remove object' confirmation modal appears and accept it
|
||||||
|
await expect.soft(page.locator('text=Warning! This action will remove this object. Are you sure you want to continue?')).toBeVisible();
|
||||||
|
await page.click('text=Ok');
|
||||||
|
|
||||||
|
// Verify that the elements pool shows no elements
|
||||||
|
await expect(page.locator('text="No contained elements"')).toBeVisible();
|
||||||
|
});
|
||||||
|
test('Can create a non-default Gauge', async ({ page }) => {
|
||||||
|
test.info().annotations.push({
|
||||||
|
type: 'issue',
|
||||||
|
description: 'https://github.com/nasa/openmct/issues/5356'
|
||||||
|
});
|
||||||
|
//Click the Create button
|
||||||
|
await page.click('button:has-text("Create")');
|
||||||
|
|
||||||
|
// Click the object specified by 'type'
|
||||||
|
await page.click(`li[role='menuitem']:text("Gauge")`);
|
||||||
|
// FIXME: We need better selectors for these custom form controls
|
||||||
|
const displayCurrentValueSwitch = page.locator('.c-toggle-switch__slider >> nth=0');
|
||||||
|
await displayCurrentValueSwitch.setChecked(false);
|
||||||
|
await page.click('button[aria-label="Save"]');
|
||||||
|
|
||||||
|
// TODO: Verify changes in the UI
|
||||||
|
});
|
||||||
|
test('Can edit a single Gauge-specific property', async ({ page }) => {
|
||||||
|
test.info().annotations.push({
|
||||||
|
type: 'issue',
|
||||||
|
description: 'https://github.com/nasa/openmct/issues/5985'
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create the gauge with defaults
|
||||||
|
await createDomainObjectWithDefaults(page, { type: 'Gauge' });
|
||||||
|
await page.click('button[title="More options"]');
|
||||||
|
await page.click('li[role="menuitem"]:has-text("Edit Properties")');
|
||||||
|
// FIXME: We need better selectors for these custom form controls
|
||||||
|
const displayCurrentValueSwitch = page.locator('.c-toggle-switch__slider >> nth=0');
|
||||||
|
await displayCurrentValueSwitch.setChecked(false);
|
||||||
|
await page.click('button[aria-label="Save"]');
|
||||||
|
|
||||||
|
// TODO: Verify changes in the UI
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -25,13 +25,13 @@ This test suite is dedicated to tests which verify the basic operations surround
|
|||||||
but only assume that example imagery is present.
|
but only assume that example imagery is present.
|
||||||
*/
|
*/
|
||||||
/* globals process */
|
/* globals process */
|
||||||
const { v4: uuid } = require('uuid');
|
|
||||||
const { waitForAnimations } = require('../../../../baseFixtures');
|
const { waitForAnimations } = require('../../../../baseFixtures');
|
||||||
const { test, expect } = require('../../../../pluginFixtures');
|
const { test, expect } = require('../../../../pluginFixtures');
|
||||||
const { createDomainObjectWithDefaults } = require('../../../../appActions');
|
const { createDomainObjectWithDefaults } = require('../../../../appActions');
|
||||||
const backgroundImageSelector = '.c-imagery__main-image__background-image';
|
const backgroundImageSelector = '.c-imagery__main-image__background-image';
|
||||||
const panHotkey = process.platform === 'linux' ? ['Control', 'Alt'] : ['Alt'];
|
const panHotkey = process.platform === 'linux' ? ['Control', 'Alt'] : ['Alt'];
|
||||||
const expectedAltText = process.platform === 'linux' ? 'Ctrl+Alt drag to pan' : 'Alt drag to pan';
|
const expectedAltText = process.platform === 'linux' ? 'Ctrl+Alt drag to pan' : 'Alt drag to pan';
|
||||||
|
const thumbnailUrlParamsRegexp = /\?w=100&h=100/;
|
||||||
|
|
||||||
//The following block of tests verifies the basic functionality of example imagery and serves as a template for Imagery objects embedded in other objects.
|
//The following block of tests verifies the basic functionality of example imagery and serves as a template for Imagery objects embedded in other objects.
|
||||||
test.describe('Example Imagery Object', () => {
|
test.describe('Example Imagery Object', () => {
|
||||||
@@ -40,10 +40,10 @@ test.describe('Example Imagery Object', () => {
|
|||||||
await page.goto('./', { waitUntil: 'networkidle' });
|
await page.goto('./', { waitUntil: 'networkidle' });
|
||||||
|
|
||||||
// Create a default 'Example Imagery' object
|
// Create a default 'Example Imagery' object
|
||||||
await createDomainObjectWithDefaults(page, { type: 'Example Imagery' });
|
const exampleImagery = await createDomainObjectWithDefaults(page, { type: 'Example Imagery' });
|
||||||
|
|
||||||
// Verify that the created object is focused
|
// Verify that the created object is focused
|
||||||
await expect(page.locator('.l-browse-bar__object-name')).toContainText('Unnamed Example Imagery');
|
await expect(page.locator('.l-browse-bar__object-name')).toContainText(exampleImagery.name);
|
||||||
await page.locator(backgroundImageSelector).hover({trial: true});
|
await page.locator(backgroundImageSelector).hover({trial: true});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -188,7 +188,7 @@ test.describe('Example Imagery in Display Layout', () => {
|
|||||||
await page.click('button:has-text("Create")');
|
await page.click('button:has-text("Create")');
|
||||||
|
|
||||||
// Click text=Example Imagery
|
// Click text=Example Imagery
|
||||||
await page.click('text=Example Imagery');
|
await page.click('li[role="menuitem"]:has-text("Example Imagery")');
|
||||||
|
|
||||||
// Clear and set Image load delay to minimum value
|
// Clear and set Image load delay to minimum value
|
||||||
await page.locator('input[type="number"]').fill('');
|
await page.locator('input[type="number"]').fill('');
|
||||||
@@ -197,7 +197,7 @@ test.describe('Example Imagery in Display Layout', () => {
|
|||||||
// Click text=OK
|
// Click text=OK
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
page.waitForNavigation({waitUntil: 'networkidle'}),
|
page.waitForNavigation({waitUntil: 'networkidle'}),
|
||||||
page.click('text=OK'),
|
page.click('button:has-text("OK")'),
|
||||||
//Wait for Save Banner to appear
|
//Wait for Save Banner to appear
|
||||||
page.waitForSelector('.c-message-banner__message')
|
page.waitForSelector('.c-message-banner__message')
|
||||||
]);
|
]);
|
||||||
@@ -207,6 +207,58 @@ test.describe('Example Imagery in Display Layout', () => {
|
|||||||
await page.goto(displayLayout.url);
|
await page.goto(displayLayout.url);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('View Large action pauses imagery when in realtime and returns to realtime', async ({ page }) => {
|
||||||
|
test.info().annotations.push({
|
||||||
|
type: 'issue',
|
||||||
|
description: 'https://github.com/nasa/openmct/issues/3647'
|
||||||
|
});
|
||||||
|
|
||||||
|
// Click time conductor mode button
|
||||||
|
await page.locator('.c-mode-button').click();
|
||||||
|
|
||||||
|
// set realtime mode
|
||||||
|
await page.locator('[data-testid="conductor-modeOption-realtime"]').click();
|
||||||
|
|
||||||
|
// pause/play button
|
||||||
|
const pausePlayButton = await page.locator('.c-button.pause-play');
|
||||||
|
|
||||||
|
await expect.soft(pausePlayButton).not.toHaveClass(/is-paused/);
|
||||||
|
|
||||||
|
// Open context menu and click view large menu item
|
||||||
|
await page.locator('button[title="View menu items"]').click();
|
||||||
|
await page.locator('li[title="View Large"]').click();
|
||||||
|
await expect(pausePlayButton).toHaveClass(/is-paused/);
|
||||||
|
|
||||||
|
await page.locator('[aria-label="Close"]').click();
|
||||||
|
await expect.soft(pausePlayButton).not.toHaveClass(/is-paused/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('View Large action leaves keeps realtime mode paused', async ({ page }) => {
|
||||||
|
test.info().annotations.push({
|
||||||
|
type: 'issue',
|
||||||
|
description: 'https://github.com/nasa/openmct/issues/3647'
|
||||||
|
});
|
||||||
|
|
||||||
|
// Click time conductor mode button
|
||||||
|
await page.locator('.c-mode-button').click();
|
||||||
|
|
||||||
|
// set realtime mode
|
||||||
|
await page.locator('[data-testid="conductor-modeOption-realtime"]').click();
|
||||||
|
|
||||||
|
// pause/play button
|
||||||
|
const pausePlayButton = await page.locator('.c-button.pause-play');
|
||||||
|
await pausePlayButton.click();
|
||||||
|
await expect.soft(pausePlayButton).toHaveClass(/is-paused/);
|
||||||
|
|
||||||
|
// Open context menu and click view large menu item
|
||||||
|
await page.locator('button[title="View menu items"]').click();
|
||||||
|
await page.locator('li[title="View Large"]').click();
|
||||||
|
await expect(pausePlayButton).toHaveClass(/is-paused/);
|
||||||
|
|
||||||
|
await page.locator('[aria-label="Close"]').click();
|
||||||
|
await expect.soft(pausePlayButton).toHaveClass(/is-paused/);
|
||||||
|
});
|
||||||
|
|
||||||
test('Imagery View operations @unstable', async ({ page }) => {
|
test('Imagery View operations @unstable', async ({ page }) => {
|
||||||
test.info().annotations.push({
|
test.info().annotations.push({
|
||||||
type: 'issue',
|
type: 'issue',
|
||||||
@@ -275,7 +327,7 @@ test.describe('Example Imagery in Flexible layout', () => {
|
|||||||
await page.click('button:has-text("Create")');
|
await page.click('button:has-text("Create")');
|
||||||
|
|
||||||
// Click text=Example Imagery
|
// Click text=Example Imagery
|
||||||
await page.click('text=Example Imagery');
|
await page.click('li[role="menuitem"]:has-text("Example Imagery")');
|
||||||
|
|
||||||
// Clear and set Image load delay to minimum value
|
// Clear and set Image load delay to minimum value
|
||||||
await page.locator('input[type="number"]').fill('');
|
await page.locator('input[type="number"]').fill('');
|
||||||
@@ -284,7 +336,7 @@ test.describe('Example Imagery in Flexible layout', () => {
|
|||||||
// Click text=OK
|
// Click text=OK
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
page.waitForNavigation({waitUntil: 'networkidle'}),
|
page.waitForNavigation({waitUntil: 'networkidle'}),
|
||||||
page.click('text=OK'),
|
page.click('button:has-text("OK")'),
|
||||||
//Wait for Save Banner to appear
|
//Wait for Save Banner to appear
|
||||||
page.waitForSelector('.c-message-banner__message')
|
page.waitForSelector('.c-message-banner__message')
|
||||||
]);
|
]);
|
||||||
@@ -317,7 +369,7 @@ test.describe('Example Imagery in Tabs View', () => {
|
|||||||
await page.click('button:has-text("Create")');
|
await page.click('button:has-text("Create")');
|
||||||
|
|
||||||
// Click text=Example Imagery
|
// Click text=Example Imagery
|
||||||
await page.click('text=Example Imagery');
|
await page.click('li[role="menuitem"]:has-text("Example Imagery")');
|
||||||
|
|
||||||
// Clear and set Image load delay to minimum value
|
// Clear and set Image load delay to minimum value
|
||||||
await page.locator('input[type="number"]').fill('');
|
await page.locator('input[type="number"]').fill('');
|
||||||
@@ -326,7 +378,7 @@ test.describe('Example Imagery in Tabs View', () => {
|
|||||||
// Click text=OK
|
// Click text=OK
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
page.waitForNavigation({waitUntil: 'networkidle'}),
|
page.waitForNavigation({waitUntil: 'networkidle'}),
|
||||||
page.click('text=OK'),
|
page.click('button:has-text("OK")'),
|
||||||
//Wait for Save Banner to appear
|
//Wait for Save Banner to appear
|
||||||
page.waitForSelector('.c-message-banner__message')
|
page.waitForSelector('.c-message-banner__message')
|
||||||
]);
|
]);
|
||||||
@@ -345,13 +397,11 @@ test.describe('Example Imagery in Time Strip', () => {
|
|||||||
test.beforeEach(async ({ page }) => {
|
test.beforeEach(async ({ page }) => {
|
||||||
await page.goto('./', { waitUntil: 'networkidle' });
|
await page.goto('./', { waitUntil: 'networkidle' });
|
||||||
timeStripObject = await createDomainObjectWithDefaults(page, {
|
timeStripObject = await createDomainObjectWithDefaults(page, {
|
||||||
type: 'Time Strip',
|
type: 'Time Strip'
|
||||||
name: 'Time Strip'.concat(' ', uuid())
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await createDomainObjectWithDefaults(page, {
|
await createDomainObjectWithDefaults(page, {
|
||||||
type: 'Example Imagery',
|
type: 'Example Imagery',
|
||||||
name: 'Example Imagery'.concat(' ', uuid()),
|
|
||||||
parent: timeStripObject.uuid
|
parent: timeStripObject.uuid
|
||||||
});
|
});
|
||||||
// Navigate to timestrip
|
// Navigate to timestrip
|
||||||
@@ -362,17 +412,28 @@ test.describe('Example Imagery in Time Strip', () => {
|
|||||||
type: 'issue',
|
type: 'issue',
|
||||||
description: 'https://github.com/nasa/openmct/issues/5632'
|
description: 'https://github.com/nasa/openmct/issues/5632'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Hover over the timestrip to reveal a thumbnail image
|
||||||
await page.locator('.c-imagery-tsv-container').hover();
|
await page.locator('.c-imagery-tsv-container').hover();
|
||||||
// get url of the hovered image
|
|
||||||
const hoveredImg = page.locator('.c-imagery-tsv div.c-imagery-tsv__image-wrapper:hover img');
|
// Get the img src of the hovered image thumbnail
|
||||||
const hoveredImgSrc = await hoveredImg.getAttribute('src');
|
const hoveredThumbnailImg = page.locator('.c-imagery-tsv div.c-imagery-tsv__image-wrapper:hover img');
|
||||||
expect(hoveredImgSrc).toBeTruthy();
|
const hoveredThumbnailImgSrc = await hoveredThumbnailImg.getAttribute('src');
|
||||||
|
|
||||||
|
// Verify that imagery timestrip view uses the thumbnailUrl as img src for thumbnails
|
||||||
|
expect(hoveredThumbnailImgSrc).toBeTruthy();
|
||||||
|
expect(hoveredThumbnailImgSrc).toMatch(thumbnailUrlParamsRegexp);
|
||||||
|
|
||||||
|
// Click on the hovered thumbnail to open "View Large" view
|
||||||
await page.locator('.c-imagery-tsv-container').click();
|
await page.locator('.c-imagery-tsv-container').click();
|
||||||
// get image of view large container
|
|
||||||
|
// Get the img src of the large view image
|
||||||
const viewLargeImg = page.locator('img.c-imagery__main-image__image');
|
const viewLargeImg = page.locator('img.c-imagery__main-image__image');
|
||||||
const viewLargeImgSrc = await viewLargeImg.getAttribute('src');
|
const viewLargeImgSrc = await viewLargeImg.getAttribute('src');
|
||||||
expect(viewLargeImgSrc).toBeTruthy();
|
expect(viewLargeImgSrc).toBeTruthy();
|
||||||
expect(viewLargeImgSrc).toEqual(hoveredImgSrc);
|
|
||||||
|
// Verify that the image in the large view is the same as the hovered thumbnail
|
||||||
|
expect(viewLargeImgSrc).toEqual(hoveredThumbnailImgSrc.split('?')[0]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -389,6 +450,12 @@ test.describe('Example Imagery in Time Strip', () => {
|
|||||||
* @param {import('@playwright/test').Page} page
|
* @param {import('@playwright/test').Page} page
|
||||||
*/
|
*/
|
||||||
async function performImageryViewOperationsAndAssert(page) {
|
async function performImageryViewOperationsAndAssert(page) {
|
||||||
|
// Verify that imagery thumbnails use a thumbnail url
|
||||||
|
const thumbnailImages = page.locator('.c-thumb__image');
|
||||||
|
const mainImage = page.locator('.c-imagery__main-image__image');
|
||||||
|
await expect(thumbnailImages.first()).toHaveAttribute('src', thumbnailUrlParamsRegexp);
|
||||||
|
await expect(mainImage).not.toHaveAttribute('src', thumbnailUrlParamsRegexp);
|
||||||
|
|
||||||
// Click previous image button
|
// Click previous image button
|
||||||
const previousImageButton = page.locator('.c-nav--prev');
|
const previousImageButton = page.locator('.c-nav--prev');
|
||||||
await previousImageButton.click();
|
await previousImageButton.click();
|
||||||
|
|||||||
@@ -24,9 +24,7 @@
|
|||||||
This test suite is dedicated to tests which verify the basic operations surrounding Notebooks.
|
This test suite is dedicated to tests which verify the basic operations surrounding Notebooks.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// FIXME: Remove this eslint exception once tests are implemented
|
const { test, expect } = require('../../../../pluginFixtures');
|
||||||
// eslint-disable-next-line no-unused-vars
|
|
||||||
const { test, expect } = require('../../../../baseFixtures');
|
|
||||||
const { expandTreePaneItemByName, createDomainObjectWithDefaults } = require('../../../../appActions');
|
const { expandTreePaneItemByName, createDomainObjectWithDefaults } = require('../../../../appActions');
|
||||||
const nbUtils = require('../../../../helper/notebookUtils');
|
const nbUtils = require('../../../../helper/notebookUtils');
|
||||||
|
|
||||||
@@ -265,71 +263,77 @@ test.describe('Notebook entry tests', () => {
|
|||||||
});
|
});
|
||||||
test.fixme('new entries persist through navigation events without save', async ({ page }) => {});
|
test.fixme('new entries persist through navigation events without save', async ({ page }) => {});
|
||||||
test.fixme('previous and new entries can be deleted', async ({ page }) => {});
|
test.fixme('previous and new entries can be deleted', async ({ page }) => {});
|
||||||
});
|
test.fixme('when a valid link is entered into a notebook entry, it becomes clickable when viewing', async ({ page }) => {
|
||||||
|
const TEST_LINK = 'http://www.google.com';
|
||||||
|
await page.goto('./#/browse/mine', { waitUntil: 'networkidle' });
|
||||||
|
|
||||||
test.describe('Snapshot Menu tests', () => {
|
// Create Notebook
|
||||||
test.fixme('When no default notebook is selected, Snapshot Menu dropdown should only have a single option', async ({ page }) => {
|
const notebook = await createDomainObjectWithDefaults(page, {
|
||||||
// There should be no default notebook
|
type: 'Notebook',
|
||||||
// Clear default notebook if exists using `localStorage.setItem('notebook-storage', null);`
|
name: "Entry Link Test"
|
||||||
// refresh page
|
});
|
||||||
// Click on 'Notebook Snaphot Menu'
|
|
||||||
// 'save to Notebook Snapshots' should be only option there
|
|
||||||
});
|
|
||||||
test.fixme('When default notebook is updated selected, Snapshot Menu dropdown should list it as the newest option', async ({ page }) => {
|
|
||||||
// Create 2a notebooks
|
|
||||||
// Set Notebook A as Default
|
|
||||||
// Open Snapshot Menu and note that Notebook A is listed
|
|
||||||
// Close Snapshot Menu
|
|
||||||
// Set Default Notebook to Notebook B
|
|
||||||
// Open Snapshot Notebook and note that Notebook B is listed
|
|
||||||
// Select Default Notebook Option and verify that Snapshot is added to Notebook B
|
|
||||||
});
|
|
||||||
test.fixme('Can add Snapshots via Snapshot Menu and details are correct', async ({ page }) => {
|
|
||||||
//Note this should be a visual test, too
|
|
||||||
// Create Telemetry object
|
|
||||||
// Create A notebook with many pages and sections.
|
|
||||||
// Set page and section defaults to be between first and last of many. i.e. 3 of 5
|
|
||||||
// Navigate to Telemetry object
|
|
||||||
// Select Default Notebook Option and verify that Snapshot is added to Notebook A
|
|
||||||
// Verify Snapshot Details appear correctly
|
|
||||||
});
|
|
||||||
test.fixme('Snapshots adjust time conductor', async ({ page }) => {
|
|
||||||
// Create Telemetry object
|
|
||||||
// Set Telemetry object's timeconductor to Fixed time with Start and Endtimes are recorded
|
|
||||||
// Embed Telemetry object into notebook
|
|
||||||
// Set Time Conductor to Local clock
|
|
||||||
// Click into embedded telemetry object and verify object appears with same fixed time from record
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test.describe('Snapshot Container tests', () => {
|
await expandTreePaneItemByName(page, 'My Items');
|
||||||
test.fixme('5 Snapshots can be added to a container', async ({ page }) => {});
|
|
||||||
test.fixme('5 Snapshots can be added to a container and Deleted with Delete All action', async ({ page }) => {});
|
await page.goto(notebook.url);
|
||||||
test.fixme('A snapshot can be Deleted from Container', async ({ page }) => {});
|
|
||||||
test.fixme('A snapshot can be Previewed from Container', async ({ page }) => {});
|
await nbUtils.enterTextEntry(page, `This should be a link: ${TEST_LINK} is it?`);
|
||||||
test.fixme('A snapshot Container can be open and closed', async ({ page }) => {});
|
|
||||||
test.fixme('Can add object to Snapshot container and pull into notebook and create a new entry', async ({ page }) => {
|
const validLink = page.locator(`a[href="${TEST_LINK}"]`);
|
||||||
//Create Notebook
|
|
||||||
//Create Telemetry Object
|
// Start waiting for popup before clicking. Note no await.
|
||||||
//From Telemetry Object, use 'save to Notebook Snapshots'
|
const popupPromise = page.waitForEvent('popup');
|
||||||
//Snapshots indicator should blink, click on it to view snapshots
|
|
||||||
//Navigate to Notebook
|
await validLink.click();
|
||||||
//Drag and Drop onto droppable area for new entry
|
const popup = await popupPromise;
|
||||||
//New Entry created with given snapshot added
|
|
||||||
//Snapshot removed from container?
|
// Wait for the popup to load.
|
||||||
|
await popup.waitForLoadState();
|
||||||
|
expect.soft(popup.url()).toContain('www.google.com');
|
||||||
|
|
||||||
|
expect(await validLink.count()).toBe(1);
|
||||||
});
|
});
|
||||||
test.fixme('Can add object to Snapshot container and pull into notebook and existing entry', async ({ page }) => {
|
test.fixme('when an invalid link is entered into a notebook entry, it does not become clickable when viewing', async ({ page }) => {
|
||||||
//Create Notebook
|
const TEST_LINK = 'www.google.com';
|
||||||
//Create Telemetry Object
|
await page.goto('./#/browse/mine', { waitUntil: 'networkidle' });
|
||||||
//From Telemetry Object, use 'save to Notebook Snapshots'
|
|
||||||
//Snapshots indicator should blink, click on it to view snapshots
|
// Create Notebook
|
||||||
//Navigate to Notebook
|
const notebook = await createDomainObjectWithDefaults(page, {
|
||||||
//Drag and Drop into exiting entry
|
type: 'Notebook',
|
||||||
//Existing Entry updated with given snapshot
|
name: "Entry Link Test"
|
||||||
//Snapshot removed from container?
|
});
|
||||||
|
|
||||||
|
await expandTreePaneItemByName(page, 'My Items');
|
||||||
|
|
||||||
|
await page.goto(notebook.url);
|
||||||
|
|
||||||
|
await nbUtils.enterTextEntry(page, `This should NOT be a link: ${TEST_LINK} is it?`);
|
||||||
|
|
||||||
|
const invalidLink = page.locator(`a[href="${TEST_LINK}"]`);
|
||||||
|
|
||||||
|
expect(await invalidLink.count()).toBe(0);
|
||||||
});
|
});
|
||||||
test.fixme('Verify Embedded options for PNG, JPG, and Annotate work correctly', async ({ page }) => {
|
test.fixme('when a nefarious link is entered into a notebook entry, it is sanitized when viewing', async ({ page }) => {
|
||||||
//Add snapshot to container
|
const TEST_LINK = 'http://www.google.com?bad=';
|
||||||
//Verify PNG, JPG, and Annotate buttons work correctly
|
const TEST_LINK_BAD = `http://www.google.com?bad=<script>alert('gimme your cookies')</script>`;
|
||||||
|
await page.goto('./#/browse/mine', { waitUntil: 'networkidle' });
|
||||||
|
|
||||||
|
// Create Notebook
|
||||||
|
const notebook = await createDomainObjectWithDefaults(page, {
|
||||||
|
type: 'Notebook',
|
||||||
|
name: "Entry Link Test"
|
||||||
|
});
|
||||||
|
|
||||||
|
await expandTreePaneItemByName(page, 'My Items');
|
||||||
|
|
||||||
|
await page.goto(notebook.url);
|
||||||
|
|
||||||
|
await nbUtils.enterTextEntry(page, `This should be a link, BUT not a bad link: ${TEST_LINK_BAD} is it?`);
|
||||||
|
|
||||||
|
const sanitizedLink = page.locator(`a[href="${TEST_LINK}"]`);
|
||||||
|
const unsanitizedLink = page.locator(`a[href="${TEST_LINK_BAD}"]`);
|
||||||
|
|
||||||
|
expect.soft(await sanitizedLink.count()).toBe(1);
|
||||||
|
expect(await unsanitizedLink.count()).toBe(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,134 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* 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.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
This test suite is dedicated to tests which verify the basic operations surrounding Notebooks.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const { test, expect } = require('../../../../pluginFixtures');
|
||||||
|
// const { expandTreePaneItemByName, createDomainObjectWithDefaults } = require('../../../../appActions');
|
||||||
|
// const nbUtils = require('../../../../helper/notebookUtils');
|
||||||
|
|
||||||
|
test.describe('Snapshot Menu tests', () => {
|
||||||
|
test.fixme('When no default notebook is selected, Snapshot Menu dropdown should only have a single option', async ({ page }) => {
|
||||||
|
// There should be no default notebook
|
||||||
|
// Clear default notebook if exists using `localStorage.setItem('notebook-storage', null);`
|
||||||
|
// refresh page
|
||||||
|
// Click on 'Notebook Snaphot Menu'
|
||||||
|
// 'save to Notebook Snapshots' should be only option there
|
||||||
|
});
|
||||||
|
test.fixme('When default notebook is updated selected, Snapshot Menu dropdown should list it as the newest option', async ({ page }) => {
|
||||||
|
// Create 2a notebooks
|
||||||
|
// Set Notebook A as Default
|
||||||
|
// Open Snapshot Menu and note that Notebook A is listed
|
||||||
|
// Close Snapshot Menu
|
||||||
|
// Set Default Notebook to Notebook B
|
||||||
|
// Open Snapshot Notebook and note that Notebook B is listed
|
||||||
|
// Select Default Notebook Option and verify that Snapshot is added to Notebook B
|
||||||
|
});
|
||||||
|
test.fixme('Can add Snapshots via Snapshot Menu and details are correct', async ({ page }) => {
|
||||||
|
//Note this should be a visual test, too
|
||||||
|
// Create Telemetry object
|
||||||
|
// Create A notebook with many pages and sections.
|
||||||
|
// Set page and section defaults to be between first and last of many. i.e. 3 of 5
|
||||||
|
// Navigate to Telemetry object
|
||||||
|
// Select Default Notebook Option and verify that Snapshot is added to Notebook A
|
||||||
|
// Verify Snapshot Details appear correctly
|
||||||
|
});
|
||||||
|
test.fixme('Snapshots adjust time conductor', async ({ page }) => {
|
||||||
|
// Create Telemetry object
|
||||||
|
// Set Telemetry object's timeconductor to Fixed time with Start and Endtimes are recorded
|
||||||
|
// Embed Telemetry object into notebook
|
||||||
|
// Set Time Conductor to Local clock
|
||||||
|
// Click into embedded telemetry object and verify object appears with same fixed time from record
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test.describe('Snapshot Container tests', () => {
|
||||||
|
test.beforeEach(async ({ page }) => {
|
||||||
|
//Navigate to baseURL
|
||||||
|
await page.goto('./', { waitUntil: 'networkidle' });
|
||||||
|
|
||||||
|
// Create Notebook
|
||||||
|
// const notebook = await createDomainObjectWithDefaults(page, {
|
||||||
|
// type: 'Notebook',
|
||||||
|
// name: "Test Notebook"
|
||||||
|
// });
|
||||||
|
// // Create Overlay Plot
|
||||||
|
// const snapShotObject = await createDomainObjectWithDefaults(page, {
|
||||||
|
// type: 'Overlay Plot',
|
||||||
|
// name: "Dropped Overlay Plot"
|
||||||
|
// });
|
||||||
|
|
||||||
|
await page.getByRole('button', { name: ' Snapshot ' }).click();
|
||||||
|
await page.getByRole('menuitem', { name: ' Save to Notebook Snapshots' }).click();
|
||||||
|
await page.getByRole('button', { name: 'Show' }).click();
|
||||||
|
|
||||||
|
});
|
||||||
|
test.fixme('5 Snapshots can be added to a container', async ({ page }) => {});
|
||||||
|
test.fixme('5 Snapshots can be added to a container and Deleted with Delete All action', async ({ page }) => {});
|
||||||
|
test.fixme('A snapshot can be Deleted from Container with 3 dot action menu', async ({ page }) => {});
|
||||||
|
test.fixme('A snapshot can be Viewed, Annotated, display deleted, and saved from Container with 3 dot action menu', async ({ page }) => {
|
||||||
|
await page.locator('.c-snapshot.c-ne__embed').first().getByTitle('More options').click();
|
||||||
|
await page.getByRole('menuitem', { name: ' View Snapshot' }).click();
|
||||||
|
await expect(page.locator('.c-overlay__outer')).toBeVisible();
|
||||||
|
await page.getByTitle('Annotate').click();
|
||||||
|
await expect(page.locator('#snap-annotation-canvas')).toBeVisible();
|
||||||
|
await page.getByRole('button', { name: '' }).click();
|
||||||
|
// await expect(page.locator('#snap-annotation-canvas')).not.toBeVisible();
|
||||||
|
await page.getByRole('button', { name: 'Save' }).click();
|
||||||
|
await page.getByRole('button', { name: 'Done' }).click();
|
||||||
|
//await expect(await page.locator)
|
||||||
|
});
|
||||||
|
test('A snapshot can be Quick Viewed from Container with 3 dot action menu', async ({ page }) => {
|
||||||
|
await page.locator('.c-snapshot.c-ne__embed').first().getByTitle('More options').click();
|
||||||
|
await page.getByRole('menuitem', { name: 'Quick View' }).click();
|
||||||
|
await expect(page.locator('.c-overlay__outer')).toBeVisible();
|
||||||
|
});
|
||||||
|
test.fixme('A snapshot can be Navigated To from Container with 3 dot action menu', async ({ page }) => {});
|
||||||
|
test.fixme('A snapshot can be Navigated To Item in Time from Container with 3 dot action menu', async ({ page }) => {});
|
||||||
|
test.fixme('A snapshot Container can be open and closed', async ({ page }) => {});
|
||||||
|
test.fixme('Can add object to Snapshot container and pull into notebook and create a new entry', async ({ page }) => {
|
||||||
|
//Create Notebook
|
||||||
|
//Create Telemetry Object
|
||||||
|
//From Telemetry Object, use 'save to Notebook Snapshots'
|
||||||
|
//Snapshots indicator should blink, click on it to view snapshots
|
||||||
|
//Navigate to Notebook
|
||||||
|
//Drag and Drop onto droppable area for new entry
|
||||||
|
//New Entry created with given snapshot added
|
||||||
|
//Snapshot removed from container?
|
||||||
|
});
|
||||||
|
test.fixme('Can add object to Snapshot container and pull into notebook and existing entry', async ({ page }) => {
|
||||||
|
//Create Notebook
|
||||||
|
//Create Telemetry Object
|
||||||
|
//From Telemetry Object, use 'save to Notebook Snapshots'
|
||||||
|
//Snapshots indicator should blink, click on it to view snapshots
|
||||||
|
//Navigate to Notebook
|
||||||
|
//Drag and Drop into exiting entry
|
||||||
|
//Existing Entry updated with given snapshot
|
||||||
|
//Snapshot removed from container?
|
||||||
|
});
|
||||||
|
test.fixme('Verify Embedded options for PNG, JPG, and Annotate work correctly', async ({ page }) => {
|
||||||
|
//Add snapshot to container
|
||||||
|
//Verify PNG, JPG, and Annotate buttons work correctly
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
This test suite is dedicated to tests which verify the basic operations surrounding Notebooks with CouchDB.
|
This test suite is dedicated to tests which verify the basic operations surrounding Notebooks with CouchDB.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const { test, expect } = require('../../../../baseFixtures');
|
const { test, expect } = require('../../../../pluginFixtures');
|
||||||
const { createDomainObjectWithDefaults } = require('../../../../appActions');
|
const { createDomainObjectWithDefaults } = require('../../../../appActions');
|
||||||
|
|
||||||
test.describe('Notebook Tests with CouchDB @couchdb', () => {
|
test.describe('Notebook Tests with CouchDB @couchdb', () => {
|
||||||
@@ -76,6 +76,7 @@ test.describe('Notebook Tests with CouchDB @couchdb', () => {
|
|||||||
await page.locator('text=To start a new entry, click here or drag and drop any object').click();
|
await page.locator('text=To start a new entry, click here or drag and drop any object').click();
|
||||||
await page.locator('[aria-label="Notebook Entry Input"]').click();
|
await page.locator('[aria-label="Notebook Entry Input"]').click();
|
||||||
await page.locator('[aria-label="Notebook Entry Input"]').fill(`First Entry`);
|
await page.locator('[aria-label="Notebook Entry Input"]').fill(`First Entry`);
|
||||||
|
await page.locator('[aria-label="Notebook Entry Input"]').press('Enter');
|
||||||
await page.waitForLoadState('networkidle');
|
await page.waitForLoadState('networkidle');
|
||||||
expect(addingNotebookElementsRequests.length).toBeLessThanOrEqual(2);
|
expect(addingNotebookElementsRequests.length).toBeLessThanOrEqual(2);
|
||||||
|
|
||||||
@@ -148,14 +149,17 @@ test.describe('Notebook Tests with CouchDB @couchdb', () => {
|
|||||||
await page.locator('text=To start a new entry, click here or drag and drop any object').click();
|
await page.locator('text=To start a new entry, click here or drag and drop any object').click();
|
||||||
await page.locator('[aria-label="Notebook Entry Input"]').click();
|
await page.locator('[aria-label="Notebook Entry Input"]').click();
|
||||||
await page.locator('[aria-label="Notebook Entry Input"]').fill(`First Entry`);
|
await page.locator('[aria-label="Notebook Entry Input"]').fill(`First Entry`);
|
||||||
|
await page.locator('[aria-label="Notebook Entry Input"]').press('Enter');
|
||||||
|
|
||||||
await page.locator('text=To start a new entry, click here or drag and drop any object').click();
|
await page.locator('text=To start a new entry, click here or drag and drop any object').click();
|
||||||
await page.locator('[aria-label="Notebook Entry Input"] >> nth=1').click();
|
await page.locator('[aria-label="Notebook Entry Input"] >> nth=1').click();
|
||||||
await page.locator('[aria-label="Notebook Entry Input"] >> nth=1').fill(`Second Entry`);
|
await page.locator('[aria-label="Notebook Entry Input"] >> nth=1').fill(`Second Entry`);
|
||||||
|
await page.locator('[aria-label="Notebook Entry Input"] >> nth=1').press('Enter');
|
||||||
|
|
||||||
await page.locator('text=To start a new entry, click here or drag and drop any object').click();
|
await page.locator('text=To start a new entry, click here or drag and drop any object').click();
|
||||||
await page.locator('[aria-label="Notebook Entry Input"] >> nth=2').click();
|
await page.locator('[aria-label="Notebook Entry Input"] >> nth=2').click();
|
||||||
await page.locator('[aria-label="Notebook Entry Input"] >> nth=2').fill(`Third Entry`);
|
await page.locator('[aria-label="Notebook Entry Input"] >> nth=2').fill(`Third Entry`);
|
||||||
|
await page.locator('[aria-label="Notebook Entry Input"] >> nth=2').press('Enter');
|
||||||
|
|
||||||
// Add three tags
|
// Add three tags
|
||||||
await page.hover(`button:has-text("Add Tag") >> nth=2`);
|
await page.hover(`button:has-text("Add Tag") >> nth=2`);
|
||||||
|
|||||||
@@ -36,27 +36,27 @@ test.describe('Restricted Notebook', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Can be renamed @addInit', async ({ page }) => {
|
test('Can be renamed @addInit', async ({ page }) => {
|
||||||
await expect(page.locator('.l-browse-bar__object-name')).toContainText(`Unnamed ${CUSTOM_NAME}`);
|
await expect(page.locator('.l-browse-bar__object-name')).toContainText(`${notebook.name}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Can be deleted if there are no locked pages @addInit', async ({ page, openmctConfig }) => {
|
test('Can be deleted if there are no locked pages @addInit', async ({ page }) => {
|
||||||
await openObjectTreeContextMenu(page, notebook.url);
|
await openObjectTreeContextMenu(page, notebook.url);
|
||||||
|
|
||||||
const menuOptions = page.locator('.c-menu ul');
|
const menuOptions = page.locator('.c-menu ul');
|
||||||
await expect.soft(menuOptions).toContainText('Remove');
|
await expect.soft(menuOptions).toContainText('Remove');
|
||||||
|
|
||||||
const restrictedNotebookTreeObject = page.locator(`a:has-text("Unnamed ${CUSTOM_NAME}")`);
|
const restrictedNotebookTreeObject = page.locator(`a:has-text("${notebook.name}")`);
|
||||||
|
|
||||||
// notebook tree object exists
|
// notebook tree object exists
|
||||||
expect.soft(await restrictedNotebookTreeObject.count()).toEqual(1);
|
expect.soft(await restrictedNotebookTreeObject.count()).toEqual(1);
|
||||||
|
|
||||||
// Click Remove Text
|
// Click Remove Text
|
||||||
await page.locator('text=Remove').click();
|
await page.locator('li[role="menuitem"]:has-text("Remove")').click();
|
||||||
|
|
||||||
// Click 'OK' on confirmation window and wait for save banner to appear
|
// Click 'OK' on confirmation window and wait for save banner to appear
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
page.waitForNavigation(),
|
page.waitForNavigation(),
|
||||||
page.locator('text=OK').click(),
|
page.locator('button:has-text("OK")').click(),
|
||||||
page.waitForSelector('.c-message-banner__message')
|
page.waitForSelector('.c-message-banner__message')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -134,7 +134,7 @@ test.describe('Restricted Notebook with at least one entry and with the page loc
|
|||||||
// Click text=Ok
|
// Click text=Ok
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
page.waitForNavigation(),
|
page.waitForNavigation(),
|
||||||
page.locator('text=Ok').click()
|
page.locator('button:has-text("OK")').click()
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// deleted page, should no longer exist
|
// deleted page, should no longer exist
|
||||||
@@ -145,15 +145,14 @@ test.describe('Restricted Notebook with at least one entry and with the page loc
|
|||||||
|
|
||||||
test.describe('Restricted Notebook with a page locked and with an embed @addInit', () => {
|
test.describe('Restricted Notebook with a page locked and with an embed @addInit', () => {
|
||||||
|
|
||||||
test.beforeEach(async ({ page, openmctConfig }) => {
|
test.beforeEach(async ({ page }) => {
|
||||||
const { myItemsFolderName } = openmctConfig;
|
const notebook = await startAndAddRestrictedNotebookObject(page);
|
||||||
await startAndAddRestrictedNotebookObject(page);
|
await nbUtils.dragAndDropEmbed(page, notebook);
|
||||||
await nbUtils.dragAndDropEmbed(page, myItemsFolderName);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Allows embeds to be deleted if page unlocked @addInit', async ({ page }) => {
|
test('Allows embeds to be deleted if page unlocked @addInit', async ({ page }) => {
|
||||||
// Click .c-ne__embed__name .c-popup-menu-button
|
// Click .c-ne__embed__name .c-popup-menu-button
|
||||||
await page.locator('.c-ne__embed__name .c-popup-menu-button').click(); // embed popup menu
|
await page.locator('.c-ne__embed__name .c-icon-button').click(); // embed popup menu
|
||||||
|
|
||||||
const embedMenu = page.locator('body >> .c-menu');
|
const embedMenu = page.locator('body >> .c-menu');
|
||||||
await expect(embedMenu).toContainText('Remove This Embed');
|
await expect(embedMenu).toContainText('Remove This Embed');
|
||||||
@@ -162,7 +161,7 @@ test.describe('Restricted Notebook with a page locked and with an embed @addInit
|
|||||||
test('Disallows embeds to be deleted if page locked @addInit', async ({ page }) => {
|
test('Disallows embeds to be deleted if page locked @addInit', async ({ page }) => {
|
||||||
await lockPage(page);
|
await lockPage(page);
|
||||||
// Click .c-ne__embed__name .c-popup-menu-button
|
// Click .c-ne__embed__name .c-popup-menu-button
|
||||||
await page.locator('.c-ne__embed__name .c-popup-menu-button').click(); // embed popup menu
|
await page.locator('.c-ne__embed__name .c-icon-button').click(); // embed popup menu
|
||||||
|
|
||||||
const embedMenu = page.locator('body >> .c-menu');
|
const embedMenu = page.locator('body >> .c-menu');
|
||||||
await expect(embedMenu).not.toContainText('Remove This Embed');
|
await expect(embedMenu).not.toContainText('Remove This Embed');
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ async function createNotebookAndEntry(page, iterations = 1) {
|
|||||||
//Go to baseURL
|
//Go to baseURL
|
||||||
await page.goto('./', { waitUntil: 'networkidle' });
|
await page.goto('./', { waitUntil: 'networkidle' });
|
||||||
|
|
||||||
createDomainObjectWithDefaults(page, { type: 'Notebook' });
|
const notebook = createDomainObjectWithDefaults(page, { type: 'Notebook' });
|
||||||
|
|
||||||
for (let iteration = 0; iteration < iterations; iteration++) {
|
for (let iteration = 0; iteration < iterations; iteration++) {
|
||||||
// Create an entry
|
// Create an entry
|
||||||
@@ -44,7 +44,10 @@ async function createNotebookAndEntry(page, iterations = 1) {
|
|||||||
const entryLocator = `[aria-label="Notebook Entry Input"] >> nth = ${iteration}`;
|
const entryLocator = `[aria-label="Notebook Entry Input"] >> nth = ${iteration}`;
|
||||||
await page.locator(entryLocator).click();
|
await page.locator(entryLocator).click();
|
||||||
await page.locator(entryLocator).fill(`Entry ${iteration}`);
|
await page.locator(entryLocator).fill(`Entry ${iteration}`);
|
||||||
|
await page.locator(entryLocator).press('Enter');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return notebook;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,13 +56,15 @@ async function createNotebookAndEntry(page, iterations = 1) {
|
|||||||
* @param {number} [iterations = 1] - the number of entries (and tags) to create
|
* @param {number} [iterations = 1] - the number of entries (and tags) to create
|
||||||
*/
|
*/
|
||||||
async function createNotebookEntryAndTags(page, iterations = 1) {
|
async function createNotebookEntryAndTags(page, iterations = 1) {
|
||||||
await createNotebookAndEntry(page, iterations);
|
const notebook = await createNotebookAndEntry(page, iterations);
|
||||||
|
await page.locator('text=Annotations').click();
|
||||||
|
|
||||||
for (let iteration = 0; iteration < iterations; iteration++) {
|
for (let iteration = 0; iteration < iterations; iteration++) {
|
||||||
// Hover and click "Add Tag" button
|
// Hover and click "Add Tag" button
|
||||||
// Hover is needed here to "slow down" the actions while running in headless mode
|
// Hover is needed here to "slow down" the actions while running in headless mode
|
||||||
await page.hover(`button:has-text("Add Tag") >> nth = ${iteration}`);
|
await page.locator(`[aria-label="Notebook Entry"] >> nth = ${iteration}`).click();
|
||||||
await page.locator(`button:has-text("Add Tag") >> 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
|
// Click inside the tag search input
|
||||||
await page.locator('[placeholder="Type to select tag"]').click();
|
await page.locator('[placeholder="Type to select tag"]').click();
|
||||||
@@ -68,19 +73,23 @@ async function createNotebookEntryAndTags(page, iterations = 1) {
|
|||||||
|
|
||||||
// Hover and click "Add Tag" button
|
// Hover and click "Add Tag" button
|
||||||
// Hover is needed here to "slow down" the actions while running in headless mode
|
// Hover is needed here to "slow down" the actions while running in headless mode
|
||||||
await page.hover(`button:has-text("Add Tag") >> nth = ${iteration}`);
|
await page.hover(`button:has-text("Add Tag")`);
|
||||||
await page.locator(`button:has-text("Add Tag") >> nth = ${iteration}`).click();
|
await page.locator(`button:has-text("Add Tag")`).click();
|
||||||
// Click inside the tag search input
|
// Click inside the tag search input
|
||||||
await page.locator('[placeholder="Type to select tag"]').click();
|
await page.locator('[placeholder="Type to select tag"]').click();
|
||||||
// Select the "Science" tag
|
// Select the "Science" tag
|
||||||
await page.locator('[aria-label="Autocomplete Options"] >> text=Science').click();
|
await page.locator('[aria-label="Autocomplete Options"] >> text=Science').click();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return notebook;
|
||||||
}
|
}
|
||||||
|
|
||||||
test.describe('Tagging in Notebooks @addInit', () => {
|
test.describe('Tagging in Notebooks @addInit', () => {
|
||||||
test('Can load tags', async ({ page }) => {
|
test('Can load tags', async ({ page }) => {
|
||||||
|
|
||||||
await createNotebookAndEntry(page);
|
await createNotebookAndEntry(page);
|
||||||
|
|
||||||
|
await page.locator('text=Annotations').click();
|
||||||
|
|
||||||
await page.locator('button:has-text("Add Tag")').click();
|
await page.locator('button:has-text("Add Tag")').click();
|
||||||
|
|
||||||
await page.locator('[placeholder="Type to select tag"]').click();
|
await page.locator('[placeholder="Type to select tag"]').click();
|
||||||
@@ -121,13 +130,12 @@ test.describe('Tagging in Notebooks @addInit', () => {
|
|||||||
|
|
||||||
test('Can delete tags', async ({ page }) => {
|
test('Can delete tags', async ({ page }) => {
|
||||||
await createNotebookEntryAndTags(page);
|
await createNotebookEntryAndTags(page);
|
||||||
await page.locator('[aria-label="Notebook Entries"]').click();
|
|
||||||
// Delete Driving
|
// Delete Driving
|
||||||
await page.hover('[aria-label="Tag"]:has-text("Driving")');
|
await page.hover('[aria-label="Tag"]:has-text("Driving")');
|
||||||
await page.locator('[aria-label="Tag"]:has-text("Driving") ~ .c-completed-tag-deletion').click();
|
await page.locator('[aria-label="Tag"]:has-text("Driving") ~ .c-completed-tag-deletion').click();
|
||||||
|
|
||||||
await expect(page.locator('[aria-label="Notebook Entry"]')).toContainText("Science");
|
await expect(page.locator('[aria-label="Tags Inspector"]')).toContainText("Science");
|
||||||
await expect(page.locator('[aria-label="Notebook Entry"]')).not.toContainText("Driving");
|
await expect(page.locator('[aria-label="Tags Inspector"]')).not.toContainText("Driving");
|
||||||
|
|
||||||
await page.locator('[aria-label="OpenMCT Search"] input[type="search"]').fill('sc');
|
await page.locator('[aria-label="OpenMCT Search"] input[type="search"]').fill('sc');
|
||||||
await expect(page.locator('[aria-label="Search Result"]')).not.toContainText("Driving");
|
await expect(page.locator('[aria-label="Search Result"]')).not.toContainText("Driving");
|
||||||
@@ -173,10 +181,10 @@ test.describe('Tagging in Notebooks @addInit', () => {
|
|||||||
//Go to baseURL
|
//Go to baseURL
|
||||||
await page.goto('./', { waitUntil: 'networkidle' });
|
await page.goto('./', { waitUntil: 'networkidle' });
|
||||||
|
|
||||||
await createDomainObjectWithDefaults(page, { type: 'Clock' });
|
const clock = await createDomainObjectWithDefaults(page, { type: 'Clock' });
|
||||||
|
|
||||||
const ITERATIONS = 4;
|
const ITERATIONS = 4;
|
||||||
await createNotebookEntryAndTags(page, ITERATIONS);
|
const notebook = await createNotebookEntryAndTags(page, ITERATIONS);
|
||||||
|
|
||||||
for (let iteration = 0; iteration < ITERATIONS; iteration++) {
|
for (let iteration = 0; iteration < ITERATIONS; iteration++) {
|
||||||
const entryLocator = `[aria-label="Notebook Entry"] >> nth = ${iteration}`;
|
const entryLocator = `[aria-label="Notebook Entry"] >> nth = ${iteration}`;
|
||||||
@@ -189,11 +197,16 @@ test.describe('Tagging in Notebooks @addInit', () => {
|
|||||||
page.goto('./#/browse/mine?hideTree=false'),
|
page.goto('./#/browse/mine?hideTree=false'),
|
||||||
page.click('.c-disclosure-triangle')
|
page.click('.c-disclosure-triangle')
|
||||||
]);
|
]);
|
||||||
// Click Unnamed Clock
|
|
||||||
await page.click('text="Unnamed Clock"');
|
|
||||||
|
|
||||||
// Click Unnamed Notebook
|
const treePane = page.locator('#tree-pane');
|
||||||
await page.click('text="Unnamed Notebook"');
|
// Click Clock
|
||||||
|
await treePane.getByRole('treeitem', {
|
||||||
|
name: clock.name
|
||||||
|
}).click();
|
||||||
|
// Click Notebook
|
||||||
|
await page.getByRole('treeitem', {
|
||||||
|
name: notebook.name
|
||||||
|
}).click();
|
||||||
|
|
||||||
for (let iteration = 0; iteration < ITERATIONS; iteration++) {
|
for (let iteration = 0; iteration < ITERATIONS; iteration++) {
|
||||||
const entryLocator = `[aria-label="Notebook Entry"] >> nth = ${iteration}`;
|
const entryLocator = `[aria-label="Notebook Entry"] >> nth = ${iteration}`;
|
||||||
@@ -207,14 +220,13 @@ test.describe('Tagging in Notebooks @addInit', () => {
|
|||||||
page.waitForLoadState('networkidle')
|
page.waitForLoadState('networkidle')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Click Unnamed Notebook
|
// Click Notebook
|
||||||
await page.click('text="Unnamed Notebook"');
|
await page.click(`text="${notebook.name}"`);
|
||||||
|
|
||||||
for (let iteration = 0; iteration < ITERATIONS; iteration++) {
|
for (let iteration = 0; iteration < ITERATIONS; iteration++) {
|
||||||
const entryLocator = `[aria-label="Notebook Entry"] >> nth = ${iteration}`;
|
const entryLocator = `[aria-label="Notebook Entry"] >> nth = ${iteration}`;
|
||||||
await expect(page.locator(entryLocator)).toContainText("Science");
|
await expect(page.locator(entryLocator)).toContainText("Science");
|
||||||
await expect(page.locator(entryLocator)).toContainText("Driving");
|
await expect(page.locator(entryLocator)).toContainText("Driving");
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,156 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* 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.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This test suite is dedicated to testing the operator status plugin.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
const { test, expect } = require('../../../../pluginFixtures');
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
Precondition: Inject Example User, Operator Status Plugins
|
||||||
|
Verify that user 1 sees updates from user/role 2 (Not possible without openmct-yamcs implementation)
|
||||||
|
|
||||||
|
Clear Role Status of single user test
|
||||||
|
STUB (test.fixme) Rolling through each
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
test.describe('Operator Status', () => {
|
||||||
|
test.beforeEach(async ({ page }) => {
|
||||||
|
// FIXME: determine if plugins will be added to index.html or need to be injected
|
||||||
|
// eslint-disable-next-line no-undef
|
||||||
|
await page.addInitScript({ path: path.join(__dirname, '../../../../helper/', 'addInitExampleUser.js')});
|
||||||
|
// eslint-disable-next-line no-undef
|
||||||
|
await page.addInitScript({ path: path.join(__dirname, '../../../../helper/', 'addInitOperatorStatus.js')});
|
||||||
|
await page.goto('./', { waitUntil: 'networkidle' });
|
||||||
|
});
|
||||||
|
|
||||||
|
// verify that operator status is visible
|
||||||
|
test('operator status is visible and expands when clicked', async ({ page }) => {
|
||||||
|
await expect(page.locator('div[title="Set my operator status"]')).toBeVisible();
|
||||||
|
await page.locator('div[title="Set my operator status"]').click();
|
||||||
|
|
||||||
|
// expect default status to be 'GO'
|
||||||
|
await expect(page.locator('.c-status-poll-panel')).toBeVisible();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('poll question indicator remains when blank poll set', async ({ page }) => {
|
||||||
|
await expect(page.locator('div[title="Set the current poll question"]')).toBeVisible();
|
||||||
|
await page.locator('div[title="Set the current poll question"]').click();
|
||||||
|
// set to blank
|
||||||
|
await page.getByRole('button', { name: 'Update' }).click();
|
||||||
|
|
||||||
|
// should still be visible
|
||||||
|
await expect(page.locator('div[title="Set the current poll question"]')).toBeVisible();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Verify that user 1 sees updates from user/role 2 (Not possible without openmct-yamcs implementation)
|
||||||
|
test('operator status table reflects answered values', async ({ page }) => {
|
||||||
|
// user navigates to operator status poll
|
||||||
|
const statusPollIndicator = page.locator('div[title="Set my operator status"]');
|
||||||
|
await statusPollIndicator.click();
|
||||||
|
|
||||||
|
// get user role value
|
||||||
|
const userRole = page.locator('.c-status-poll-panel__user-role');
|
||||||
|
const userRoleText = await userRole.innerText();
|
||||||
|
|
||||||
|
// get selected status value
|
||||||
|
const selectStatus = page.locator('select[name="setStatus"]');
|
||||||
|
await selectStatus.selectOption({ index: 1});
|
||||||
|
const initialStatusValue = await selectStatus.inputValue();
|
||||||
|
|
||||||
|
// open manage status poll
|
||||||
|
const manageStatusPollIndicator = page.locator('div[title="Set the current poll question"]');
|
||||||
|
await manageStatusPollIndicator.click();
|
||||||
|
// parse the table row values
|
||||||
|
const row = page.locator(`tr:has-text("${userRoleText}")`);
|
||||||
|
const rowValues = await row.innerText();
|
||||||
|
const rowValuesArr = rowValues.split('\t');
|
||||||
|
const COLUMN_STATUS_INDEX = 1;
|
||||||
|
// check initial set value matches status table
|
||||||
|
expect(rowValuesArr[COLUMN_STATUS_INDEX].toLowerCase())
|
||||||
|
.toEqual(initialStatusValue.toLowerCase());
|
||||||
|
|
||||||
|
// change user status
|
||||||
|
await statusPollIndicator.click();
|
||||||
|
// FIXME: might want to grab a dynamic option instead of arbitrary
|
||||||
|
await page.locator('select[name="setStatus"]').selectOption({ index: 2});
|
||||||
|
const updatedStatusValue = await selectStatus.inputValue();
|
||||||
|
// verify user status is reflected in table
|
||||||
|
await manageStatusPollIndicator.click();
|
||||||
|
|
||||||
|
const updatedRow = page.locator(`tr:has-text("${userRoleText}")`);
|
||||||
|
const updatedRowValues = await updatedRow.innerText();
|
||||||
|
const updatedRowValuesArr = updatedRowValues.split('\t');
|
||||||
|
|
||||||
|
expect(updatedRowValuesArr[COLUMN_STATUS_INDEX].toLowerCase())
|
||||||
|
.toEqual(updatedStatusValue.toLowerCase());
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
test('clear poll button removes poll responses', async ({ page }) => {
|
||||||
|
// user navigates to operator status poll
|
||||||
|
const statusPollIndicator = page.locator('div[title="Set my operator status"]');
|
||||||
|
await statusPollIndicator.click();
|
||||||
|
|
||||||
|
// get user role value
|
||||||
|
const userRole = page.locator('.c-status-poll-panel__user-role');
|
||||||
|
const userRoleText = await userRole.innerText();
|
||||||
|
|
||||||
|
// get selected status value
|
||||||
|
const selectStatus = page.locator('select[name="setStatus"]');
|
||||||
|
// FIXME: might want to grab a dynamic option instead of arbitrary
|
||||||
|
await selectStatus.selectOption({ index: 1});
|
||||||
|
const initialStatusValue = await selectStatus.inputValue();
|
||||||
|
|
||||||
|
// open manage status poll
|
||||||
|
const manageStatusPollIndicator = page.locator('div[title="Set the current poll question"]');
|
||||||
|
await manageStatusPollIndicator.click();
|
||||||
|
// parse the table row values
|
||||||
|
const row = page.locator(`tr:has-text("${userRoleText}")`);
|
||||||
|
const rowValues = await row.innerText();
|
||||||
|
const rowValuesArr = rowValues.split('\t');
|
||||||
|
const COLUMN_STATUS_INDEX = 1;
|
||||||
|
// check initial set value matches status table
|
||||||
|
expect(rowValuesArr[COLUMN_STATUS_INDEX].toLowerCase())
|
||||||
|
.toEqual(initialStatusValue.toLowerCase());
|
||||||
|
|
||||||
|
// clear the poll
|
||||||
|
await page.locator('button[title="Clear the previous poll question"]').click();
|
||||||
|
|
||||||
|
const updatedRow = page.locator(`tr:has-text("${userRoleText}")`);
|
||||||
|
const updatedRowValues = await updatedRow.innerText();
|
||||||
|
const updatedRowValuesArr = updatedRowValues.split('\t');
|
||||||
|
const UNSET_VALUE_LABEL = 'Not set';
|
||||||
|
expect(updatedRowValuesArr[COLUMN_STATUS_INDEX])
|
||||||
|
.toEqual(UNSET_VALUE_LABEL);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
test.fixme('iterate through all possible response values', async ({ page }) => {
|
||||||
|
// test all possible respone values for the poll
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
@@ -32,7 +32,7 @@ test.use({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test.describe('ExportAsJSON', () => {
|
test.fixme('ExportAsJSON', () => {
|
||||||
test('User can set autoscale with a valid range @snapshot', async ({ page, openmctConfig }) => {
|
test('User can set autoscale with a valid range @snapshot', async ({ page, openmctConfig }) => {
|
||||||
const { myItemsFolderName } = openmctConfig;
|
const { myItemsFolderName } = openmctConfig;
|
||||||
|
|
||||||
@@ -110,10 +110,10 @@ async function createSinewaveOverlayPlot(page, myItemsFolderName) {
|
|||||||
await page.locator('button:has-text("Create")').click();
|
await page.locator('button:has-text("Create")').click();
|
||||||
|
|
||||||
// add overlay plot with defaults
|
// add overlay plot with defaults
|
||||||
await page.locator('li:has-text("Overlay Plot")').click();
|
await page.locator('li[role="menuitem"]:has-text("Overlay Plot")').click();
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
page.waitForNavigation(),
|
page.waitForNavigation(),
|
||||||
page.locator('text=OK').click(),
|
page.locator('button:has-text("OK")').click(),
|
||||||
//Wait for Save Banner to appear1
|
//Wait for Save Banner to appear1
|
||||||
page.waitForSelector('.c-message-banner__message')
|
page.waitForSelector('.c-message-banner__message')
|
||||||
]);
|
]);
|
||||||
@@ -129,10 +129,10 @@ async function createSinewaveOverlayPlot(page, myItemsFolderName) {
|
|||||||
await page.locator('button:has-text("Create")').click();
|
await page.locator('button:has-text("Create")').click();
|
||||||
|
|
||||||
// add sine wave generator with defaults
|
// add sine wave generator with defaults
|
||||||
await page.locator('li:has-text("Sine Wave Generator")').click();
|
await page.locator('li[role="menuitem"]:has-text("Sine Wave Generator")').click();
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
page.waitForNavigation(),
|
page.waitForNavigation(),
|
||||||
page.locator('text=OK').click(),
|
page.locator('button:has-text("OK")').click(),
|
||||||
//Wait for Save Banner to appear1
|
//Wait for Save Banner to appear1
|
||||||
page.waitForSelector('.c-message-banner__message')
|
page.waitForSelector('.c-message-banner__message')
|
||||||
]);
|
]);
|
||||||
@@ -156,7 +156,7 @@ async function turnOffAutoscale(page) {
|
|||||||
await page.locator('text=Unnamed Overlay Plot Snapshot >> button').nth(3).click();
|
await page.locator('text=Unnamed Overlay Plot Snapshot >> button').nth(3).click();
|
||||||
|
|
||||||
// uncheck autoscale
|
// uncheck autoscale
|
||||||
await page.locator('text=Y Axis Label Log mode Auto scale Padding >> input[type="checkbox"] >> nth=1').uncheck();
|
await page.getByRole('listitem').filter({ hasText: 'Auto scale' }).getByRole('checkbox').uncheck();
|
||||||
|
|
||||||
// save
|
// save
|
||||||
await page.locator('text=Snapshot Save and Finish Editing Save and Continue Editing >> button').nth(1).click();
|
await page.locator('text=Snapshot Save and Finish Editing Save and Continue Editing >> button').nth(1).click();
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 18 KiB |
@@ -88,10 +88,10 @@ async function makeOverlayPlot(page, myItemsFolderName) {
|
|||||||
// create overlay plot
|
// create overlay plot
|
||||||
|
|
||||||
await page.locator('button.c-create-button').click();
|
await page.locator('button.c-create-button').click();
|
||||||
await page.locator('li:has-text("Overlay Plot")').click();
|
await page.locator('li[role="menuitem"]:has-text("Overlay Plot")').click();
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
page.waitForNavigation({ waitUntil: 'networkidle'}),
|
page.waitForNavigation({ waitUntil: 'networkidle'}),
|
||||||
page.locator('text=OK').click(),
|
page.locator('button:has-text("OK")').click(),
|
||||||
//Wait for Save Banner to appear
|
//Wait for Save Banner to appear
|
||||||
page.waitForSelector('.c-message-banner__message')
|
page.waitForSelector('.c-message-banner__message')
|
||||||
]);
|
]);
|
||||||
@@ -106,7 +106,7 @@ async function makeOverlayPlot(page, myItemsFolderName) {
|
|||||||
// create a sinewave generator
|
// create a sinewave generator
|
||||||
|
|
||||||
await page.locator('button.c-create-button').click();
|
await page.locator('button.c-create-button').click();
|
||||||
await page.locator('li:has-text("Sine Wave Generator")').click();
|
await page.locator('li[role="menuitem"]:has-text("Sine Wave Generator")').click();
|
||||||
|
|
||||||
// set amplitude to 6, offset 4, period 2
|
// set amplitude to 6, offset 4, period 2
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ async function makeOverlayPlot(page, myItemsFolderName) {
|
|||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
page.waitForNavigation({ waitUntil: 'networkidle'}),
|
page.waitForNavigation({ waitUntil: 'networkidle'}),
|
||||||
page.locator('text=OK').click(),
|
page.locator('button:has-text("OK")').click(),
|
||||||
//Wait for Save Banner to appear
|
//Wait for Save Banner to appear
|
||||||
page.waitForSelector('.c-message-banner__message')
|
page.waitForSelector('.c-message-banner__message')
|
||||||
]);
|
]);
|
||||||
@@ -205,7 +205,8 @@ async function enableEditMode(page) {
|
|||||||
*/
|
*/
|
||||||
async function enableLogMode(page) {
|
async function enableLogMode(page) {
|
||||||
// turn on log mode
|
// turn on log mode
|
||||||
await page.locator('text=Y Axis Label Log mode Auto scale Padding >> input[type="checkbox"]').first().check();
|
await page.getByRole('listitem').filter({ hasText: 'Log mode' }).getByRole('checkbox').check();
|
||||||
|
// await page.locator('text=Y Axis Label Log mode Auto scale Padding >> input[type="checkbox"]').first().check();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -213,7 +214,7 @@ async function enableLogMode(page) {
|
|||||||
*/
|
*/
|
||||||
async function disableLogMode(page) {
|
async function disableLogMode(page) {
|
||||||
// turn off log mode
|
// turn off log mode
|
||||||
await page.locator('text=Y Axis Label Log mode Auto scale Padding >> input[type="checkbox"]').first().uncheck();
|
await page.getByRole('listitem').filter({ hasText: 'Log mode' }).getByRole('checkbox').uncheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -88,11 +88,11 @@ async function makeStackedPlot(page, myItemsFolderName) {
|
|||||||
|
|
||||||
// create stacked plot
|
// create stacked plot
|
||||||
await page.locator('button.c-create-button').click();
|
await page.locator('button.c-create-button').click();
|
||||||
await page.locator('li:has-text("Stacked Plot")').click();
|
await page.locator('li[role="menuitem"]:has-text("Stacked Plot")').click();
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
page.waitForNavigation({ waitUntil: 'networkidle'}),
|
page.waitForNavigation({ waitUntil: 'networkidle'}),
|
||||||
page.locator('text=OK').click(),
|
page.locator('button:has-text("OK")').click(),
|
||||||
//Wait for Save Banner to appear
|
//Wait for Save Banner to appear
|
||||||
page.waitForSelector('.c-message-banner__message')
|
page.waitForSelector('.c-message-banner__message')
|
||||||
]);
|
]);
|
||||||
@@ -146,11 +146,11 @@ async function saveStackedPlot(page) {
|
|||||||
async function createSineWaveGenerator(page) {
|
async function createSineWaveGenerator(page) {
|
||||||
//Create sine wave generator
|
//Create sine wave generator
|
||||||
await page.locator('button.c-create-button').click();
|
await page.locator('button.c-create-button').click();
|
||||||
await page.locator('li:has-text("Sine Wave Generator")').click();
|
await page.locator('li[role="menuitem"]:has-text("Sine Wave Generator")').click();
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
page.waitForNavigation({ waitUntil: 'networkidle'}),
|
page.waitForNavigation({ waitUntil: 'networkidle'}),
|
||||||
page.locator('text=OK').click(),
|
page.locator('button:has-text("OK")').click(),
|
||||||
//Wait for Save Banner to appear
|
//Wait for Save Banner to appear
|
||||||
page.waitForSelector('.c-message-banner__message')
|
page.waitForSelector('.c-message-banner__message')
|
||||||
]);
|
]);
|
||||||
|
|||||||
124
e2e/tests/functional/plugins/plot/overlayPlot.e2e.spec.js
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* 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. Note this test suite if very much under active development and should not
|
||||||
|
necessarily be used for reference when writing new tests in this area.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const { test, expect } = require('../../../../pluginFixtures');
|
||||||
|
const { createDomainObjectWithDefaults } = require('../../../../appActions');
|
||||||
|
|
||||||
|
test.describe('Overlay Plot', () => {
|
||||||
|
test('Plot legend color is in sync with plot series color', async ({ page }) => {
|
||||||
|
await page.goto('/', { waitUntil: 'networkidle' });
|
||||||
|
const overlayPlot = await createDomainObjectWithDefaults(page, {
|
||||||
|
type: "Overlay Plot"
|
||||||
|
});
|
||||||
|
|
||||||
|
await createDomainObjectWithDefaults(page, {
|
||||||
|
type: "Sine Wave Generator",
|
||||||
|
parent: overlayPlot.uuid
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.goto(overlayPlot.url);
|
||||||
|
|
||||||
|
// navigate to plot series color palette
|
||||||
|
await page.click('.l-browse-bar__actions__edit');
|
||||||
|
await page.locator('li.c-tree__item.menus-to-left .c-disclosure-triangle').click();
|
||||||
|
await page.locator('.c-click-swatch--menu').click();
|
||||||
|
await page.locator('.c-palette__item[style="background: rgb(255, 166, 61);"]').click();
|
||||||
|
|
||||||
|
// gets color for swatch located in legend
|
||||||
|
const element = await page.waitForSelector('.plot-series-color-swatch');
|
||||||
|
const color = await element.evaluate((el) => {
|
||||||
|
return window.getComputedStyle(el).getPropertyValue('background-color');
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(color).toBe('rgb(255, 166, 61)');
|
||||||
|
});
|
||||||
|
test('The elements pool supports dragging series into multiple y-axis buckets', async ({ page }) => {
|
||||||
|
await page.goto('/', { waitUntil: 'networkidle' });
|
||||||
|
const overlayPlot = await createDomainObjectWithDefaults(page, {
|
||||||
|
type: "Overlay Plot"
|
||||||
|
});
|
||||||
|
|
||||||
|
await createDomainObjectWithDefaults(page, {
|
||||||
|
type: "Sine Wave Generator",
|
||||||
|
name: 'swg a',
|
||||||
|
parent: overlayPlot.uuid
|
||||||
|
});
|
||||||
|
await createDomainObjectWithDefaults(page, {
|
||||||
|
type: "Sine Wave Generator",
|
||||||
|
name: 'swg b',
|
||||||
|
parent: overlayPlot.uuid
|
||||||
|
});
|
||||||
|
await createDomainObjectWithDefaults(page, {
|
||||||
|
type: "Sine Wave Generator",
|
||||||
|
name: 'swg c',
|
||||||
|
parent: overlayPlot.uuid
|
||||||
|
});
|
||||||
|
await createDomainObjectWithDefaults(page, {
|
||||||
|
type: "Sine Wave Generator",
|
||||||
|
name: 'swg d',
|
||||||
|
parent: overlayPlot.uuid
|
||||||
|
});
|
||||||
|
await createDomainObjectWithDefaults(page, {
|
||||||
|
type: "Sine Wave Generator",
|
||||||
|
name: 'swg e',
|
||||||
|
parent: overlayPlot.uuid
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.goto(overlayPlot.url);
|
||||||
|
await page.click('button[title="Edit"]');
|
||||||
|
|
||||||
|
// Expand the elements pool vertically
|
||||||
|
await page.locator('.l-pane__handle').nth(2).hover({ trial: true });
|
||||||
|
await page.mouse.down();
|
||||||
|
await page.mouse.move(0, 100);
|
||||||
|
await page.mouse.up();
|
||||||
|
|
||||||
|
// Drag swg a, c, e into Y Axis 2
|
||||||
|
await page.locator('#inspector-elements-tree >> text=swg a').dragTo(page.locator('[aria-label="Element Item Group Y Axis 2"]'));
|
||||||
|
await page.locator('#inspector-elements-tree >> text=swg c').dragTo(page.locator('[aria-label="Element Item Group Y Axis 2"]'));
|
||||||
|
await page.locator('#inspector-elements-tree >> text=swg e').dragTo(page.locator('[aria-label="Element Item Group Y Axis 2"]'));
|
||||||
|
|
||||||
|
// Drag swg b into Y Axis 3
|
||||||
|
await page.locator('#inspector-elements-tree >> text=swg b').dragTo(page.locator('[aria-label="Element Item Group Y Axis 3"]'));
|
||||||
|
|
||||||
|
const yAxis1Group = page.getByLabel("Y Axis 1");
|
||||||
|
const yAxis2Group = page.getByLabel("Y Axis 2");
|
||||||
|
const yAxis3Group = page.getByLabel("Y Axis 3");
|
||||||
|
|
||||||
|
// Verify that the elements are in the correct buckets and in the correct order
|
||||||
|
expect(yAxis1Group.getByRole('listitem', { name: 'swg d' })).toBeTruthy();
|
||||||
|
expect(yAxis1Group.getByRole('listitem').nth(0).getByText('swg d')).toBeTruthy();
|
||||||
|
expect(yAxis2Group.getByRole('listitem', { name: 'swg e' })).toBeTruthy();
|
||||||
|
expect(yAxis2Group.getByRole('listitem').nth(0).getByText('swg e')).toBeTruthy();
|
||||||
|
expect(yAxis2Group.getByRole('listitem', { name: 'swg c' })).toBeTruthy();
|
||||||
|
expect(yAxis2Group.getByRole('listitem').nth(1).getByText('swg c')).toBeTruthy();
|
||||||
|
expect(yAxis2Group.getByRole('listitem', { name: 'swg a' })).toBeTruthy();
|
||||||
|
expect(yAxis2Group.getByRole('listitem').nth(2).getByText('swg a')).toBeTruthy();
|
||||||
|
expect(yAxis3Group.getByRole('listitem', { name: 'swg b' })).toBeTruthy();
|
||||||
|
expect(yAxis3Group.getByRole('listitem').nth(0).getByText('swg b')).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -68,10 +68,10 @@ async function makeOverlayPlot(page) {
|
|||||||
// create overlay plot
|
// create overlay plot
|
||||||
|
|
||||||
await page.locator('button.c-create-button').click();
|
await page.locator('button.c-create-button').click();
|
||||||
await page.locator('li:has-text("Overlay Plot")').click();
|
await page.locator('li[role="menuitem"]:has-text("Overlay Plot")').click();
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
page.waitForNavigation({ waitUntil: 'networkidle'}),
|
page.waitForNavigation({ waitUntil: 'networkidle'}),
|
||||||
page.locator('text=OK').click(),
|
page.locator('button:has-text("OK")').click(),
|
||||||
//Wait for Save Banner to appear
|
//Wait for Save Banner to appear
|
||||||
page.waitForSelector('.c-message-banner__message')
|
page.waitForSelector('.c-message-banner__message')
|
||||||
]);
|
]);
|
||||||
@@ -86,13 +86,13 @@ async function makeOverlayPlot(page) {
|
|||||||
// create a sinewave generator
|
// create a sinewave generator
|
||||||
|
|
||||||
await page.locator('button.c-create-button').click();
|
await page.locator('button.c-create-button').click();
|
||||||
await page.locator('li:has-text("Sine Wave Generator")').click();
|
await page.locator('li[role="menuitem"]:has-text("Sine Wave Generator")').click();
|
||||||
|
|
||||||
// Click OK to make generator
|
// Click OK to make generator
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
page.waitForNavigation({ waitUntil: 'networkidle'}),
|
page.waitForNavigation({ waitUntil: 'networkidle'}),
|
||||||
page.locator('text=OK').click(),
|
page.locator('button:has-text("OK")').click(),
|
||||||
//Wait for Save Banner to appear
|
//Wait for Save Banner to appear
|
||||||
page.waitForSelector('.c-message-banner__message')
|
page.waitForSelector('.c-message-banner__message')
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -25,8 +25,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const { test, expect } = require('../../../../baseFixtures');
|
const { test, expect } = require('../../../../pluginFixtures');
|
||||||
const { createDomainObjectWithDefaults } = require('../../../../appActions');
|
const { createDomainObjectWithDefaults} = require('../../../../appActions');
|
||||||
|
|
||||||
test.describe('Plot Integrity Testing @unstable', () => {
|
test.describe('Plot Integrity Testing @unstable', () => {
|
||||||
let sineWaveGeneratorObject;
|
let sineWaveGeneratorObject;
|
||||||
@@ -40,7 +40,6 @@ test.describe('Plot Integrity Testing @unstable', () => {
|
|||||||
test('Plots do not re-request data when a plot is clicked', async ({ page }) => {
|
test('Plots do not re-request data when a plot is clicked', async ({ page }) => {
|
||||||
//Navigate to Sine Wave Generator
|
//Navigate to Sine Wave Generator
|
||||||
await page.goto(sineWaveGeneratorObject.url);
|
await page.goto(sineWaveGeneratorObject.url);
|
||||||
//Capture the number of plots points and store as const name numberOfPlotPoints
|
|
||||||
//Click on the plot canvas
|
//Click on the plot canvas
|
||||||
await page.locator('canvas').nth(1).click();
|
await page.locator('canvas').nth(1).click();
|
||||||
//No request was made to get historical data
|
//No request was made to get historical data
|
||||||
@@ -51,4 +50,90 @@ test.describe('Plot Integrity Testing @unstable', () => {
|
|||||||
});
|
});
|
||||||
expect(createMineFolderRequests.length).toEqual(0);
|
expect(createMineFolderRequests.length).toEqual(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Plot is rendered when infinity values exist', async ({ page }) => {
|
||||||
|
// Edit Plot
|
||||||
|
await editSineWaveToUseInfinityOption(page, sineWaveGeneratorObject);
|
||||||
|
|
||||||
|
//Get pixel data from Canvas
|
||||||
|
const plotPixelSize = await getCanvasPixelsWithData(page);
|
||||||
|
expect(plotPixelSize).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function edits a sine wave generator with the default options and enables the infinity values option.
|
||||||
|
*
|
||||||
|
* @param {import('@playwright/test').Page} page
|
||||||
|
* @param {import('../../../../appActions').CreateObjectInfo} sineWaveGeneratorObject
|
||||||
|
* @returns {Promise<CreatedObjectInfo>} An object containing information about the edited domain object.
|
||||||
|
*/
|
||||||
|
async function editSineWaveToUseInfinityOption(page, sineWaveGeneratorObject) {
|
||||||
|
await page.goto(sineWaveGeneratorObject.url);
|
||||||
|
// Edit LAD table
|
||||||
|
await page.locator('[title="More options"]').click();
|
||||||
|
await page.locator('[title="Edit properties of this object."]').click();
|
||||||
|
// Modify the infinity option to true
|
||||||
|
const infinityInput = page.locator('[aria-label="Include Infinity Values"]');
|
||||||
|
await infinityInput.click();
|
||||||
|
|
||||||
|
// Click OK button and wait for Navigate event
|
||||||
|
await Promise.all([
|
||||||
|
page.waitForLoadState(),
|
||||||
|
page.click('[aria-label="Save"]'),
|
||||||
|
// Wait for Save Banner to appear
|
||||||
|
page.waitForSelector('.c-message-banner__message')
|
||||||
|
]);
|
||||||
|
|
||||||
|
// FIXME: Changes to SWG properties should be reflected on save, but they're not?
|
||||||
|
// Thus, navigate away and back to the object.
|
||||||
|
await page.goto('./#/browse/mine');
|
||||||
|
await page.goto(sineWaveGeneratorObject.url);
|
||||||
|
|
||||||
|
await page.locator('c-progress-bar c-telemetry-table__progress-bar').waitFor({
|
||||||
|
state: 'hidden'
|
||||||
|
});
|
||||||
|
|
||||||
|
// FIXME: The progress bar disappears on series data load, not on plot render,
|
||||||
|
// so wait for a half a second before evaluating the canvas.
|
||||||
|
// eslint-disable-next-line playwright/no-wait-for-timeout
|
||||||
|
await page.waitForTimeout(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {import('@playwright/test').Page} page
|
||||||
|
*/
|
||||||
|
async function getCanvasPixelsWithData(page) {
|
||||||
|
const getTelemValuePromise = new Promise(resolve => page.exposeFunction('getCanvasValue', resolve));
|
||||||
|
|
||||||
|
await page.evaluate(() => {
|
||||||
|
// The document canvas is where the plot points and lines are drawn.
|
||||||
|
// The only way to access the canvas is using document (using page.evaluate)
|
||||||
|
let data;
|
||||||
|
let canvas;
|
||||||
|
let ctx;
|
||||||
|
canvas = document.querySelector('canvas');
|
||||||
|
ctx = canvas.getContext('2d');
|
||||||
|
data = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
|
||||||
|
const imageDataValues = Object.values(data);
|
||||||
|
let plotPixels = [];
|
||||||
|
// Each pixel consists of four values within the ImageData.data array. The for loop iterates by multiples of four.
|
||||||
|
// The values associated with each pixel are R (red), G (green), B (blue), and A (alpha), in that order.
|
||||||
|
for (let i = 0; i < imageDataValues.length;) {
|
||||||
|
if (imageDataValues[i] > 0) {
|
||||||
|
plotPixels.push({
|
||||||
|
startIndex: i,
|
||||||
|
endIndex: i + 3,
|
||||||
|
value: `rgb(${imageDataValues[i]}, ${imageDataValues[i + 1]}, ${imageDataValues[i + 2]}, ${imageDataValues[i + 3]})`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
i = i + 4;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
window.getCanvasValue(plotPixels.length);
|
||||||
|
});
|
||||||
|
|
||||||
|
return getTelemValuePromise;
|
||||||
|
}
|
||||||
|
|||||||
93
e2e/tests/functional/plugins/plot/scatterPlot.e2e.spec.js
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* 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.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This test suite is dedicated to testing the Scatter Plot component.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const { test, expect } = require('../../../../pluginFixtures');
|
||||||
|
const { createDomainObjectWithDefaults } = require('../../../../appActions');
|
||||||
|
const uuid = require('uuid').v4;
|
||||||
|
|
||||||
|
test.describe('Scatter Plot', () => {
|
||||||
|
let scatterPlot;
|
||||||
|
|
||||||
|
test.beforeEach(async ({ page }) => {
|
||||||
|
// Open a browser, navigate to the main page, and wait until all networkevents to resolve
|
||||||
|
await page.goto('./', { waitUntil: 'networkidle' });
|
||||||
|
|
||||||
|
// Create the Scatter Plot
|
||||||
|
scatterPlot = await createDomainObjectWithDefaults(page, { type: 'Scatter Plot' });
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Can add and remove telemetry sources', async ({ page }) => {
|
||||||
|
const editButtonLocator = page.locator('button[title="Edit"]');
|
||||||
|
const saveButtonLocator = page.locator('button[title="Save"]');
|
||||||
|
|
||||||
|
// Create a sine wave generator within the scatter plot
|
||||||
|
const swg1 = await createDomainObjectWithDefaults(page, {
|
||||||
|
type: 'Sine Wave Generator',
|
||||||
|
name: `swg-${uuid()}`,
|
||||||
|
parent: scatterPlot.uuid
|
||||||
|
});
|
||||||
|
|
||||||
|
// Navigate to the scatter plot and verify that
|
||||||
|
// the SWG appears in the elements pool
|
||||||
|
await page.goto(scatterPlot.url);
|
||||||
|
await editButtonLocator.click();
|
||||||
|
await expect.soft(page.locator(`#inspector-elements-tree >> text=${swg1.name}`)).toBeVisible();
|
||||||
|
await saveButtonLocator.click();
|
||||||
|
await page.locator('li[title="Save and Finish Editing"]').click();
|
||||||
|
|
||||||
|
// Create another sine wave generator within the scatter plot
|
||||||
|
const swg2 = await createDomainObjectWithDefaults(page, {
|
||||||
|
type: 'Sine Wave Generator',
|
||||||
|
name: `swg-${uuid()}`,
|
||||||
|
parent: scatterPlot.uuid
|
||||||
|
});
|
||||||
|
|
||||||
|
// Verify that the 'Replace telemetry source' modal appears and accept it
|
||||||
|
await expect.soft(page.locator('text=This action will replace the current telemetry source. Do you want to continue?')).toBeVisible();
|
||||||
|
await page.click('text=Ok');
|
||||||
|
|
||||||
|
// Navigate to the scatter plot and verify that the new SWG
|
||||||
|
// appears in the elements pool and the old one is gone
|
||||||
|
await page.goto(scatterPlot.url);
|
||||||
|
await editButtonLocator.click();
|
||||||
|
await expect.soft(page.locator(`#inspector-elements-tree >> text=${swg1.name}`)).toBeHidden();
|
||||||
|
await expect.soft(page.locator(`#inspector-elements-tree >> text=${swg2.name}`)).toBeVisible();
|
||||||
|
await saveButtonLocator.click();
|
||||||
|
|
||||||
|
// Right click on the new SWG in the elements pool and delete it
|
||||||
|
await page.locator(`#inspector-elements-tree >> text=${swg2.name}`).click({
|
||||||
|
button: 'right'
|
||||||
|
});
|
||||||
|
await page.locator('li[title="Remove this object from its containing object."]').click();
|
||||||
|
|
||||||
|
// Verify that the 'Remove object' confirmation modal appears and accept it
|
||||||
|
await expect.soft(page.locator('text=Warning! This action will remove this object. Are you sure you want to continue?')).toBeVisible();
|
||||||
|
await page.click('text=Ok');
|
||||||
|
|
||||||
|
// Verify that the elements pool shows no elements
|
||||||
|
await expect(page.locator('text="No contained elements"')).toBeVisible();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
* at runtime from the About dialog for additional information.
|
* at runtime from the About dialog for additional information.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
const { test, expect } = require('../../../../baseFixtures');
|
const { test, expect } = require('../../../../pluginFixtures');
|
||||||
const { setFixedTimeMode, setRealTimeMode, setStartOffset, setEndOffset } = require('../../../../appActions');
|
const { setFixedTimeMode, setRealTimeMode, setStartOffset, setEndOffset } = require('../../../../appActions');
|
||||||
|
|
||||||
test.describe('Time conductor operations', () => {
|
test.describe('Time conductor operations', () => {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ test.describe('Timer', () => {
|
|||||||
timer = await createDomainObjectWithDefaults(page, { type: 'timer' });
|
timer = await createDomainObjectWithDefaults(page, { type: 'timer' });
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Can perform actions on the Timer', async ({ page, openmctConfig }) => {
|
test('Can perform actions on the Timer', async ({ page }) => {
|
||||||
test.info().annotations.push({
|
test.info().annotations.push({
|
||||||
type: 'issue',
|
type: 'issue',
|
||||||
description: 'https://github.com/nasa/openmct/issues/4313'
|
description: 'https://github.com/nasa/openmct/issues/4313'
|
||||||
|
|||||||
85
e2e/tests/functional/recentObjects.e2e.spec.js
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* 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.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
const { test, expect } = require('../../pluginFixtures.js');
|
||||||
|
const { createDomainObjectWithDefaults } = require('../../appActions.js');
|
||||||
|
|
||||||
|
test.describe('Recent Objects', () => {
|
||||||
|
test('Recent Objects CRUD operations', async ({ page }) => {
|
||||||
|
await page.goto('./', { waitUntil: 'networkidle' });
|
||||||
|
|
||||||
|
// Create a folder and nest a Clock within it
|
||||||
|
const recentObjectsList = page.locator('[aria-label="Recent Objects"]');
|
||||||
|
const folderA = await createDomainObjectWithDefaults(page, {
|
||||||
|
type: 'Folder'
|
||||||
|
});
|
||||||
|
const clock = await createDomainObjectWithDefaults(page, {
|
||||||
|
type: 'Clock',
|
||||||
|
parent: folderA.uuid
|
||||||
|
});
|
||||||
|
|
||||||
|
// Drag the Recent Objects panel up a bit
|
||||||
|
await page.locator('div:nth-child(2) > .l-pane__handle').hover();
|
||||||
|
await page.mouse.down();
|
||||||
|
await page.mouse.move(0, 100);
|
||||||
|
await page.mouse.up();
|
||||||
|
|
||||||
|
// Verify that both created objects appear in the list and are in the correct order
|
||||||
|
expect(recentObjectsList.getByRole('listitem', { name: clock.name })).toBeTruthy();
|
||||||
|
expect(recentObjectsList.getByRole('listitem', { name: folderA.name })).toBeTruthy();
|
||||||
|
expect(recentObjectsList.getByRole('listitem', { name: clock.name }).locator('a').getByText(folderA.name)).toBeTruthy();
|
||||||
|
expect(recentObjectsList.getByRole('listitem').nth(0).getByText(clock.name)).toBeTruthy();
|
||||||
|
expect(recentObjectsList.getByRole('listitem', { name: clock.name }).locator('a').getByText(folderA.name)).toBeTruthy();
|
||||||
|
expect(recentObjectsList.getByRole('listitem').nth(1).getByText(folderA.name)).toBeTruthy();
|
||||||
|
|
||||||
|
// Navigate to the folder by clicking on the main object name in the recent objects list item
|
||||||
|
await recentObjectsList.getByRole('listitem', { name: folderA.name }).getByText(folderA.name).click();
|
||||||
|
await page.waitForURL(`**/${folderA.uuid}?*`);
|
||||||
|
expect(recentObjectsList.getByRole('listitem').nth(0).getByText(folderA.name)).toBeTruthy();
|
||||||
|
|
||||||
|
// Rename
|
||||||
|
folderA.name = `${folderA.name}-NEW!`;
|
||||||
|
await page.locator('.l-browse-bar__object-name').fill("");
|
||||||
|
await page.locator('.l-browse-bar__object-name').fill(folderA.name);
|
||||||
|
await page.keyboard.press('Enter');
|
||||||
|
|
||||||
|
// Verify rename has been applied in recent objects list item and objects paths
|
||||||
|
expect(page.getByRole('listitem', { name: clock.name }).locator('a').getByText(folderA.name)).toBeTruthy();
|
||||||
|
expect(recentObjectsList.getByRole('listitem', { name: folderA.name })).toBeTruthy();
|
||||||
|
|
||||||
|
// Delete
|
||||||
|
await page.click('button[title="Show selected item in tree"]');
|
||||||
|
// Delete the folder via the left tree pane treeitem context menu
|
||||||
|
await page.getByRole('treeitem', { name: new RegExp(folderA.name) }).locator('a').click({
|
||||||
|
button: 'right'
|
||||||
|
});
|
||||||
|
await page.getByRole('menuitem', { name: /Remove/ }).click();
|
||||||
|
await page.getByRole('button', { name: 'OK' }).click();
|
||||||
|
|
||||||
|
// Verify that the folder and clock are no longer in the recent objects list
|
||||||
|
await expect(recentObjectsList.getByRole('listitem', { name: folderA.name })).toBeHidden();
|
||||||
|
await expect(recentObjectsList.getByRole('listitem', { name: clock.name })).toBeHidden();
|
||||||
|
});
|
||||||
|
test.fixme("Clicking on the 'target button' scrolls the object into view in the tree and highlights it");
|
||||||
|
test.fixme("Clicking on an object in the path of a recent object navigates to the object");
|
||||||
|
test.fixme("Tests for context menu actions from recent objects");
|
||||||
|
});
|
||||||
@@ -31,7 +31,7 @@ test.describe('Grand Search', () => {
|
|||||||
test('Can search for objects, and subsequent search dropdown behaves properly', async ({ page, openmctConfig }) => {
|
test('Can search for objects, and subsequent search dropdown behaves properly', async ({ page, openmctConfig }) => {
|
||||||
const { myItemsFolderName } = openmctConfig;
|
const { myItemsFolderName } = openmctConfig;
|
||||||
|
|
||||||
await createObjectsForSearch(page, myItemsFolderName);
|
const createdObjects = await createObjectsForSearch(page);
|
||||||
|
|
||||||
// Click [aria-label="OpenMCT Search"] input[type="search"]
|
// Click [aria-label="OpenMCT Search"] input[type="search"]
|
||||||
await page.locator('[aria-label="OpenMCT Search"] input[type="search"]').click();
|
await page.locator('[aria-label="OpenMCT Search"] input[type="search"]').click();
|
||||||
@@ -41,8 +41,8 @@ test.describe('Grand Search', () => {
|
|||||||
await expect(page.locator('[aria-label="Search Result"] >> nth=1')).toContainText(`Clock B ${myItemsFolderName} Red Folder Blue Folder`);
|
await expect(page.locator('[aria-label="Search Result"] >> nth=1')).toContainText(`Clock B ${myItemsFolderName} Red Folder Blue Folder`);
|
||||||
await expect(page.locator('[aria-label="Search Result"] >> nth=2')).toContainText(`Clock C ${myItemsFolderName} Red Folder Blue Folder`);
|
await expect(page.locator('[aria-label="Search Result"] >> nth=2')).toContainText(`Clock C ${myItemsFolderName} Red Folder Blue Folder`);
|
||||||
await expect(page.locator('[aria-label="Search Result"] >> nth=3')).toContainText(`Clock D ${myItemsFolderName} Red Folder Blue Folder`);
|
await expect(page.locator('[aria-label="Search Result"] >> nth=3')).toContainText(`Clock D ${myItemsFolderName} Red Folder Blue Folder`);
|
||||||
// Click text=Elements >> nth=0
|
// Click the Elements pool to dismiss the search menu
|
||||||
await page.locator('text=Elements').first().click();
|
await page.locator('.l-pane__label:has-text("Elements")').click();
|
||||||
await expect(page.locator('[aria-label="Search Result"] >> nth=0')).toBeHidden();
|
await expect(page.locator('[aria-label="Search Result"] >> nth=0')).toBeHidden();
|
||||||
|
|
||||||
await page.locator('[aria-label="OpenMCT Search"] [aria-label="Search Input"]').click();
|
await page.locator('[aria-label="OpenMCT Search"] [aria-label="Search Input"]').click();
|
||||||
@@ -72,12 +72,12 @@ test.describe('Grand Search', () => {
|
|||||||
await page.locator('[aria-label="OpenMCT Search"] [aria-label="Search Input"]').fill('Cl');
|
await page.locator('[aria-label="OpenMCT Search"] [aria-label="Search Input"]').fill('Cl');
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
page.waitForNavigation(),
|
page.waitForNavigation(),
|
||||||
page.locator('text=Clock A').click()
|
page.locator('[aria-label="Clock A clock result"] >> text=Clock A').click()
|
||||||
]);
|
]);
|
||||||
await expect(page.locator('.is-object-type-clock')).toBeVisible();
|
await expect(page.locator('.is-object-type-clock')).toBeVisible();
|
||||||
|
|
||||||
await page.locator('[aria-label="OpenMCT Search"] [aria-label="Search Input"]').fill('Disp');
|
await page.locator('[aria-label="OpenMCT Search"] [aria-label="Search Input"]').fill('Disp');
|
||||||
await expect(page.locator('[aria-label="Search Result"] >> nth=0')).toContainText('Unnamed Display Layout');
|
await expect(page.locator('[aria-label="Search Result"] >> nth=0')).toContainText(createdObjects.displayLayout.name);
|
||||||
await expect(page.locator('[aria-label="Search Result"] >> nth=0')).not.toContainText('Folder');
|
await expect(page.locator('[aria-label="Search Result"] >> nth=0')).not.toContainText('Folder');
|
||||||
|
|
||||||
await page.locator('[aria-label="OpenMCT Search"] input[type="search"]').fill('Clock C');
|
await page.locator('[aria-label="OpenMCT Search"] input[type="search"]').fill('Clock C');
|
||||||
@@ -185,7 +185,7 @@ async function createFolderObject(page, folderName) {
|
|||||||
await page.locator('text=Properties Title Notes >> input[type="text"]').fill(folderName);
|
await page.locator('text=Properties Title Notes >> input[type="text"]').fill(folderName);
|
||||||
|
|
||||||
// Create folder object
|
// Create folder object
|
||||||
await page.locator('text=OK').click();
|
await page.locator('button:has-text("OK")').click();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function waitForSearchCompletion(page) {
|
async function waitForSearchCompletion(page) {
|
||||||
@@ -197,75 +197,56 @@ async function waitForSearchCompletion(page) {
|
|||||||
* Creates some domain objects for searching
|
* Creates some domain objects for searching
|
||||||
* @param {import('@playwright/test').Page} page
|
* @param {import('@playwright/test').Page} page
|
||||||
*/
|
*/
|
||||||
async function createObjectsForSearch(page, myItemsFolderName) {
|
async function createObjectsForSearch(page) {
|
||||||
//Go to baseURL
|
//Go to baseURL
|
||||||
await page.goto('./', { waitUntil: 'networkidle' });
|
await page.goto('./', { waitUntil: 'networkidle' });
|
||||||
|
|
||||||
await page.locator('button:has-text("Create")').click();
|
const redFolder = await createDomainObjectWithDefaults(page, {
|
||||||
await page.locator('li:has-text("Folder") >> nth=1').click();
|
type: 'Folder',
|
||||||
await Promise.all([
|
name: 'Red Folder'
|
||||||
page.waitForNavigation(),
|
});
|
||||||
await page.locator('text=Properties Title Notes >> input[type="text"]').fill('Red Folder'),
|
|
||||||
await page.locator(`text=Save In Open MCT ${myItemsFolderName} >> span`).nth(3).click(),
|
|
||||||
page.locator('button:has-text("OK")').click()
|
|
||||||
]);
|
|
||||||
|
|
||||||
await page.locator('button:has-text("Create")').click();
|
const blueFolder = await createDomainObjectWithDefaults(page, {
|
||||||
await page.locator('li:has-text("Folder") >> nth=2').click();
|
type: 'Folder',
|
||||||
await Promise.all([
|
name: 'Blue Folder',
|
||||||
page.waitForNavigation(),
|
parent: redFolder.uuid
|
||||||
await page.locator('text=Properties Title Notes >> input[type="text"]').fill('Blue Folder'),
|
});
|
||||||
await page.locator('form[name="mctForm"] >> text=Red Folder').click(),
|
|
||||||
page.locator('button:has-text("OK")').click()
|
|
||||||
]);
|
|
||||||
|
|
||||||
await page.locator('button:has-text("Create")').click();
|
const clockA = await createDomainObjectWithDefaults(page, {
|
||||||
await page.locator('li[title="A digital clock that uses system time and supports a variety of display formats and timezones."]').click();
|
type: 'Clock',
|
||||||
await Promise.all([
|
name: 'Clock A',
|
||||||
page.waitForNavigation(),
|
parent: blueFolder.uuid
|
||||||
await page.locator('text=Properties Title Notes >> input[type="text"] >> nth=0').fill('Clock A'),
|
});
|
||||||
await page.locator('form[name="mctForm"] >> text=Blue Folder').click(),
|
const clockB = await createDomainObjectWithDefaults(page, {
|
||||||
page.locator('button:has-text("OK")').click()
|
type: 'Clock',
|
||||||
]);
|
name: 'Clock B',
|
||||||
|
parent: blueFolder.uuid
|
||||||
|
});
|
||||||
|
const clockC = await createDomainObjectWithDefaults(page, {
|
||||||
|
type: 'Clock',
|
||||||
|
name: 'Clock C',
|
||||||
|
parent: blueFolder.uuid
|
||||||
|
});
|
||||||
|
const clockD = await createDomainObjectWithDefaults(page, {
|
||||||
|
type: 'Clock',
|
||||||
|
name: 'Clock D',
|
||||||
|
parent: blueFolder.uuid
|
||||||
|
});
|
||||||
|
|
||||||
await page.locator('button:has-text("Create")').click();
|
const displayLayout = await createDomainObjectWithDefaults(page, {
|
||||||
await page.locator('li[title="A digital clock that uses system time and supports a variety of display formats and timezones."]').click();
|
type: 'Display Layout'
|
||||||
await Promise.all([
|
});
|
||||||
page.waitForNavigation(),
|
|
||||||
await page.locator('text=Properties Title Notes >> input[type="text"] >> nth=0').fill('Clock B'),
|
|
||||||
await page.locator('form[name="mctForm"] >> text=Blue Folder').click(),
|
|
||||||
page.locator('button:has-text("OK")').click()
|
|
||||||
]);
|
|
||||||
|
|
||||||
await page.locator('button:has-text("Create")').click();
|
// Go back into edit mode for the display layout
|
||||||
await page.locator('li[title="A digital clock that uses system time and supports a variety of display formats and timezones."]').click();
|
await page.locator('button[title="Edit"]').click();
|
||||||
await Promise.all([
|
|
||||||
page.waitForNavigation(),
|
|
||||||
await page.locator('text=Properties Title Notes >> input[type="text"] >> nth=0').fill('Clock C'),
|
|
||||||
await page.locator('form[name="mctForm"] >> text=Blue Folder').click(),
|
|
||||||
page.locator('button:has-text("OK")').click()
|
|
||||||
]);
|
|
||||||
|
|
||||||
await page.locator('button:has-text("Create")').click();
|
return {
|
||||||
await page.locator('li[title="A digital clock that uses system time and supports a variety of display formats and timezones."]').click();
|
redFolder,
|
||||||
await Promise.all([
|
blueFolder,
|
||||||
page.waitForNavigation(),
|
clockA,
|
||||||
await page.locator('text=Properties Title Notes >> input[type="text"] >> nth=0').fill('Clock D'),
|
clockB,
|
||||||
await page.locator('form[name="mctForm"] >> text=Blue Folder').click(),
|
clockC,
|
||||||
page.locator('button:has-text("OK")').click()
|
clockD,
|
||||||
]);
|
displayLayout
|
||||||
|
};
|
||||||
await Promise.all([
|
|
||||||
page.waitForNavigation(),
|
|
||||||
page.locator(`a:has-text("${myItemsFolderName}") >> nth=0`).click()
|
|
||||||
]);
|
|
||||||
// Click button:has-text("Create")
|
|
||||||
await page.locator('button:has-text("Create")').click();
|
|
||||||
// Click li:has-text("Notebook")
|
|
||||||
await page.locator('li:has-text("Display Layout")').click();
|
|
||||||
// Click button:has-text("OK")
|
|
||||||
await Promise.all([
|
|
||||||
page.waitForNavigation(),
|
|
||||||
page.locator('button:has-text("OK")').click()
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ test.describe('Performance tests', () => {
|
|||||||
await page.setInputFiles('#fileElem', filePath);
|
await page.setInputFiles('#fileElem', filePath);
|
||||||
|
|
||||||
// Click text=OK
|
// Click text=OK
|
||||||
await page.locator('text=OK').click();
|
await page.locator('button:has-text("OK")').click();
|
||||||
|
|
||||||
await expect(page.locator('a:has-text("Performance Display Layout Display Layout")')).toBeVisible();
|
await expect(page.locator('a:has-text("Performance Display Layout Display Layout")')).toBeVisible();
|
||||||
|
|
||||||
|
|||||||
58
e2e/tests/visual/notification.visual.spec.js
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* 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.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This test is dedicated to test notification banner functionality and its accessibility attributes.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const { test, expect } = require('../../pluginFixtures');
|
||||||
|
const percySnapshot = require('@percy/playwright');
|
||||||
|
const { createDomainObjectWithDefaults } = require('../../appActions');
|
||||||
|
|
||||||
|
test.describe('Visual - Check Notification Info Banner of \'Save successful\'', () => {
|
||||||
|
test.beforeEach(async ({ page }) => {
|
||||||
|
// Go to baseURL and Hide Tree
|
||||||
|
await page.goto('./', { waitUntil: 'networkidle' });
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Create a clock, click on \'Save successful\' banner and dismiss it', async ({ page }) => {
|
||||||
|
// Create a clock domain object
|
||||||
|
await createDomainObjectWithDefaults(page, { type: 'Clock' });
|
||||||
|
// Verify there is a button with aria-label="Review 1 Notification"
|
||||||
|
expect(await page.locator('button[aria-label="Review 1 Notification"]').isVisible()).toBe(true);
|
||||||
|
// Verify there is a button with aria-label="Clear all notifications"
|
||||||
|
expect(await page.locator('button[aria-label="Clear all notifications"]').isVisible()).toBe(true);
|
||||||
|
// Click on the div with role="alert" that has "Save successful" text
|
||||||
|
await page.locator('div[role="alert"]:has-text("Save successful")').click();
|
||||||
|
// Verify there is a div with role="dialog"
|
||||||
|
expect(await page.locator('div[role="dialog"]').isVisible()).toBe(true);
|
||||||
|
// Verify the div with role="dialog" contains text "Save successful"
|
||||||
|
expect(await page.locator('div[role="dialog"]').innerText()).toContain('Save successful');
|
||||||
|
await percySnapshot(page, 'Notification banner');
|
||||||
|
// Verify there is a button with text "Dismiss"
|
||||||
|
expect(await page.locator('button:has-text("Dismiss")').isVisible()).toBe(true);
|
||||||
|
// Click on button with text "Dismiss"
|
||||||
|
await page.locator('button:has-text("Dismiss")').click();
|
||||||
|
// Verify there is no div with role="dialog"
|
||||||
|
expect(await page.locator('div[role="dialog"]').isVisible()).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -65,7 +65,7 @@ export default class ExampleUserProvider extends EventEmitter {
|
|||||||
this.user = undefined;
|
this.user = undefined;
|
||||||
this.loggedIn = false;
|
this.loggedIn = false;
|
||||||
this.autoLoginUser = undefined;
|
this.autoLoginUser = undefined;
|
||||||
this.status = STATUSES[1];
|
this.status = STATUSES[0];
|
||||||
this.pollQuestion = undefined;
|
this.pollQuestion = undefined;
|
||||||
this.defaultStatusRole = defaultStatusRole;
|
this.defaultStatusRole = defaultStatusRole;
|
||||||
|
|
||||||
@@ -124,6 +124,7 @@ export default class ExampleUserProvider extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setStatusForRole(role, status) {
|
setStatusForRole(role, status) {
|
||||||
|
status.timestamp = Date.now();
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.emit('statusChange', {
|
this.emit('statusChange', {
|
||||||
role,
|
role,
|
||||||
@@ -133,14 +134,23 @@ export default class ExampleUserProvider extends EventEmitter {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
getPollQuestion() {
|
// eslint-disable-next-line require-await
|
||||||
return Promise.resolve({
|
async getPollQuestion() {
|
||||||
question: 'Set "GO" if your position is ready for a boarding action on the Klingon cruiser',
|
if (this.pollQuestion) {
|
||||||
timestamp: Date.now()
|
return this.pollQuestion;
|
||||||
});
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setPollQuestion(pollQuestion) {
|
setPollQuestion(pollQuestion) {
|
||||||
|
if (!pollQuestion) {
|
||||||
|
// If the poll question is undefined, set it to a blank string.
|
||||||
|
// This behavior better reflects how other telemetry systems
|
||||||
|
// deal with undefined poll questions.
|
||||||
|
pollQuestion = '';
|
||||||
|
}
|
||||||
|
|
||||||
this.pollQuestion = {
|
this.pollQuestion = {
|
||||||
question: pollQuestion,
|
question: pollQuestion,
|
||||||
timestamp: Date.now()
|
timestamp: Date.now()
|
||||||
|
|||||||
@@ -33,11 +33,13 @@ define([
|
|||||||
dataRateInHz: 1,
|
dataRateInHz: 1,
|
||||||
randomness: 0,
|
randomness: 0,
|
||||||
phase: 0,
|
phase: 0,
|
||||||
loadDelay: 0
|
loadDelay: 0,
|
||||||
|
infinityValues: false
|
||||||
};
|
};
|
||||||
|
|
||||||
function GeneratorProvider(openmct) {
|
function GeneratorProvider(openmct, StalenessProvider) {
|
||||||
this.workerInterface = new WorkerInterface(openmct);
|
this.openmct = openmct;
|
||||||
|
this.workerInterface = new WorkerInterface(openmct, StalenessProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
GeneratorProvider.prototype.canProvideTelemetry = function (domainObject) {
|
GeneratorProvider.prototype.canProvideTelemetry = function (domainObject) {
|
||||||
@@ -56,7 +58,8 @@ define([
|
|||||||
'dataRateInHz',
|
'dataRateInHz',
|
||||||
'randomness',
|
'randomness',
|
||||||
'phase',
|
'phase',
|
||||||
'loadDelay'
|
'loadDelay',
|
||||||
|
'infinityValues'
|
||||||
];
|
];
|
||||||
|
|
||||||
request = request || {};
|
request = request || {};
|
||||||
@@ -79,6 +82,7 @@ define([
|
|||||||
workerRequest[prop] = Number(workerRequest[prop]);
|
workerRequest[prop] = Number(workerRequest[prop]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
workerRequest.id = this.openmct.objects.makeKeyString(domainObject.identifier);
|
||||||
workerRequest.name = domainObject.name;
|
workerRequest.name = domainObject.name;
|
||||||
|
|
||||||
return workerRequest;
|
return workerRequest;
|
||||||
|
|||||||
151
example/generator/SinewaveStalenessProvider.js
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* 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 EventEmitter from 'EventEmitter';
|
||||||
|
|
||||||
|
export default class SinewaveLimitProvider extends EventEmitter {
|
||||||
|
|
||||||
|
constructor(openmct) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.openmct = openmct;
|
||||||
|
this.observingStaleness = {};
|
||||||
|
this.watchingTheClock = false;
|
||||||
|
this.isRealTime = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
supportsStaleness(domainObject) {
|
||||||
|
return domainObject.type === 'generator';
|
||||||
|
}
|
||||||
|
|
||||||
|
isStale(domainObject, options) {
|
||||||
|
if (!this.providingStaleness(domainObject)) {
|
||||||
|
return Promise.resolve({
|
||||||
|
isStale: false,
|
||||||
|
utc: 0
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const id = this.getObjectKeyString(domainObject);
|
||||||
|
|
||||||
|
if (!this.observerExists(id)) {
|
||||||
|
this.createObserver(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve(this.observingStaleness[id].isStale);
|
||||||
|
}
|
||||||
|
|
||||||
|
subscribeToStaleness(domainObject, callback) {
|
||||||
|
const id = this.getObjectKeyString(domainObject);
|
||||||
|
|
||||||
|
if (this.isRealTime === undefined) {
|
||||||
|
this.updateRealTime(this.openmct.time.clock());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.handleClockUpdate();
|
||||||
|
|
||||||
|
if (this.observerExists(id)) {
|
||||||
|
this.addCallbackToObserver(id, callback);
|
||||||
|
} else {
|
||||||
|
this.createObserver(id, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
const intervalId = setInterval(() => {
|
||||||
|
if (this.providingStaleness(domainObject)) {
|
||||||
|
this.updateStaleness(id, !this.observingStaleness[id].isStale);
|
||||||
|
}
|
||||||
|
}, 10000);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
clearInterval(intervalId);
|
||||||
|
this.updateStaleness(id, false);
|
||||||
|
this.handleClockUpdate();
|
||||||
|
this.destroyObserver(id);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
handleClockUpdate() {
|
||||||
|
let observers = Object.values(this.observingStaleness).length > 0;
|
||||||
|
|
||||||
|
if (observers && !this.watchingTheClock) {
|
||||||
|
this.watchingTheClock = true;
|
||||||
|
this.openmct.time.on('clock', this.updateRealTime, this);
|
||||||
|
} else if (!observers && this.watchingTheClock) {
|
||||||
|
this.watchingTheClock = false;
|
||||||
|
this.openmct.time.off('clock', this.updateRealTime, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateRealTime(clock) {
|
||||||
|
this.isRealTime = clock !== undefined;
|
||||||
|
|
||||||
|
if (!this.isRealTime) {
|
||||||
|
Object.keys(this.observingStaleness).forEach((id) => {
|
||||||
|
this.updateStaleness(id, false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateStaleness(id, isStale) {
|
||||||
|
this.observingStaleness[id].isStale = isStale;
|
||||||
|
this.observingStaleness[id].utc = Date.now();
|
||||||
|
this.observingStaleness[id].callback({
|
||||||
|
isStale: this.observingStaleness[id].isStale,
|
||||||
|
utc: this.observingStaleness[id].utc
|
||||||
|
});
|
||||||
|
this.emit('stalenessEvent', {
|
||||||
|
id,
|
||||||
|
isStale: this.observingStaleness[id].isStale
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
createObserver(id, callback) {
|
||||||
|
this.observingStaleness[id] = {
|
||||||
|
isStale: false,
|
||||||
|
utc: Date.now()
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof callback === 'function') {
|
||||||
|
this.addCallbackToObserver(id, callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
destroyObserver(id) {
|
||||||
|
delete this.observingStaleness[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
providingStaleness(domainObject) {
|
||||||
|
return domainObject.telemetry?.staleness === true && this.isRealTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
getObjectKeyString(object) {
|
||||||
|
return this.openmct.objects.makeKeyString(object.identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
addCallbackToObserver(id, callback) {
|
||||||
|
this.observingStaleness[id].callback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
observerExists(id) {
|
||||||
|
return this.observingStaleness?.[id];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,14 +25,24 @@ define([
|
|||||||
], function (
|
], function (
|
||||||
{ v4: uuid }
|
{ v4: uuid }
|
||||||
) {
|
) {
|
||||||
function WorkerInterface(openmct) {
|
function WorkerInterface(openmct, StalenessProvider) {
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
const workerUrl = `${openmct.getAssetPath()}${__OPENMCT_ROOT_RELATIVE__}generatorWorker.js`;
|
const workerUrl = `${openmct.getAssetPath()}${__OPENMCT_ROOT_RELATIVE__}generatorWorker.js`;
|
||||||
|
this.StalenessProvider = StalenessProvider;
|
||||||
this.worker = new Worker(workerUrl);
|
this.worker = new Worker(workerUrl);
|
||||||
this.worker.onmessage = this.onMessage.bind(this);
|
this.worker.onmessage = this.onMessage.bind(this);
|
||||||
this.callbacks = {};
|
this.callbacks = {};
|
||||||
|
this.staleTelemetryIds = {};
|
||||||
|
|
||||||
|
this.watchStaleness();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WorkerInterface.prototype.watchStaleness = function () {
|
||||||
|
this.StalenessProvider.on('stalenessEvent', ({ id, isStale}) => {
|
||||||
|
this.staleTelemetryIds[id] = isStale;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
WorkerInterface.prototype.onMessage = function (message) {
|
WorkerInterface.prototype.onMessage = function (message) {
|
||||||
message = message.data;
|
message = message.data;
|
||||||
var callback = this.callbacks[message.id];
|
var callback = this.callbacks[message.id];
|
||||||
@@ -83,11 +93,12 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
WorkerInterface.prototype.subscribe = function (request, cb) {
|
WorkerInterface.prototype.subscribe = function (request, cb) {
|
||||||
function callback(message) {
|
const id = request.id;
|
||||||
cb(message.data);
|
const messageId = this.dispatch('subscribe', request, (message) => {
|
||||||
}
|
if (!this.staleTelemetryIds[id]) {
|
||||||
|
cb(message.data);
|
||||||
var messageId = this.dispatch('subscribe', request, callback);
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return function () {
|
return function () {
|
||||||
this.dispatch('unsubscribe', {
|
this.dispatch('unsubscribe', {
|
||||||
|
|||||||
@@ -76,10 +76,10 @@
|
|||||||
name: data.name,
|
name: data.name,
|
||||||
utc: nextStep,
|
utc: nextStep,
|
||||||
yesterday: nextStep - 60 * 60 * 24 * 1000,
|
yesterday: nextStep - 60 * 60 * 24 * 1000,
|
||||||
sin: sin(nextStep, data.period, data.amplitude, data.offset, data.phase, data.randomness),
|
sin: sin(nextStep, data.period, data.amplitude, data.offset, data.phase, data.randomness, data.infinityValues),
|
||||||
wavelengths: wavelengths(),
|
wavelengths: wavelengths(),
|
||||||
intensities: intensities(),
|
intensities: intensities(),
|
||||||
cos: cos(nextStep, data.period, data.amplitude, data.offset, data.phase, data.randomness)
|
cos: cos(nextStep, data.period, data.amplitude, data.offset, data.phase, data.randomness, data.infinityValues)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
nextStep += step;
|
nextStep += step;
|
||||||
@@ -117,6 +117,7 @@
|
|||||||
var phase = request.phase;
|
var phase = request.phase;
|
||||||
var randomness = request.randomness;
|
var randomness = request.randomness;
|
||||||
var loadDelay = Math.max(request.loadDelay, 0);
|
var loadDelay = Math.max(request.loadDelay, 0);
|
||||||
|
var infinityValues = request.infinityValues;
|
||||||
|
|
||||||
var step = 1000 / dataRateInHz;
|
var step = 1000 / dataRateInHz;
|
||||||
var nextStep = start - (start % step) + step;
|
var nextStep = start - (start % step) + step;
|
||||||
@@ -127,10 +128,10 @@
|
|||||||
data.push({
|
data.push({
|
||||||
utc: nextStep,
|
utc: nextStep,
|
||||||
yesterday: nextStep - 60 * 60 * 24 * 1000,
|
yesterday: nextStep - 60 * 60 * 24 * 1000,
|
||||||
sin: sin(nextStep, period, amplitude, offset, phase, randomness),
|
sin: sin(nextStep, period, amplitude, offset, phase, randomness, infinityValues),
|
||||||
wavelengths: wavelengths(),
|
wavelengths: wavelengths(),
|
||||||
intensities: intensities(),
|
intensities: intensities(),
|
||||||
cos: cos(nextStep, period, amplitude, offset, phase, randomness)
|
cos: cos(nextStep, period, amplitude, offset, phase, randomness, infinityValues)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,12 +156,20 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function cos(timestamp, period, amplitude, offset, phase, randomness) {
|
function cos(timestamp, period, amplitude, offset, phase, randomness, infinityValues) {
|
||||||
|
if (infinityValues && Math.random() > 0.5) {
|
||||||
|
return Number.POSITIVE_INFINITY;
|
||||||
|
}
|
||||||
|
|
||||||
return amplitude
|
return amplitude
|
||||||
* Math.cos(phase + (timestamp / period / 1000 * Math.PI * 2)) + (amplitude * Math.random() * randomness) + offset;
|
* Math.cos(phase + (timestamp / period / 1000 * Math.PI * 2)) + (amplitude * Math.random() * randomness) + offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sin(timestamp, period, amplitude, offset, phase, randomness) {
|
function sin(timestamp, period, amplitude, offset, phase, randomness, infinityValues) {
|
||||||
|
if (infinityValues && Math.random() > 0.5) {
|
||||||
|
return Number.POSITIVE_INFINITY;
|
||||||
|
}
|
||||||
|
|
||||||
return amplitude
|
return amplitude
|
||||||
* Math.sin(phase + (timestamp / period / 1000 * Math.PI * 2)) + (amplitude * Math.random() * randomness) + offset;
|
* Math.sin(phase + (timestamp / period / 1000 * Math.PI * 2)) + (amplitude * Math.random() * randomness) + offset;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,147 +20,163 @@
|
|||||||
* at runtime from the About dialog for additional information.
|
* at runtime from the About dialog for additional information.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
define([
|
import GeneratorProvider from "./GeneratorProvider";
|
||||||
"./GeneratorProvider",
|
import SinewaveLimitProvider from "./SinewaveLimitProvider";
|
||||||
"./SinewaveLimitProvider",
|
import SinewaveStalenessProvider from "./SinewaveStalenessProvider";
|
||||||
"./StateGeneratorProvider",
|
import StateGeneratorProvider from "./StateGeneratorProvider";
|
||||||
"./GeneratorMetadataProvider"
|
import GeneratorMetadataProvider from "./GeneratorMetadataProvider";
|
||||||
], function (
|
|
||||||
GeneratorProvider,
|
|
||||||
SinewaveLimitProvider,
|
|
||||||
StateGeneratorProvider,
|
|
||||||
GeneratorMetadataProvider
|
|
||||||
) {
|
|
||||||
|
|
||||||
return function (openmct) {
|
export default function (openmct) {
|
||||||
|
|
||||||
openmct.types.addType("example.state-generator", {
|
openmct.types.addType("example.state-generator", {
|
||||||
name: "State Generator",
|
name: "State Generator",
|
||||||
description: "For development use. Generates example enumerated telemetry by cycling through a given set of states.",
|
description: "For development use. Generates example enumerated telemetry by cycling through a given set of states.",
|
||||||
cssClass: "icon-generator-telemetry",
|
cssClass: "icon-generator-telemetry",
|
||||||
creatable: true,
|
creatable: true,
|
||||||
form: [
|
form: [
|
||||||
{
|
{
|
||||||
name: "State Duration (seconds)",
|
name: "State Duration (seconds)",
|
||||||
control: "numberfield",
|
control: "numberfield",
|
||||||
cssClass: "l-input-sm l-numeric",
|
cssClass: "l-input-sm l-numeric",
|
||||||
key: "duration",
|
key: "duration",
|
||||||
required: true,
|
required: true,
|
||||||
property: [
|
property: [
|
||||||
"telemetry",
|
"telemetry",
|
||||||
"duration"
|
"duration"
|
||||||
]
|
]
|
||||||
}
|
|
||||||
],
|
|
||||||
initialize: function (object) {
|
|
||||||
object.telemetry = {
|
|
||||||
duration: 5
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
});
|
],
|
||||||
|
initialize: function (object) {
|
||||||
|
object.telemetry = {
|
||||||
|
duration: 5
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
openmct.telemetry.addProvider(new StateGeneratorProvider());
|
openmct.telemetry.addProvider(new StateGeneratorProvider());
|
||||||
|
|
||||||
openmct.types.addType("generator", {
|
openmct.types.addType("generator", {
|
||||||
name: "Sine Wave Generator",
|
name: "Sine Wave Generator",
|
||||||
description: "For development use. Generates example streaming telemetry data using a simple sine wave algorithm.",
|
description: "For development use. Generates example streaming telemetry data using a simple sine wave algorithm.",
|
||||||
cssClass: "icon-generator-telemetry",
|
cssClass: "icon-generator-telemetry",
|
||||||
creatable: true,
|
creatable: true,
|
||||||
form: [
|
form: [
|
||||||
{
|
{
|
||||||
name: "Period",
|
name: "Period",
|
||||||
control: "numberfield",
|
control: "numberfield",
|
||||||
cssClass: "l-input-sm l-numeric",
|
cssClass: "l-input-sm l-numeric",
|
||||||
key: "period",
|
key: "period",
|
||||||
required: true,
|
required: true,
|
||||||
property: [
|
property: [
|
||||||
"telemetry",
|
"telemetry",
|
||||||
"period"
|
"period"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Amplitude",
|
name: "Amplitude",
|
||||||
control: "numberfield",
|
control: "numberfield",
|
||||||
cssClass: "l-numeric",
|
cssClass: "l-numeric",
|
||||||
key: "amplitude",
|
key: "amplitude",
|
||||||
required: true,
|
required: true,
|
||||||
property: [
|
property: [
|
||||||
"telemetry",
|
"telemetry",
|
||||||
"amplitude"
|
"amplitude"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Offset",
|
name: "Offset",
|
||||||
control: "numberfield",
|
control: "numberfield",
|
||||||
cssClass: "l-numeric",
|
cssClass: "l-numeric",
|
||||||
key: "offset",
|
key: "offset",
|
||||||
required: true,
|
required: true,
|
||||||
property: [
|
property: [
|
||||||
"telemetry",
|
"telemetry",
|
||||||
"offset"
|
"offset"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Data Rate (hz)",
|
name: "Data Rate (hz)",
|
||||||
control: "numberfield",
|
control: "numberfield",
|
||||||
cssClass: "l-input-sm l-numeric",
|
cssClass: "l-input-sm l-numeric",
|
||||||
key: "dataRateInHz",
|
key: "dataRateInHz",
|
||||||
required: true,
|
required: true,
|
||||||
property: [
|
property: [
|
||||||
"telemetry",
|
"telemetry",
|
||||||
"dataRateInHz"
|
"dataRateInHz"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Phase (radians)",
|
name: "Phase (radians)",
|
||||||
control: "numberfield",
|
control: "numberfield",
|
||||||
cssClass: "l-input-sm l-numeric",
|
cssClass: "l-input-sm l-numeric",
|
||||||
key: "phase",
|
key: "phase",
|
||||||
required: true,
|
required: true,
|
||||||
property: [
|
property: [
|
||||||
"telemetry",
|
"telemetry",
|
||||||
"phase"
|
"phase"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Randomness",
|
name: "Randomness",
|
||||||
control: "numberfield",
|
control: "numberfield",
|
||||||
cssClass: "l-input-sm l-numeric",
|
cssClass: "l-input-sm l-numeric",
|
||||||
key: "randomness",
|
key: "randomness",
|
||||||
required: true,
|
required: true,
|
||||||
property: [
|
property: [
|
||||||
"telemetry",
|
"telemetry",
|
||||||
"randomness"
|
"randomness"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Loading Delay (ms)",
|
name: "Loading Delay (ms)",
|
||||||
control: "numberfield",
|
control: "numberfield",
|
||||||
cssClass: "l-input-sm l-numeric",
|
cssClass: "l-input-sm l-numeric",
|
||||||
key: "loadDelay",
|
key: "loadDelay",
|
||||||
required: true,
|
required: true,
|
||||||
property: [
|
property: [
|
||||||
"telemetry",
|
"telemetry",
|
||||||
"loadDelay"
|
"loadDelay"
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
],
|
{
|
||||||
initialize: function (object) {
|
name: "Include Infinity Values",
|
||||||
object.telemetry = {
|
control: "toggleSwitch",
|
||||||
period: 10,
|
cssClass: "l-input",
|
||||||
amplitude: 1,
|
key: "infinityValues",
|
||||||
offset: 0,
|
property: [
|
||||||
dataRateInHz: 1,
|
"telemetry",
|
||||||
phase: 0,
|
"infinityValues"
|
||||||
randomness: 0,
|
]
|
||||||
loadDelay: 0
|
},
|
||||||
};
|
{
|
||||||
|
name: "Provide Staleness Updates",
|
||||||
|
control: "toggleSwitch",
|
||||||
|
cssClass: "l-input",
|
||||||
|
key: "staleness",
|
||||||
|
property: [
|
||||||
|
"telemetry",
|
||||||
|
"staleness"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
});
|
],
|
||||||
|
initialize: function (object) {
|
||||||
|
object.telemetry = {
|
||||||
|
period: 10,
|
||||||
|
amplitude: 1,
|
||||||
|
offset: 0,
|
||||||
|
dataRateInHz: 1,
|
||||||
|
phase: 0,
|
||||||
|
randomness: 0,
|
||||||
|
loadDelay: 0,
|
||||||
|
infinityValues: false,
|
||||||
|
staleness: false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const stalenessProvider = new SinewaveStalenessProvider(openmct);
|
||||||
|
|
||||||
openmct.telemetry.addProvider(new GeneratorProvider(openmct));
|
openmct.telemetry.addProvider(new GeneratorProvider(openmct, stalenessProvider));
|
||||||
openmct.telemetry.addProvider(new GeneratorMetadataProvider());
|
openmct.telemetry.addProvider(new GeneratorMetadataProvider());
|
||||||
openmct.telemetry.addProvider(new SinewaveLimitProvider());
|
openmct.telemetry.addProvider(new SinewaveLimitProvider());
|
||||||
};
|
openmct.telemetry.addProvider(stalenessProvider);
|
||||||
|
}
|
||||||
});
|
|
||||||
|
|||||||
@@ -107,6 +107,15 @@ export default function () {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'Image Thumbnail',
|
||||||
|
key: 'thumbnail-url',
|
||||||
|
format: 'thumbnail',
|
||||||
|
hints: {
|
||||||
|
thumbnail: 1
|
||||||
|
},
|
||||||
|
source: 'url'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'Image Download Name',
|
name: 'Image Download Name',
|
||||||
key: 'imageDownloadName',
|
key: 'imageDownloadName',
|
||||||
@@ -143,6 +152,16 @@ export default function () {
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const formatThumbnail = {
|
||||||
|
format: function (url) {
|
||||||
|
return `${url}?w=100&h=100`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
openmct.telemetry.addFormat({
|
||||||
|
key: 'thumbnail',
|
||||||
|
...formatThumbnail
|
||||||
|
});
|
||||||
openmct.telemetry.addProvider(getRealtimeProvider());
|
openmct.telemetry.addProvider(getRealtimeProvider());
|
||||||
openmct.telemetry.addProvider(getHistoricalProvider());
|
openmct.telemetry.addProvider(getHistoricalProvider());
|
||||||
openmct.telemetry.addProvider(getLadProvider());
|
openmct.telemetry.addProvider(getLadProvider());
|
||||||
@@ -242,6 +261,13 @@ function pointForTimestamp(timestamp, name, imageSamples, delay) {
|
|||||||
const url = imageSamples[Math.floor(timestamp / delay) % imageSamples.length];
|
const url = imageSamples[Math.floor(timestamp / delay) % imageSamples.length];
|
||||||
const urlItems = url.split('/');
|
const urlItems = url.split('/');
|
||||||
const imageDownloadName = `example.imagery.${urlItems[urlItems.length - 1]}`;
|
const imageDownloadName = `example.imagery.${urlItems[urlItems.length - 1]}`;
|
||||||
|
const navCamTransformations = {
|
||||||
|
"translateX": 0,
|
||||||
|
"translateY": 18,
|
||||||
|
"rotation": 0,
|
||||||
|
"scale": 0.3,
|
||||||
|
"cameraAngleOfView": 70
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name,
|
name,
|
||||||
@@ -251,6 +277,7 @@ function pointForTimestamp(timestamp, name, imageSamples, delay) {
|
|||||||
sunOrientation: getCompassValues(0, 360),
|
sunOrientation: getCompassValues(0, 360),
|
||||||
cameraPan: getCompassValues(0, 360),
|
cameraPan: getCompassValues(0, 360),
|
||||||
heading: getCompassValues(0, 360),
|
heading: getCompassValues(0, 360),
|
||||||
|
transformations: navCamTransformations,
|
||||||
imageDownloadName
|
imageDownloadName
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,12 +28,12 @@ module.exports = (config) => {
|
|||||||
let singleRun;
|
let singleRun;
|
||||||
|
|
||||||
if (process.env.KARMA_DEBUG) {
|
if (process.env.KARMA_DEBUG) {
|
||||||
webpackConfig = require('./webpack.dev.js');
|
webpackConfig = require("./.webpack/webpack.dev.js");
|
||||||
browsers = ['ChromeDebugging'];
|
browsers = ["ChromeDebugging"];
|
||||||
singleRun = false;
|
singleRun = false;
|
||||||
} else {
|
} else {
|
||||||
webpackConfig = require('./webpack.coverage.js');
|
webpackConfig = require("./.webpack/webpack.coverage.js");
|
||||||
browsers = ['ChromeHeadless'];
|
browsers = ["ChromeHeadless"];
|
||||||
singleRun = true;
|
singleRun = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,28 +42,28 @@ module.exports = (config) => {
|
|||||||
delete webpackConfig.entry;
|
delete webpackConfig.entry;
|
||||||
|
|
||||||
config.set({
|
config.set({
|
||||||
basePath: '',
|
basePath: "",
|
||||||
frameworks: ['jasmine', 'webpack'],
|
frameworks: ["jasmine", "webpack"],
|
||||||
files: [
|
files: [
|
||||||
'indexTest.js',
|
"indexTest.js",
|
||||||
// included means: should the files be included in the browser using <script> tag?
|
// included means: should the files be included in the browser using <script> tag?
|
||||||
// We don't want them as a <script> because the shared worker source
|
// We don't want them as a <script> because the shared worker source
|
||||||
// needs loaded remotely by the shared worker process.
|
// needs loaded remotely by the shared worker process.
|
||||||
{
|
{
|
||||||
pattern: 'dist/couchDBChangesFeed.js*',
|
pattern: "dist/couchDBChangesFeed.js*",
|
||||||
included: false
|
included: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: 'dist/inMemorySearchWorker.js*',
|
pattern: "dist/inMemorySearchWorker.js*",
|
||||||
included: false
|
included: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: 'dist/generatorWorker.js*',
|
pattern: "dist/generatorWorker.js*",
|
||||||
included: false
|
included: false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
port: 9876,
|
port: 9876,
|
||||||
reporters: ['spec', 'junit', 'coverage-istanbul'],
|
reporters: ["spec", "junit", "coverage-istanbul"],
|
||||||
browsers,
|
browsers,
|
||||||
client: {
|
client: {
|
||||||
jasmine: {
|
jasmine: {
|
||||||
@@ -73,8 +73,8 @@ module.exports = (config) => {
|
|||||||
},
|
},
|
||||||
customLaunchers: {
|
customLaunchers: {
|
||||||
ChromeDebugging: {
|
ChromeDebugging: {
|
||||||
base: 'Chrome',
|
base: "Chrome",
|
||||||
flags: ['--remote-debugging-port=9222'],
|
flags: ["--remote-debugging-port=9222"],
|
||||||
debug: true
|
debug: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -90,7 +90,7 @@ module.exports = (config) => {
|
|||||||
fixWebpackSourcePaths: true,
|
fixWebpackSourcePaths: true,
|
||||||
skipFilesWithNoCoverage: true,
|
skipFilesWithNoCoverage: true,
|
||||||
dir: "coverage/unit", //Sets coverage file to be consumed by codecov.io
|
dir: "coverage/unit", //Sets coverage file to be consumed by codecov.io
|
||||||
reports: ['lcovonly']
|
reports: ["lcovonly"]
|
||||||
},
|
},
|
||||||
specReporter: {
|
specReporter: {
|
||||||
maxLogLines: 5,
|
maxLogLines: 5,
|
||||||
@@ -102,11 +102,11 @@ module.exports = (config) => {
|
|||||||
failFast: false
|
failFast: false
|
||||||
},
|
},
|
||||||
preprocessors: {
|
preprocessors: {
|
||||||
'indexTest.js': ['webpack', 'sourcemap']
|
"indexTest.js": ["webpack", "sourcemap"]
|
||||||
},
|
},
|
||||||
webpack: webpackConfig,
|
webpack: webpackConfig,
|
||||||
webpackMiddleware: {
|
webpackMiddleware: {
|
||||||
stats: 'errors-warnings'
|
stats: "errors-warnings"
|
||||||
},
|
},
|
||||||
concurrency: 1,
|
concurrency: 1,
|
||||||
singleRun,
|
singleRun,
|
||||||
|
|||||||
45
openmct.js
@@ -30,8 +30,53 @@ if (document.currentScript) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} BuildInfo
|
||||||
|
* @property {string} version
|
||||||
|
* @property {string} buildDate
|
||||||
|
* @property {string} revision
|
||||||
|
* @property {string} branch
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} OpenMCT
|
||||||
|
* @property {BuildInfo} buildInfo
|
||||||
|
* @property {*} selection
|
||||||
|
* @property {import('./src/api/time/TimeAPI').default} time
|
||||||
|
* @property {import('./src/api/composition/CompositionAPI').default} composition
|
||||||
|
* @property {*} objectViews
|
||||||
|
* @property {*} inspectorViews
|
||||||
|
* @property {*} propertyEditors
|
||||||
|
* @property {*} toolbars
|
||||||
|
* @property {*} types
|
||||||
|
* @property {import('./src/api/objects/ObjectAPI').default} objects
|
||||||
|
* @property {import('./src/api/telemetry/TelemetryAPI').default} telemetry
|
||||||
|
* @property {import('./src/api/indicators/IndicatorAPI').default} indicators
|
||||||
|
* @property {import('./src/api/user/UserAPI').default} user
|
||||||
|
* @property {import('./src/api/notifications/NotificationAPI').default} notifications
|
||||||
|
* @property {import('./src/api/Editor').default} editor
|
||||||
|
* @property {import('./src/api/overlays/OverlayAPI')} overlays
|
||||||
|
* @property {import('./src/api/menu/MenuAPI').default} menus
|
||||||
|
* @property {import('./src/api/actions/ActionsAPI').default} actions
|
||||||
|
* @property {import('./src/api/status/StatusAPI').default} status
|
||||||
|
* @property {*} priority
|
||||||
|
* @property {import('./src/ui/router/ApplicationRouter')} router
|
||||||
|
* @property {import('./src/api/faultmanagement/FaultManagementAPI').default} faults
|
||||||
|
* @property {import('./src/api/forms/FormsAPI').default} forms
|
||||||
|
* @property {import('./src/api/Branding').default} branding
|
||||||
|
* @property {import('./src/api/annotation/AnnotationAPI').default} annotation
|
||||||
|
* @property {{(plugin: OpenMCTPlugin) => void}} install
|
||||||
|
* @property {{() => string}} getAssetPath
|
||||||
|
* @property {{(domElement: HTMLElement, isHeadlessMode: boolean) => void}} start
|
||||||
|
* @property {{() => void}} startHeadless
|
||||||
|
* @property {{() => void}} destroy
|
||||||
|
* @property {OpenMCTPlugin[]} plugins
|
||||||
|
* @property {OpenMCTComponent[]} components
|
||||||
|
*/
|
||||||
|
|
||||||
const MCT = require('./src/MCT');
|
const MCT = require('./src/MCT');
|
||||||
|
|
||||||
|
/** @type {OpenMCT} */
|
||||||
const openmct = new MCT();
|
const openmct = new MCT();
|
||||||
|
|
||||||
module.exports = openmct;
|
module.exports = openmct;
|
||||||
|
|||||||
68
package.json
@@ -1,38 +1,36 @@
|
|||||||
{
|
{
|
||||||
"name": "openmct",
|
"name": "openmct",
|
||||||
"version": "2.1.1",
|
"version": "2.1.6-SNAPSHOT",
|
||||||
"description": "The Open MCT core platform",
|
"description": "The Open MCT core platform",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/eslint-parser": "7.18.9",
|
"@babel/eslint-parser": "7.18.9",
|
||||||
"@braintree/sanitize-url": "6.0.0",
|
"@braintree/sanitize-url": "6.0.2",
|
||||||
"@percy/cli": "1.10.3",
|
"@percy/cli": "1.17.0",
|
||||||
"@percy/playwright": "1.0.4",
|
"@percy/playwright": "1.0.4",
|
||||||
"@playwright/test": "1.25.2",
|
"@playwright/test": "1.29.0",
|
||||||
"@types/eventemitter3": "^1.0.0",
|
"@types/eventemitter3": "1.2.0",
|
||||||
"@types/jasmine": "^4.0.1",
|
"@types/jasmine": "4.3.1",
|
||||||
"@types/karma": "^6.3.2",
|
"@types/lodash": "4.14.191",
|
||||||
"@types/lodash": "^4.14.178",
|
"babel-loader": "9.1.0",
|
||||||
"@types/mocha": "^9.1.0",
|
|
||||||
"babel-loader": "8.2.5",
|
|
||||||
"babel-plugin-istanbul": "6.1.1",
|
"babel-plugin-istanbul": "6.1.1",
|
||||||
"codecov": "3.8.3",
|
"codecov": "3.8.3",
|
||||||
"comma-separated-values": "3.6.4",
|
"comma-separated-values": "3.6.4",
|
||||||
"copy-webpack-plugin": "11.0.0",
|
"copy-webpack-plugin": "11.0.0",
|
||||||
"css-loader": "6.7.1",
|
"css-loader": "6.7.3",
|
||||||
"d3-axis": "3.0.0",
|
"d3-axis": "3.0.0",
|
||||||
"d3-scale": "3.3.0",
|
"d3-scale": "3.3.0",
|
||||||
"d3-selection": "3.0.0",
|
"d3-selection": "3.0.0",
|
||||||
"eslint": "8.23.1",
|
"eslint": "8.32.0",
|
||||||
"eslint-plugin-compat": "4.0.2",
|
"eslint-plugin-compat": "4.0.2",
|
||||||
"eslint-plugin-playwright": "0.11.2",
|
"eslint-plugin-playwright": "0.12.0",
|
||||||
"eslint-plugin-vue": "9.3.0",
|
"eslint-plugin-vue": "9.9.0",
|
||||||
"eslint-plugin-you-dont-need-lodash-underscore": "6.12.0",
|
"eslint-plugin-you-dont-need-lodash-underscore": "6.12.0",
|
||||||
"eventemitter3": "1.2.0",
|
"eventemitter3": "1.2.0",
|
||||||
"file-saver": "2.0.5",
|
"file-saver": "2.0.5",
|
||||||
"git-rev-sync": "3.0.2",
|
"git-rev-sync": "3.0.2",
|
||||||
"html2canvas": "1.4.1",
|
"html2canvas": "1.4.1",
|
||||||
"imports-loader": "4.0.1",
|
"imports-loader": "4.0.1",
|
||||||
"jasmine-core": "4.4.0",
|
"jasmine-core": "4.5.0",
|
||||||
"karma": "6.3.20",
|
"karma": "6.3.20",
|
||||||
"karma-chrome-launcher": "3.1.1",
|
"karma-chrome-launcher": "3.1.1",
|
||||||
"karma-cli": "2.0.0",
|
"karma-cli": "2.0.0",
|
||||||
@@ -41,46 +39,49 @@
|
|||||||
"karma-jasmine": "5.1.0",
|
"karma-jasmine": "5.1.0",
|
||||||
"karma-junit-reporter": "2.0.1",
|
"karma-junit-reporter": "2.0.1",
|
||||||
"karma-sourcemap-loader": "0.3.8",
|
"karma-sourcemap-loader": "0.3.8",
|
||||||
"karma-spec-reporter": "0.0.34",
|
"karma-spec-reporter": "0.0.36",
|
||||||
"karma-webpack": "5.0.0",
|
"karma-webpack": "5.0.0",
|
||||||
|
"kdbush": "^3.0.0",
|
||||||
"location-bar": "3.0.1",
|
"location-bar": "3.0.1",
|
||||||
"lodash": "4.17.21",
|
"lodash": "4.17.21",
|
||||||
"mini-css-extract-plugin": "2.6.1",
|
"mini-css-extract-plugin": "2.7.2",
|
||||||
"moment": "2.29.4",
|
"moment": "2.29.4",
|
||||||
"moment-duration-format": "2.3.2",
|
"moment-duration-format": "2.3.2",
|
||||||
"moment-timezone": "0.5.37",
|
"moment-timezone": "0.5.40",
|
||||||
"nyc": "15.1.0",
|
"nyc": "15.1.0",
|
||||||
"painterro": "1.2.78",
|
"painterro": "1.2.78",
|
||||||
"playwright-core": "1.25.2",
|
"playwright-core": "1.29.0",
|
||||||
"plotly.js-basic-dist": "2.14.0",
|
"plotly.js-basic-dist": "2.17.0",
|
||||||
"plotly.js-gl2d-dist": "2.14.0",
|
"plotly.js-gl2d-dist": "2.17.1",
|
||||||
"printj": "1.3.1",
|
"printj": "1.3.1",
|
||||||
"resolve-url-loader": "5.0.0",
|
"resolve-url-loader": "5.0.0",
|
||||||
"sass": "1.55.0",
|
"sanitize-html": "2.8.1",
|
||||||
"sass-loader": "13.0.2",
|
"sass": "1.57.1",
|
||||||
"sinon": "14.0.0",
|
"sass-loader": "13.2.0",
|
||||||
|
"sinon": "15.0.1",
|
||||||
"style-loader": "^3.3.1",
|
"style-loader": "^3.3.1",
|
||||||
|
"typescript": "4.9.4",
|
||||||
"uuid": "9.0.0",
|
"uuid": "9.0.0",
|
||||||
"vue": "2.6.14",
|
"vue": "2.6.14",
|
||||||
"vue-eslint-parser": "9.1.0",
|
"vue-eslint-parser": "9.1.0",
|
||||||
"vue-loader": "15.9.8",
|
"vue-loader": "15.9.8",
|
||||||
"vue-template-compiler": "2.6.14",
|
"vue-template-compiler": "2.6.14",
|
||||||
"webpack": "5.74.0",
|
"webpack": "5.74.0",
|
||||||
"webpack-cli": "4.10.0",
|
"webpack-cli": "5.0.0",
|
||||||
"webpack-dev-server": "4.11.1",
|
"webpack-dev-server": "4.11.1",
|
||||||
"webpack-merge": "5.8.0"
|
"webpack-merge": "5.8.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rm -rf ./dist ./node_modules ./package-lock.json",
|
"clean": "rm -rf ./dist ./node_modules ./package-lock.json",
|
||||||
"clean-test-lint": "npm run clean; npm install; npm run test; npm run lint",
|
"clean-test-lint": "npm run clean; npm install; npm run test; npm run lint",
|
||||||
"start": "npx webpack serve --config ./webpack.dev.js",
|
"start": "npx webpack serve --config ./.webpack/webpack.dev.js",
|
||||||
"start:coverage": "npx webpack serve --config ./webpack.coverage.js",
|
"start:coverage": "npx webpack serve --config ./.webpack/webpack.coverage.js",
|
||||||
"lint": "eslint example src e2e --ext .js,.vue openmct.js --max-warnings=0",
|
"lint": "eslint example src e2e --ext .js,.vue openmct.js --max-warnings=0",
|
||||||
"lint:fix": "eslint example src e2e --ext .js,.vue openmct.js --fix",
|
"lint:fix": "eslint example src e2e --ext .js,.vue openmct.js --fix",
|
||||||
"build:prod": "webpack --config webpack.prod.js",
|
"build:prod": "webpack --config ./.webpack/webpack.prod.js",
|
||||||
"build:dev": "webpack --config webpack.dev.js",
|
"build:dev": "webpack --config ./.webpack/webpack.dev.js",
|
||||||
"build:coverage": "webpack --config webpack.coverage.js",
|
"build:coverage": "webpack --config ./.webpack/webpack.coverage.js",
|
||||||
"build:watch": "webpack --config webpack.dev.js --watch",
|
"build:watch": "webpack --config ./.webpack/webpack.dev.js --watch",
|
||||||
"info": "npx envinfo --system --browsers --npmPackages --binaries --languages --markdown",
|
"info": "npx envinfo --system --browsers --npmPackages --binaries --languages --markdown",
|
||||||
"test": "karma start",
|
"test": "karma start",
|
||||||
"test:debug": "KARMA_DEBUG=true karma start",
|
"test:debug": "KARMA_DEBUG=true karma start",
|
||||||
@@ -99,7 +100,7 @@
|
|||||||
"cov:e2e:full:publish": "codecov --disable=gcov -f ./coverage/e2e/lcov.info -F e2e-full",
|
"cov:e2e:full:publish": "codecov --disable=gcov -f ./coverage/e2e/lcov.info -F e2e-full",
|
||||||
"cov:e2e:stable:publish": "codecov --disable=gcov -f ./coverage/e2e/lcov.info -F e2e-stable",
|
"cov:e2e:stable:publish": "codecov --disable=gcov -f ./coverage/e2e/lcov.info -F e2e-stable",
|
||||||
"cov:unit:publish": "codecov --disable=gcov -f ./coverage/unit/lcov.info -F unit",
|
"cov:unit:publish": "codecov --disable=gcov -f ./coverage/unit/lcov.info -F unit",
|
||||||
"prepare": "npm run build:prod"
|
"prepare": "npm run build:prod && npx tsc"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -116,6 +117,5 @@
|
|||||||
"ios_saf > 15"
|
"ios_saf > 15"
|
||||||
],
|
],
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0"
|
||||||
"private": true
|
|
||||||
}
|
}
|
||||||
|
|||||||
19
src/MCT.js
@@ -19,7 +19,7 @@
|
|||||||
* this source code distribution or the Licensing information page available
|
* this source code distribution or the Licensing information page available
|
||||||
* at runtime from the About dialog for additional information.
|
* at runtime from the About dialog for additional information.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
/* eslint-disable no-undef */
|
||||||
define([
|
define([
|
||||||
'EventEmitter',
|
'EventEmitter',
|
||||||
'./api/api',
|
'./api/api',
|
||||||
@@ -81,13 +81,11 @@ define([
|
|||||||
/**
|
/**
|
||||||
* The Open MCT application. This may be configured by installing plugins
|
* The Open MCT application. This may be configured by installing plugins
|
||||||
* or registering extensions before the application is started.
|
* or registering extensions before the application is started.
|
||||||
* @class MCT
|
* @constructor
|
||||||
* @memberof module:openmct
|
* @memberof module:openmct
|
||||||
* @augments {EventEmitter}
|
|
||||||
*/
|
*/
|
||||||
function MCT() {
|
function MCT() {
|
||||||
EventEmitter.call(this);
|
EventEmitter.call(this);
|
||||||
/* eslint-disable no-undef */
|
|
||||||
this.buildInfo = {
|
this.buildInfo = {
|
||||||
version: __OPENMCT_VERSION__,
|
version: __OPENMCT_VERSION__,
|
||||||
buildDate: __OPENMCT_BUILD_DATE__,
|
buildDate: __OPENMCT_BUILD_DATE__,
|
||||||
@@ -101,7 +99,7 @@ define([
|
|||||||
* Tracks current selection state of the application.
|
* Tracks current selection state of the application.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
['selection', () => new Selection(this)],
|
['selection', () => new Selection.default(this)],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MCT's time conductor, which may be used to synchronize view contents
|
* MCT's time conductor, which may be used to synchronize view contents
|
||||||
@@ -125,7 +123,7 @@ define([
|
|||||||
* @memberof module:openmct.MCT#
|
* @memberof module:openmct.MCT#
|
||||||
* @name composition
|
* @name composition
|
||||||
*/
|
*/
|
||||||
['composition', () => new api.CompositionAPI(this)],
|
['composition', () => new api.CompositionAPI.default(this)],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registry for views of domain objects which should appear in the
|
* Registry for views of domain objects which should appear in the
|
||||||
@@ -258,6 +256,15 @@ define([
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MCT's annotation API that enables
|
||||||
|
* human-created comments and categorization linked to data products
|
||||||
|
* @type {module:openmct.AnnotationAPI}
|
||||||
|
* @memberof module:openmct.MCT#
|
||||||
|
* @name annotation
|
||||||
|
*/
|
||||||
|
this.annotation = new api.AnnotationAPI(this);
|
||||||
|
|
||||||
// Plugins that are installed by default
|
// Plugins that are installed by default
|
||||||
this.install(this.plugins.Plot());
|
this.install(this.plugins.Plot());
|
||||||
this.install(this.plugins.TelemetryTable.default());
|
this.install(this.plugins.TelemetryTable.default());
|
||||||
|
|||||||
@@ -23,8 +23,7 @@
|
|||||||
let brandingOptions = {};
|
let brandingOptions = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} BrandingOptions
|
* @typedef {object} BrandingOptions
|
||||||
* @memberOf openmct/branding
|
|
||||||
* @property {string} smallLogoImage URL to the image to use as the applications logo.
|
* @property {string} smallLogoImage URL to the image to use as the applications logo.
|
||||||
* This logo will appear on every screen and when clicked will launch the about dialog.
|
* This logo will appear on every screen and when clicked will launch the about dialog.
|
||||||
* @property {string} aboutHtml Custom content for the about screen. When defined the
|
* @property {string} aboutHtml Custom content for the about screen. When defined the
|
||||||
|
|||||||
@@ -56,17 +56,12 @@ export default class Editor extends EventEmitter {
|
|||||||
* Save any unsaved changes from this editing session. This will
|
* Save any unsaved changes from this editing session. This will
|
||||||
* end the current transaction.
|
* end the current transaction.
|
||||||
*/
|
*/
|
||||||
save() {
|
async save() {
|
||||||
const transaction = this.openmct.objects.getActiveTransaction();
|
const transaction = this.openmct.objects.getActiveTransaction();
|
||||||
|
await transaction.commit();
|
||||||
return transaction.commit()
|
this.editing = false;
|
||||||
.then(() => {
|
this.emit('isEditing', false);
|
||||||
this.editing = false;
|
this.openmct.objects.endTransaction();
|
||||||
this.emit('isEditing', false);
|
|
||||||
this.openmct.objects.endTransaction();
|
|
||||||
}).catch(error => {
|
|
||||||
throw error;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -78,6 +73,10 @@ export default class Editor extends EventEmitter {
|
|||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const transaction = this.openmct.objects.getActiveTransaction();
|
const transaction = this.openmct.objects.getActiveTransaction();
|
||||||
|
if (!transaction) {
|
||||||
|
return resolve();
|
||||||
|
}
|
||||||
|
|
||||||
transaction.cancel()
|
transaction.cancel()
|
||||||
.then(resolve)
|
.then(resolve)
|
||||||
.catch(reject)
|
.catch(reject)
|
||||||
|
|||||||
@@ -52,6 +52,29 @@ const ANNOTATION_LAST_CREATED = 'annotationLastCreated';
|
|||||||
* @property {String} foregroundColor eg. "#ffffff"
|
* @property {String} foregroundColor eg. "#ffffff"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {import('../objects/ObjectAPI').DomainObject} DomainObject
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {import('../objects/ObjectAPI').Identifier} Identifier
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {import('../../../openmct').OpenMCT} OpenMCT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An interface for interacting with annotations of domain objects.
|
||||||
|
* An annotation of a domain object is an operator created object for the purposes
|
||||||
|
* of further describing data in plots, notebooks, maps, etc. For example, an annotation
|
||||||
|
* could be a tag on a plot notating an interesting set of points labeled SCIENCE. It could
|
||||||
|
* also be set of notebook entries the operator has tagged DRIVING when a robot monitored by OpenMCT
|
||||||
|
* about rationals behind why the robot has taken a certain path.
|
||||||
|
* Annotations are discoverable using search, and are typically rendered in OpenMCT views to bring attention
|
||||||
|
* to other users.
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
export default class AnnotationAPI extends EventEmitter {
|
export default class AnnotationAPI extends EventEmitter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -81,24 +104,26 @@ export default class AnnotationAPI extends EventEmitter {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the a generic annotation
|
* Creates an annotation on a given domain object (e.g., a plot) and a set of targets (e.g., telemetry objects)
|
||||||
* @typedef {Object} CreateAnnotationOptions
|
* @typedef {Object} CreateAnnotationOptions
|
||||||
* @property {String} name a name for the new parameter
|
* @property {String} name a name for the new annotation (e.g., "Plot annnotation")
|
||||||
* @property {import('../objects/ObjectAPI').DomainObject} domainObject the domain object to create
|
* @property {DomainObject} domainObject the domain object this annotation was created with
|
||||||
* @property {ANNOTATION_TYPES} annotationType the type of annotation to create
|
* @property {ANNOTATION_TYPES} annotationType the type of annotation to create (e.g., PLOT_SPATIAL)
|
||||||
* @property {Tag[]} tags
|
* @property {Tag[]} tags tags to add to the annotation, e.g., SCIENCE for science related annotations
|
||||||
* @property {String} contentText
|
* @property {String} contentText Some text to add to the annotation, e.g. ("This annotation is about science")
|
||||||
* @property {import('../objects/ObjectAPI').Identifier[]} targets
|
* @property {Object<string, Object>} targets The targets ID keystrings and their specific properties.
|
||||||
|
* For plots, this will be a bounding box, e.g.: {maxY: 100, minY: 0, maxX: 100, minX: 0}
|
||||||
|
* For notebooks, this will be an entry ID, e.g.: {entryId: "entry-ecb158f5-d23c-45e1-a704-649b382622ba"}
|
||||||
|
* @property {DomainObject>} targetDomainObjects the targets ID keystrings and the domain objects this annotation points to (e.g., telemetry objects for a plot)
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* @method create
|
* @method create
|
||||||
* @param {CreateAnnotationOptions} options
|
* @param {CreateAnnotationOptions} options
|
||||||
* @returns {Promise<import('../objects/ObjectAPI').DomainObject>} a promise which will resolve when the domain object
|
* @returns {Promise<DomainObject>} a promise which will resolve when the domain object
|
||||||
* has been created, or be rejected if it cannot be saved
|
* has been created, or be rejected if it cannot be saved
|
||||||
*/
|
*/
|
||||||
async create({name, domainObject, annotationType, tags, contentText, targets}) {
|
async create({name, domainObject, annotationType, tags, contentText, targets, targetDomainObjects}) {
|
||||||
if (!Object.keys(this.ANNOTATION_TYPES).includes(annotationType)) {
|
if (!Object.keys(this.ANNOTATION_TYPES).includes(annotationType)) {
|
||||||
throw new Error(`Unknown annotation type: ${annotationType}`);
|
throw new Error(`Unknown annotation type: ${annotationType}`);
|
||||||
}
|
}
|
||||||
@@ -107,6 +132,10 @@ export default class AnnotationAPI extends EventEmitter {
|
|||||||
throw new Error(`At least one target is required to create an annotation`);
|
throw new Error(`At least one target is required to create an annotation`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!Object.keys(targetDomainObjects).length) {
|
||||||
|
throw new Error(`At least one targetDomainObject is required to create an annotation`);
|
||||||
|
}
|
||||||
|
|
||||||
const domainObjectKeyString = this.openmct.objects.makeKeyString(domainObject.identifier);
|
const domainObjectKeyString = this.openmct.objects.makeKeyString(domainObject.identifier);
|
||||||
const originalPathObjects = await this.openmct.objects.getOriginalPath(domainObjectKeyString);
|
const originalPathObjects = await this.openmct.objects.getOriginalPath(domainObjectKeyString);
|
||||||
const originalContextPath = this.openmct.objects.getRelativePath(originalPathObjects);
|
const originalContextPath = this.openmct.objects.getRelativePath(originalPathObjects);
|
||||||
@@ -139,7 +168,9 @@ export default class AnnotationAPI extends EventEmitter {
|
|||||||
const success = await this.openmct.objects.save(createdObject);
|
const success = await this.openmct.objects.save(createdObject);
|
||||||
if (success) {
|
if (success) {
|
||||||
this.emit('annotationCreated', createdObject);
|
this.emit('annotationCreated', createdObject);
|
||||||
this.#updateAnnotationModified(domainObject);
|
Object.values(targetDomainObjects).forEach(targetDomainObject => {
|
||||||
|
this.#updateAnnotationModified(targetDomainObject);
|
||||||
|
});
|
||||||
|
|
||||||
return createdObject;
|
return createdObject;
|
||||||
} else {
|
} else {
|
||||||
@@ -147,8 +178,15 @@ export default class AnnotationAPI extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#updateAnnotationModified(domainObject) {
|
#updateAnnotationModified(targetDomainObject) {
|
||||||
this.openmct.objects.mutate(domainObject, this.ANNOTATION_LAST_CREATED, Date.now());
|
// As certain telemetry objects are immutable, we'll need to check here first
|
||||||
|
// to see if we can add the annotation last created property.
|
||||||
|
// TODO: This should be removed once we have a better way to handle immutable telemetry objects
|
||||||
|
if (targetDomainObject.isMutable) {
|
||||||
|
this.openmct.objects.mutate(targetDomainObject, this.ANNOTATION_LAST_CREATED, Date.now());
|
||||||
|
} else {
|
||||||
|
this.emit('targetDomainObjectAnnotated', targetDomainObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -162,7 +200,7 @@ export default class AnnotationAPI extends EventEmitter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @method isAnnotation
|
* @method isAnnotation
|
||||||
* @param {import('../objects/ObjectAPI').DomainObject} domainObject domainObject the domainObject in question
|
* @param {DomainObject} domainObject the domainObject in question
|
||||||
* @returns {Boolean} Returns true if the domain object is an annotation
|
* @returns {Boolean} Returns true if the domain object is an annotation
|
||||||
*/
|
*/
|
||||||
isAnnotation(domainObject) {
|
isAnnotation(domainObject) {
|
||||||
@@ -190,56 +228,19 @@ export default class AnnotationAPI extends EventEmitter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @method getAnnotations
|
* @method getAnnotations
|
||||||
* @param {String} query - The keystring of the domain object to search for annotations for
|
* @param {Identifier} domainObjectIdentifier - The domain object identifier to use to search for annotations. For example, a telemetry object identifier.
|
||||||
* @returns {import('../objects/ObjectAPI').DomainObject[]} Returns an array of domain objects that match the search query
|
* @returns {DomainObject[]} Returns an array of annotations that match the search query
|
||||||
*/
|
*/
|
||||||
async getAnnotations(query) {
|
async getAnnotations(domainObjectIdentifier) {
|
||||||
const searchResults = (await Promise.all(this.openmct.objects.search(query, null, this.openmct.objects.SEARCH_TYPES.ANNOTATIONS))).flat();
|
const keyStringQuery = this.openmct.objects.makeKeyString(domainObjectIdentifier);
|
||||||
|
const searchResults = (await Promise.all(this.openmct.objects.search(keyStringQuery, null, this.openmct.objects.SEARCH_TYPES.ANNOTATIONS))).flat();
|
||||||
|
|
||||||
return searchResults;
|
return searchResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @method addSingleAnnotationTag
|
|
||||||
* @param {import('../objects/ObjectAPI').DomainObject=} existingAnnotation - An optional annotation to add the tag to. If not specified, we will create an annotation.
|
|
||||||
* @param {import('../objects/ObjectAPI').DomainObject} targetDomainObject - The domain object the annotation will point to.
|
|
||||||
* @param {Object=} targetSpecificDetails - Optional object to add to the target object. E.g., for notebooks this would be an entryID
|
|
||||||
* @param {AnnotationType} annotationType - The type of annotation this is for.
|
|
||||||
* @returns {import('../objects/ObjectAPI').DomainObject[]} Returns the annotation that was either created or passed as an existingAnnotation
|
|
||||||
*/
|
|
||||||
async addSingleAnnotationTag(existingAnnotation, targetDomainObject, targetSpecificDetails, annotationType, tag) {
|
|
||||||
if (!existingAnnotation) {
|
|
||||||
const targets = {};
|
|
||||||
const targetKeyString = this.openmct.objects.makeKeyString(targetDomainObject.identifier);
|
|
||||||
targets[targetKeyString] = targetSpecificDetails;
|
|
||||||
const contentText = `${annotationType} tag`;
|
|
||||||
const annotationCreationArguments = {
|
|
||||||
name: contentText,
|
|
||||||
domainObject: targetDomainObject,
|
|
||||||
annotationType,
|
|
||||||
tags: [tag],
|
|
||||||
contentText,
|
|
||||||
targets
|
|
||||||
};
|
|
||||||
const newAnnotation = await this.create(annotationCreationArguments);
|
|
||||||
|
|
||||||
return newAnnotation;
|
|
||||||
} else {
|
|
||||||
if (!existingAnnotation.tags.includes(tag)) {
|
|
||||||
throw new Error(`Existing annotation did not contain tag ${tag}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (existingAnnotation._deleted) {
|
|
||||||
this.unDeleteAnnotation(existingAnnotation);
|
|
||||||
}
|
|
||||||
|
|
||||||
return existingAnnotation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method deleteAnnotations
|
* @method deleteAnnotations
|
||||||
* @param {import('../objects/ObjectAPI').DomainObject[]} existingAnnotation - An array of annotations to delete (set _deleted to true)
|
* @param {DomainObject[]} existingAnnotation - An array of annotations to delete (set _deleted to true)
|
||||||
*/
|
*/
|
||||||
deleteAnnotations(annotations) {
|
deleteAnnotations(annotations) {
|
||||||
if (!annotations) {
|
if (!annotations) {
|
||||||
@@ -255,7 +256,7 @@ export default class AnnotationAPI extends EventEmitter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @method deleteAnnotations
|
* @method deleteAnnotations
|
||||||
* @param {import('../objects/ObjectAPI').DomainObject} existingAnnotation - An annotations to undelete (set _deleted to false)
|
* @param {DomainObject} annotation - An annotation to undelete (set _deleted to false)
|
||||||
*/
|
*/
|
||||||
unDeleteAnnotation(annotation) {
|
unDeleteAnnotation(annotation) {
|
||||||
if (!annotation) {
|
if (!annotation) {
|
||||||
@@ -265,6 +266,39 @@ export default class AnnotationAPI extends EventEmitter {
|
|||||||
this.openmct.objects.mutate(annotation, '_deleted', false);
|
this.openmct.objects.mutate(annotation, '_deleted', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getTagsFromAnnotations(annotations, filterDuplicates = true) {
|
||||||
|
if (!annotations) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
let tagsFromAnnotations = annotations.flatMap((annotation) => {
|
||||||
|
if (annotation._deleted) {
|
||||||
|
return [];
|
||||||
|
} else {
|
||||||
|
return annotation.tags;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (filterDuplicates) {
|
||||||
|
tagsFromAnnotations = tagsFromAnnotations.filter((tag, index, tagArray) => {
|
||||||
|
return tagArray.indexOf(tag) === index;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const fullTagModels = this.#addTagMetaInformationToTags(tagsFromAnnotations);
|
||||||
|
|
||||||
|
return fullTagModels;
|
||||||
|
}
|
||||||
|
|
||||||
|
#addTagMetaInformationToTags(tags) {
|
||||||
|
return tags.map(tagKey => {
|
||||||
|
const tagModel = this.availableTags[tagKey];
|
||||||
|
tagModel.tagID = tagKey;
|
||||||
|
|
||||||
|
return tagModel;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#getMatchingTags(query) {
|
#getMatchingTags(query) {
|
||||||
if (!query) {
|
if (!query) {
|
||||||
return [];
|
return [];
|
||||||
@@ -283,12 +317,7 @@ export default class AnnotationAPI extends EventEmitter {
|
|||||||
|
|
||||||
#addTagMetaInformationToResults(results, matchingTagKeys) {
|
#addTagMetaInformationToResults(results, matchingTagKeys) {
|
||||||
const tagsAddedToResults = results.map(result => {
|
const tagsAddedToResults = results.map(result => {
|
||||||
const fullTagModels = result.tags.map(tagKey => {
|
const fullTagModels = this.#addTagMetaInformationToTags(result.tags);
|
||||||
const tagModel = this.availableTags[tagKey];
|
|
||||||
tagModel.tagID = tagKey;
|
|
||||||
|
|
||||||
return tagModel;
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
fullTagModels,
|
fullTagModels,
|
||||||
@@ -338,6 +367,33 @@ export default class AnnotationAPI extends EventEmitter {
|
|||||||
return combinedResults;
|
return combinedResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method #breakApartSeparateTargets
|
||||||
|
* @param {Array} results A set of search results that could have the multiple targets for the same result
|
||||||
|
* @returns {Array} The same set of results, but with each target separated out into its own result
|
||||||
|
*/
|
||||||
|
#breakApartSeparateTargets(results) {
|
||||||
|
const separateResults = [];
|
||||||
|
results.forEach(result => {
|
||||||
|
Object.keys(result.targets).forEach(targetID => {
|
||||||
|
const separatedResult = {
|
||||||
|
...result
|
||||||
|
};
|
||||||
|
separatedResult.targets = {
|
||||||
|
[targetID]: result.targets[targetID]
|
||||||
|
};
|
||||||
|
separatedResult.targetModels = result.targetModels.filter(targetModel => {
|
||||||
|
const targetKeyString = this.openmct.objects.makeKeyString(targetModel.identifier);
|
||||||
|
|
||||||
|
return targetKeyString === targetID;
|
||||||
|
});
|
||||||
|
separateResults.push(separatedResult);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return separateResults;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method searchForTags
|
* @method searchForTags
|
||||||
* @param {String} query A query to match against tags. E.g., "dr" will match the tags "drilling" and "driving"
|
* @param {String} query A query to match against tags. E.g., "dr" will match the tags "drilling" and "driving"
|
||||||
@@ -360,7 +416,8 @@ export default class AnnotationAPI extends EventEmitter {
|
|||||||
const resultsWithValidPath = appliedTargetsModels.filter(result => {
|
const resultsWithValidPath = appliedTargetsModels.filter(result => {
|
||||||
return this.openmct.objects.isReachable(result.targetModels?.[0]?.originalPath);
|
return this.openmct.objects.isReachable(result.targetModels?.[0]?.originalPath);
|
||||||
});
|
});
|
||||||
|
const breakApartSeparateTargets = this.#breakApartSeparateTargets(resultsWithValidPath);
|
||||||
|
|
||||||
return resultsWithValidPath;
|
return breakApartSeparateTargets;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,7 +94,6 @@ describe("The Annotation API", () => {
|
|||||||
openmct.startHeadless();
|
openmct.startHeadless();
|
||||||
});
|
});
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
openmct.objects.providers = {};
|
|
||||||
await resetApplicationState(openmct);
|
await resetApplicationState(openmct);
|
||||||
});
|
});
|
||||||
it("is defined", () => {
|
it("is defined", () => {
|
||||||
@@ -109,6 +108,7 @@ describe("The Annotation API", () => {
|
|||||||
annotationType: openmct.annotation.ANNOTATION_TYPES.NOTEBOOK,
|
annotationType: openmct.annotation.ANNOTATION_TYPES.NOTEBOOK,
|
||||||
tags: ['sometag'],
|
tags: ['sometag'],
|
||||||
contentText: "fooContext",
|
contentText: "fooContext",
|
||||||
|
targetDomainObjects: [mockDomainObject],
|
||||||
targets: {'fooTarget': {}}
|
targets: {'fooTarget': {}}
|
||||||
};
|
};
|
||||||
const annotationObject = await openmct.annotation.create(annotationCreationArguments);
|
const annotationObject = await openmct.annotation.create(annotationCreationArguments);
|
||||||
@@ -125,27 +125,39 @@ describe("The Annotation API", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Tagging", () => {
|
describe("Tagging", () => {
|
||||||
|
let tagCreationArguments;
|
||||||
|
beforeEach(() => {
|
||||||
|
tagCreationArguments = {
|
||||||
|
name: 'Test Annotation',
|
||||||
|
domainObject: mockDomainObject,
|
||||||
|
annotationType: openmct.annotation.ANNOTATION_TYPES.NOTEBOOK,
|
||||||
|
tags: ['aWonderfulTag'],
|
||||||
|
contentText: 'fooContext',
|
||||||
|
targets: {'fooNameSpace:some-object': {entryId: 'fooBarEntry'}},
|
||||||
|
targetDomainObjects: [mockDomainObject]
|
||||||
|
};
|
||||||
|
});
|
||||||
it("can create a tag", async () => {
|
it("can create a tag", async () => {
|
||||||
const annotationObject = await openmct.annotation.addSingleAnnotationTag(null, mockDomainObject, {entryId: 'foo'}, openmct.annotation.ANNOTATION_TYPES.NOTEBOOK, 'aWonderfulTag');
|
const annotationObject = await openmct.annotation.create(tagCreationArguments);
|
||||||
expect(annotationObject).toBeDefined();
|
expect(annotationObject).toBeDefined();
|
||||||
expect(annotationObject.type).toEqual('annotation');
|
expect(annotationObject.type).toEqual('annotation');
|
||||||
expect(annotationObject.tags).toContain('aWonderfulTag');
|
expect(annotationObject.tags).toContain('aWonderfulTag');
|
||||||
});
|
});
|
||||||
it("can delete a tag", async () => {
|
it("can delete a tag", async () => {
|
||||||
const annotationObject = await openmct.annotation.addSingleAnnotationTag(null, mockDomainObject, {entryId: 'foo'}, openmct.annotation.ANNOTATION_TYPES.NOTEBOOK, 'aWonderfulTag');
|
const annotationObject = await openmct.annotation.create(tagCreationArguments);
|
||||||
expect(annotationObject).toBeDefined();
|
expect(annotationObject).toBeDefined();
|
||||||
openmct.annotation.deleteAnnotations([annotationObject]);
|
openmct.annotation.deleteAnnotations([annotationObject]);
|
||||||
expect(annotationObject._deleted).toBeTrue();
|
expect(annotationObject._deleted).toBeTrue();
|
||||||
});
|
});
|
||||||
it("throws an error if deleting non-existent tag", async () => {
|
it("throws an error if deleting non-existent tag", async () => {
|
||||||
const annotationObject = await openmct.annotation.addSingleAnnotationTag(null, mockDomainObject, {entryId: 'foo'}, openmct.annotation.ANNOTATION_TYPES.NOTEBOOK, 'aWonderfulTag');
|
const annotationObject = await openmct.annotation.create(tagCreationArguments);
|
||||||
expect(annotationObject).toBeDefined();
|
expect(annotationObject).toBeDefined();
|
||||||
expect(() => {
|
expect(() => {
|
||||||
openmct.annotation.removeAnnotationTag(annotationObject, 'ThisTagShouldNotExist');
|
openmct.annotation.removeAnnotationTag(annotationObject, 'ThisTagShouldNotExist');
|
||||||
}).toThrow();
|
}).toThrow();
|
||||||
});
|
});
|
||||||
it("can remove all tags", async () => {
|
it("can remove all tags", async () => {
|
||||||
const annotationObject = await openmct.annotation.addSingleAnnotationTag(null, mockDomainObject, {entryId: 'foo'}, openmct.annotation.ANNOTATION_TYPES.NOTEBOOK, 'aWonderfulTag');
|
const annotationObject = await openmct.annotation.create(tagCreationArguments);
|
||||||
expect(annotationObject).toBeDefined();
|
expect(annotationObject).toBeDefined();
|
||||||
expect(() => {
|
expect(() => {
|
||||||
openmct.annotation.deleteAnnotations([annotationObject]);
|
openmct.annotation.deleteAnnotations([annotationObject]);
|
||||||
@@ -153,13 +165,13 @@ describe("The Annotation API", () => {
|
|||||||
expect(annotationObject._deleted).toBeTrue();
|
expect(annotationObject._deleted).toBeTrue();
|
||||||
});
|
});
|
||||||
it("can add/delete/add a tag", async () => {
|
it("can add/delete/add a tag", async () => {
|
||||||
let annotationObject = await openmct.annotation.addSingleAnnotationTag(null, mockDomainObject, {entryId: 'foo'}, openmct.annotation.ANNOTATION_TYPES.NOTEBOOK, 'aWonderfulTag');
|
let annotationObject = await openmct.annotation.create(tagCreationArguments);
|
||||||
expect(annotationObject).toBeDefined();
|
expect(annotationObject).toBeDefined();
|
||||||
expect(annotationObject.type).toEqual('annotation');
|
expect(annotationObject.type).toEqual('annotation');
|
||||||
expect(annotationObject.tags).toContain('aWonderfulTag');
|
expect(annotationObject.tags).toContain('aWonderfulTag');
|
||||||
openmct.annotation.deleteAnnotations([annotationObject]);
|
openmct.annotation.deleteAnnotations([annotationObject]);
|
||||||
expect(annotationObject._deleted).toBeTrue();
|
expect(annotationObject._deleted).toBeTrue();
|
||||||
annotationObject = await openmct.annotation.addSingleAnnotationTag(null, mockDomainObject, {entryId: 'foo'}, openmct.annotation.ANNOTATION_TYPES.NOTEBOOK, 'aWonderfulTag');
|
annotationObject = await openmct.annotation.create(tagCreationArguments);
|
||||||
expect(annotationObject).toBeDefined();
|
expect(annotationObject).toBeDefined();
|
||||||
expect(annotationObject.type).toEqual('annotation');
|
expect(annotationObject.type).toEqual('annotation');
|
||||||
expect(annotationObject.tags).toContain('aWonderfulTag');
|
expect(annotationObject.tags).toContain('aWonderfulTag');
|
||||||
|
|||||||
@@ -37,7 +37,9 @@ define([
|
|||||||
'./types/TypeRegistry',
|
'./types/TypeRegistry',
|
||||||
'./user/UserAPI',
|
'./user/UserAPI',
|
||||||
'./annotation/AnnotationAPI'
|
'./annotation/AnnotationAPI'
|
||||||
], function (
|
],
|
||||||
|
|
||||||
|
function (
|
||||||
ActionsAPI,
|
ActionsAPI,
|
||||||
CompositionAPI,
|
CompositionAPI,
|
||||||
EditorAPI,
|
EditorAPI,
|
||||||
|
|||||||
@@ -20,34 +20,41 @@
|
|||||||
* at runtime from the About dialog for additional information.
|
* at runtime from the About dialog for additional information.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
define([
|
import DefaultCompositionProvider from './DefaultCompositionProvider';
|
||||||
'lodash',
|
import CompositionCollection from './CompositionCollection';
|
||||||
'EventEmitter',
|
|
||||||
'./DefaultCompositionProvider',
|
/**
|
||||||
'./CompositionCollection'
|
* @typedef {import('./CompositionProvider').default} CompositionProvider
|
||||||
], function (
|
*/
|
||||||
_,
|
|
||||||
EventEmitter,
|
/**
|
||||||
DefaultCompositionProvider,
|
* @typedef {import('../objects/ObjectAPI').DomainObject} DomainObject
|
||||||
CompositionCollection
|
*/
|
||||||
) {
|
|
||||||
|
/**
|
||||||
|
* @typedef {import('../../../openmct').OpenMCT} OpenMCT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An interface for interacting with the composition of domain objects.
|
||||||
|
* The composition of a domain object is the list of other domain objects
|
||||||
|
* it "contains" (for instance, that should be displayed beneath it
|
||||||
|
* in the tree.)
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
export default class CompositionAPI {
|
||||||
/**
|
/**
|
||||||
* An interface for interacting with the composition of domain objects.
|
* @param {OpenMCT} publicAPI
|
||||||
* The composition of a domain object is the list of other domain objects
|
|
||||||
* it "contains" (for instance, that should be displayed beneath it
|
|
||||||
* in the tree.)
|
|
||||||
*
|
|
||||||
* @interface CompositionAPI
|
|
||||||
* @returns {module:openmct.CompositionCollection}
|
|
||||||
* @memberof module:openmct
|
|
||||||
*/
|
*/
|
||||||
function CompositionAPI(publicAPI) {
|
constructor(publicAPI) {
|
||||||
|
/** @type {CompositionProvider[]} */
|
||||||
this.registry = [];
|
this.registry = [];
|
||||||
|
/** @type {CompositionPolicy[]} */
|
||||||
this.policies = [];
|
this.policies = [];
|
||||||
this.addProvider(new DefaultCompositionProvider(publicAPI, this));
|
this.addProvider(new DefaultCompositionProvider(publicAPI, this));
|
||||||
|
/** @type {OpenMCT} */
|
||||||
this.publicAPI = publicAPI;
|
this.publicAPI = publicAPI;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a composition provider.
|
* Add a composition provider.
|
||||||
*
|
*
|
||||||
@@ -55,21 +62,19 @@ define([
|
|||||||
* behavior for certain domain objects.
|
* behavior for certain domain objects.
|
||||||
*
|
*
|
||||||
* @method addProvider
|
* @method addProvider
|
||||||
* @param {module:openmct.CompositionProvider} provider the provider to add
|
* @param {CompositionProvider} provider the provider to add
|
||||||
* @memberof module:openmct.CompositionAPI#
|
|
||||||
*/
|
*/
|
||||||
CompositionAPI.prototype.addProvider = function (provider) {
|
addProvider(provider) {
|
||||||
this.registry.unshift(provider);
|
this.registry.unshift(provider);
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the composition (if any) of this domain object.
|
* Retrieve the composition (if any) of this domain object.
|
||||||
*
|
*
|
||||||
* @method get
|
* @method get
|
||||||
* @returns {module:openmct.CompositionCollection}
|
* @param {DomainObject} domainObject
|
||||||
* @memberof module:openmct.CompositionAPI#
|
* @returns {CompositionCollection}
|
||||||
*/
|
*/
|
||||||
CompositionAPI.prototype.get = function (domainObject) {
|
get(domainObject) {
|
||||||
const provider = this.registry.find(p => {
|
const provider = this.registry.find(p => {
|
||||||
return p.appliesTo(domainObject);
|
return p.appliesTo(domainObject);
|
||||||
});
|
});
|
||||||
@@ -79,8 +84,7 @@ define([
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new CompositionCollection(domainObject, provider, this.publicAPI);
|
return new CompositionCollection(domainObject, provider, this.publicAPI);
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A composition policy is a function which either allows or disallows
|
* A composition policy is a function which either allows or disallows
|
||||||
* placing one object in another's composition.
|
* placing one object in another's composition.
|
||||||
@@ -90,52 +94,51 @@ define([
|
|||||||
* generally be written to return true in the default case.
|
* generally be written to return true in the default case.
|
||||||
*
|
*
|
||||||
* @callback CompositionPolicy
|
* @callback CompositionPolicy
|
||||||
* @memberof module:openmct.CompositionAPI~
|
* @param {DomainObject} containingObject the object which
|
||||||
* @param {module:openmct.DomainObject} containingObject the object which
|
|
||||||
* would act as a container
|
* would act as a container
|
||||||
* @param {module:openmct.DomainObject} containedObject the object which
|
* @param {DomainObject} containedObject the object which
|
||||||
* would be contained
|
* would be contained
|
||||||
* @returns {boolean} false if this composition should be disallowed
|
* @returns {boolean} false if this composition should be disallowed
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a composition policy. Composition policies may disallow domain
|
* Add a composition policy. Composition policies may disallow domain
|
||||||
* objects from containing other domain objects.
|
* objects from containing other domain objects.
|
||||||
*
|
*
|
||||||
* @method addPolicy
|
* @method addPolicy
|
||||||
* @param {module:openmct.CompositionAPI~CompositionPolicy} policy
|
* @param {CompositionPolicy} policy
|
||||||
* the policy to add
|
* the policy to add
|
||||||
* @memberof module:openmct.CompositionAPI#
|
|
||||||
*/
|
*/
|
||||||
CompositionAPI.prototype.addPolicy = function (policy) {
|
addPolicy(policy) {
|
||||||
this.policies.push(policy);
|
this.policies.push(policy);
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether or not a domain object is allowed to contain another
|
* Check whether or not a domain object is allowed to contain another
|
||||||
* domain object.
|
* domain object.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @method checkPolicy
|
* @method checkPolicy
|
||||||
* @param {module:openmct.DomainObject} containingObject the object which
|
* @param {DomainObject} container the object which
|
||||||
* would act as a container
|
* would act as a container
|
||||||
* @param {module:openmct.DomainObject} containedObject the object which
|
* @param {DomainObject} containee the object which
|
||||||
* would be contained
|
* would be contained
|
||||||
* @returns {boolean} false if this composition should be disallowed
|
* @returns {boolean} false if this composition should be disallowed
|
||||||
|
* @param {CompositionPolicy} policy
|
||||||
* @param {module:openmct.CompositionAPI~CompositionPolicy} policy
|
|
||||||
* the policy to add
|
* the policy to add
|
||||||
* @memberof module:openmct.CompositionAPI#
|
|
||||||
*/
|
*/
|
||||||
CompositionAPI.prototype.checkPolicy = function (container, containee) {
|
checkPolicy(container, containee) {
|
||||||
return this.policies.every(function (policy) {
|
return this.policies.every(function (policy) {
|
||||||
return policy(container, containee);
|
return policy(container, containee);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
CompositionAPI.prototype.supportsComposition = function (domainObject) {
|
/**
|
||||||
|
* Check whether or not a domainObject supports composition
|
||||||
|
*
|
||||||
|
* @param {DomainObject} domainObject
|
||||||
|
* @returns {boolean} true if the domainObject supports composition
|
||||||
|
*/
|
||||||
|
supportsComposition(domainObject) {
|
||||||
return this.get(domainObject) !== undefined;
|
return this.get(domainObject) !== undefined;
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return CompositionAPI;
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -1,325 +1,319 @@
|
|||||||
define([
|
import CompositionAPI from './CompositionAPI';
|
||||||
'./CompositionAPI',
|
import CompositionCollection from './CompositionCollection';
|
||||||
'./CompositionCollection'
|
|
||||||
], function (
|
|
||||||
CompositionAPI,
|
|
||||||
CompositionCollection
|
|
||||||
) {
|
|
||||||
|
|
||||||
describe('The Composition API', function () {
|
describe('The Composition API', function () {
|
||||||
let publicAPI;
|
let publicAPI;
|
||||||
let compositionAPI;
|
let compositionAPI;
|
||||||
let topicService;
|
let topicService;
|
||||||
let mutationTopic;
|
let mutationTopic;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
|
||||||
|
mutationTopic = jasmine.createSpyObj('mutationTopic', [
|
||||||
|
'listen'
|
||||||
|
]);
|
||||||
|
topicService = jasmine.createSpy('topicService');
|
||||||
|
topicService.and.returnValue(mutationTopic);
|
||||||
|
publicAPI = {};
|
||||||
|
publicAPI.objects = jasmine.createSpyObj('ObjectAPI', [
|
||||||
|
'get',
|
||||||
|
'mutate',
|
||||||
|
'observe',
|
||||||
|
'areIdsEqual'
|
||||||
|
]);
|
||||||
|
|
||||||
|
publicAPI.objects.areIdsEqual.and.callFake(function (id1, id2) {
|
||||||
|
return id1.namespace === id2.namespace && id1.key === id2.key;
|
||||||
|
});
|
||||||
|
|
||||||
|
publicAPI.composition = jasmine.createSpyObj('CompositionAPI', [
|
||||||
|
'checkPolicy'
|
||||||
|
]);
|
||||||
|
publicAPI.composition.checkPolicy.and.returnValue(true);
|
||||||
|
|
||||||
|
publicAPI.objects.eventEmitter = jasmine.createSpyObj('eventemitter', [
|
||||||
|
'on'
|
||||||
|
]);
|
||||||
|
publicAPI.objects.get.and.callFake(function (identifier) {
|
||||||
|
return Promise.resolve({identifier: identifier});
|
||||||
|
});
|
||||||
|
publicAPI.$injector = jasmine.createSpyObj('$injector', [
|
||||||
|
'get'
|
||||||
|
]);
|
||||||
|
publicAPI.$injector.get.and.returnValue(topicService);
|
||||||
|
compositionAPI = new CompositionAPI(publicAPI);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns falsy if an object does not support composition', function () {
|
||||||
|
expect(compositionAPI.get({})).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('default composition', function () {
|
||||||
|
let domainObject;
|
||||||
|
let composition;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
|
domainObject = {
|
||||||
mutationTopic = jasmine.createSpyObj('mutationTopic', [
|
name: 'test folder',
|
||||||
'listen'
|
identifier: {
|
||||||
]);
|
namespace: 'test',
|
||||||
topicService = jasmine.createSpy('topicService');
|
key: '1'
|
||||||
topicService.and.returnValue(mutationTopic);
|
},
|
||||||
publicAPI = {};
|
composition: [
|
||||||
publicAPI.objects = jasmine.createSpyObj('ObjectAPI', [
|
{
|
||||||
'get',
|
namespace: 'test',
|
||||||
'mutate',
|
key: 'a'
|
||||||
'observe',
|
},
|
||||||
'areIdsEqual'
|
{
|
||||||
]);
|
namespace: 'test',
|
||||||
|
key: 'b'
|
||||||
publicAPI.objects.areIdsEqual.and.callFake(function (id1, id2) {
|
},
|
||||||
return id1.namespace === id2.namespace && id1.key === id2.key;
|
{
|
||||||
});
|
namespace: 'test',
|
||||||
|
key: 'c'
|
||||||
publicAPI.composition = jasmine.createSpyObj('CompositionAPI', [
|
}
|
||||||
'checkPolicy'
|
]
|
||||||
]);
|
};
|
||||||
publicAPI.composition.checkPolicy.and.returnValue(true);
|
composition = compositionAPI.get(domainObject);
|
||||||
|
|
||||||
publicAPI.objects.eventEmitter = jasmine.createSpyObj('eventemitter', [
|
|
||||||
'on'
|
|
||||||
]);
|
|
||||||
publicAPI.objects.get.and.callFake(function (identifier) {
|
|
||||||
return Promise.resolve({identifier: identifier});
|
|
||||||
});
|
|
||||||
publicAPI.$injector = jasmine.createSpyObj('$injector', [
|
|
||||||
'get'
|
|
||||||
]);
|
|
||||||
publicAPI.$injector.get.and.returnValue(topicService);
|
|
||||||
compositionAPI = new CompositionAPI(publicAPI);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns falsy if an object does not support composition', function () {
|
it('returns composition collection', function () {
|
||||||
expect(compositionAPI.get({})).toBeFalsy();
|
expect(composition).toBeDefined();
|
||||||
|
expect(composition).toEqual(jasmine.any(CompositionCollection));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('default composition', function () {
|
it('correctly reflects composability', function () {
|
||||||
let domainObject;
|
expect(compositionAPI.supportsComposition(domainObject)).toBe(true);
|
||||||
let composition;
|
delete domainObject.composition;
|
||||||
|
expect(compositionAPI.supportsComposition(domainObject)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
beforeEach(function () {
|
it('loads composition from domain object', function () {
|
||||||
domainObject = {
|
const listener = jasmine.createSpy('addListener');
|
||||||
name: 'test folder',
|
composition.on('add', listener);
|
||||||
|
|
||||||
|
return composition.load().then(function () {
|
||||||
|
expect(listener.calls.count()).toBe(3);
|
||||||
|
expect(listener).toHaveBeenCalledWith({
|
||||||
identifier: {
|
identifier: {
|
||||||
namespace: 'test',
|
namespace: 'test',
|
||||||
key: '1'
|
key: 'a'
|
||||||
},
|
}
|
||||||
composition: [
|
|
||||||
{
|
|
||||||
namespace: 'test',
|
|
||||||
key: 'a'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
namespace: 'test',
|
|
||||||
key: 'b'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
namespace: 'test',
|
|
||||||
key: 'c'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
composition = compositionAPI.get(domainObject);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns composition collection', function () {
|
|
||||||
expect(composition).toBeDefined();
|
|
||||||
expect(composition).toEqual(jasmine.any(CompositionCollection));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('correctly reflects composability', function () {
|
|
||||||
expect(compositionAPI.supportsComposition(domainObject)).toBe(true);
|
|
||||||
delete domainObject.composition;
|
|
||||||
expect(compositionAPI.supportsComposition(domainObject)).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('loads composition from domain object', function () {
|
|
||||||
const listener = jasmine.createSpy('addListener');
|
|
||||||
composition.on('add', listener);
|
|
||||||
|
|
||||||
return composition.load().then(function () {
|
|
||||||
expect(listener.calls.count()).toBe(3);
|
|
||||||
expect(listener).toHaveBeenCalledWith({
|
|
||||||
identifier: {
|
|
||||||
namespace: 'test',
|
|
||||||
key: 'a'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('supports reordering of composition', function () {
|
});
|
||||||
let listener;
|
describe('supports reordering of composition', function () {
|
||||||
beforeEach(function () {
|
let listener;
|
||||||
listener = jasmine.createSpy('reorderListener');
|
beforeEach(function () {
|
||||||
composition.on('reorder', listener);
|
listener = jasmine.createSpy('reorderListener');
|
||||||
|
composition.on('reorder', listener);
|
||||||
|
|
||||||
return composition.load();
|
return composition.load();
|
||||||
});
|
});
|
||||||
it('', function () {
|
it('', function () {
|
||||||
composition.reorder(1, 0);
|
composition.reorder(1, 0);
|
||||||
let newComposition =
|
let newComposition =
|
||||||
publicAPI.objects.mutate.calls.mostRecent().args[2];
|
publicAPI.objects.mutate.calls.mostRecent().args[2];
|
||||||
let reorderPlan = listener.calls.mostRecent().args[0][0];
|
let reorderPlan = listener.calls.mostRecent().args[0][0];
|
||||||
|
|
||||||
expect(reorderPlan.oldIndex).toBe(1);
|
expect(reorderPlan.oldIndex).toBe(1);
|
||||||
expect(reorderPlan.newIndex).toBe(0);
|
expect(reorderPlan.newIndex).toBe(0);
|
||||||
expect(newComposition[0].key).toEqual('b');
|
expect(newComposition[0].key).toEqual('b');
|
||||||
expect(newComposition[1].key).toEqual('a');
|
expect(newComposition[1].key).toEqual('a');
|
||||||
expect(newComposition[2].key).toEqual('c');
|
expect(newComposition[2].key).toEqual('c');
|
||||||
});
|
});
|
||||||
it('', function () {
|
it('', function () {
|
||||||
composition.reorder(0, 2);
|
composition.reorder(0, 2);
|
||||||
let newComposition =
|
let newComposition =
|
||||||
publicAPI.objects.mutate.calls.mostRecent().args[2];
|
publicAPI.objects.mutate.calls.mostRecent().args[2];
|
||||||
let reorderPlan = listener.calls.mostRecent().args[0][0];
|
let reorderPlan = listener.calls.mostRecent().args[0][0];
|
||||||
|
|
||||||
expect(reorderPlan.oldIndex).toBe(0);
|
expect(reorderPlan.oldIndex).toBe(0);
|
||||||
expect(reorderPlan.newIndex).toBe(2);
|
expect(reorderPlan.newIndex).toBe(2);
|
||||||
expect(newComposition[0].key).toEqual('b');
|
expect(newComposition[0].key).toEqual('b');
|
||||||
expect(newComposition[1].key).toEqual('c');
|
expect(newComposition[1].key).toEqual('c');
|
||||||
expect(newComposition[2].key).toEqual('a');
|
expect(newComposition[2].key).toEqual('a');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('supports adding an object to composition', function () {
|
||||||
|
let addListener = jasmine.createSpy('addListener');
|
||||||
|
let mockChildObject = {
|
||||||
|
identifier: {
|
||||||
|
key: 'mock-key',
|
||||||
|
namespace: ''
|
||||||
|
}
|
||||||
|
};
|
||||||
|
composition.on('add', addListener);
|
||||||
|
composition.add(mockChildObject);
|
||||||
|
|
||||||
|
expect(domainObject.composition.length).toBe(4);
|
||||||
|
expect(domainObject.composition[3]).toEqual(mockChildObject.identifier);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('static custom composition', function () {
|
||||||
|
let customProvider;
|
||||||
|
let domainObject;
|
||||||
|
let composition;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
// A simple custom provider, returns the same composition for
|
||||||
|
// all objects of a given type.
|
||||||
|
customProvider = {
|
||||||
|
appliesTo: function (object) {
|
||||||
|
return object.type === 'custom-object-type';
|
||||||
|
},
|
||||||
|
load: function (object) {
|
||||||
|
return Promise.resolve([
|
||||||
|
{
|
||||||
|
namespace: 'custom',
|
||||||
|
key: 'thing'
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
},
|
||||||
|
add: jasmine.createSpy('add'),
|
||||||
|
remove: jasmine.createSpy('remove')
|
||||||
|
};
|
||||||
|
domainObject = {
|
||||||
|
identifier: {
|
||||||
|
namespace: 'test',
|
||||||
|
key: '1'
|
||||||
|
},
|
||||||
|
type: 'custom-object-type'
|
||||||
|
};
|
||||||
|
compositionAPI.addProvider(customProvider);
|
||||||
|
composition = compositionAPI.get(domainObject);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('supports listening and loading', function () {
|
||||||
|
const addListener = jasmine.createSpy('addListener');
|
||||||
|
composition.on('add', addListener);
|
||||||
|
|
||||||
|
return composition.load().then(function (children) {
|
||||||
|
let listenObject;
|
||||||
|
const loadedObject = children[0];
|
||||||
|
|
||||||
|
expect(addListener).toHaveBeenCalled();
|
||||||
|
|
||||||
|
listenObject = addListener.calls.mostRecent().args[0];
|
||||||
|
expect(listenObject).toEqual(loadedObject);
|
||||||
|
expect(loadedObject).toEqual({
|
||||||
|
identifier: {
|
||||||
|
namespace: 'custom',
|
||||||
|
key: 'thing'
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('supports adding an object to composition', function () {
|
});
|
||||||
let addListener = jasmine.createSpy('addListener');
|
describe('Calling add or remove', function () {
|
||||||
let mockChildObject = {
|
let mockChildObject;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
mockChildObject = {
|
||||||
identifier: {
|
identifier: {
|
||||||
key: 'mock-key',
|
key: 'mock-key',
|
||||||
namespace: ''
|
namespace: ''
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
composition.on('add', addListener);
|
|
||||||
composition.add(mockChildObject);
|
composition.add(mockChildObject);
|
||||||
|
|
||||||
expect(domainObject.composition.length).toBe(4);
|
|
||||||
expect(domainObject.composition[3]).toEqual(mockChildObject.identifier);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('static custom composition', function () {
|
|
||||||
let customProvider;
|
|
||||||
let domainObject;
|
|
||||||
let composition;
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
// A simple custom provider, returns the same composition for
|
|
||||||
// all objects of a given type.
|
|
||||||
customProvider = {
|
|
||||||
appliesTo: function (object) {
|
|
||||||
return object.type === 'custom-object-type';
|
|
||||||
},
|
|
||||||
load: function (object) {
|
|
||||||
return Promise.resolve([
|
|
||||||
{
|
|
||||||
namespace: 'custom',
|
|
||||||
key: 'thing'
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
},
|
|
||||||
add: jasmine.createSpy('add'),
|
|
||||||
remove: jasmine.createSpy('remove')
|
|
||||||
};
|
|
||||||
domainObject = {
|
|
||||||
identifier: {
|
|
||||||
namespace: 'test',
|
|
||||||
key: '1'
|
|
||||||
},
|
|
||||||
type: 'custom-object-type'
|
|
||||||
};
|
|
||||||
compositionAPI.addProvider(customProvider);
|
|
||||||
composition = compositionAPI.get(domainObject);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('supports listening and loading', function () {
|
it('calls add on the provider', function () {
|
||||||
const addListener = jasmine.createSpy('addListener');
|
expect(customProvider.add).toHaveBeenCalledWith(domainObject, mockChildObject.identifier);
|
||||||
composition.on('add', addListener);
|
|
||||||
|
|
||||||
return composition.load().then(function (children) {
|
|
||||||
let listenObject;
|
|
||||||
const loadedObject = children[0];
|
|
||||||
|
|
||||||
expect(addListener).toHaveBeenCalled();
|
|
||||||
|
|
||||||
listenObject = addListener.calls.mostRecent().args[0];
|
|
||||||
expect(listenObject).toEqual(loadedObject);
|
|
||||||
expect(loadedObject).toEqual({
|
|
||||||
identifier: {
|
|
||||||
namespace: 'custom',
|
|
||||||
key: 'thing'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
describe('Calling add or remove', function () {
|
|
||||||
let mockChildObject;
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
mockChildObject = {
|
|
||||||
identifier: {
|
|
||||||
key: 'mock-key',
|
|
||||||
namespace: ''
|
|
||||||
}
|
|
||||||
};
|
|
||||||
composition.add(mockChildObject);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('calls add on the provider', function () {
|
|
||||||
expect(customProvider.add).toHaveBeenCalledWith(domainObject, mockChildObject.identifier);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('calls remove on the provider', function () {
|
|
||||||
composition.remove(mockChildObject);
|
|
||||||
expect(customProvider.remove).toHaveBeenCalledWith(domainObject, mockChildObject.identifier);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('dynamic custom composition', function () {
|
|
||||||
let customProvider;
|
|
||||||
let domainObject;
|
|
||||||
let composition;
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
// A dynamic provider, loads an empty composition and exposes
|
|
||||||
// listener functions.
|
|
||||||
customProvider = jasmine.createSpyObj('dynamicProvider', [
|
|
||||||
'appliesTo',
|
|
||||||
'load',
|
|
||||||
'on',
|
|
||||||
'off'
|
|
||||||
]);
|
|
||||||
|
|
||||||
customProvider.appliesTo.and.returnValue('true');
|
|
||||||
customProvider.load.and.returnValue(Promise.resolve([]));
|
|
||||||
|
|
||||||
domainObject = {
|
|
||||||
identifier: {
|
|
||||||
namespace: 'test',
|
|
||||||
key: '1'
|
|
||||||
},
|
|
||||||
type: 'custom-object-type'
|
|
||||||
};
|
|
||||||
compositionAPI.addProvider(customProvider);
|
|
||||||
composition = compositionAPI.get(domainObject);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('supports listening and loading', function () {
|
it('calls remove on the provider', function () {
|
||||||
const addListener = jasmine.createSpy('addListener');
|
composition.remove(mockChildObject);
|
||||||
const removeListener = jasmine.createSpy('removeListener');
|
expect(customProvider.remove).toHaveBeenCalledWith(domainObject, mockChildObject.identifier);
|
||||||
const addPromise = new Promise(function (resolve) {
|
|
||||||
addListener.and.callFake(resolve);
|
|
||||||
});
|
|
||||||
const removePromise = new Promise(function (resolve) {
|
|
||||||
removeListener.and.callFake(resolve);
|
|
||||||
});
|
|
||||||
|
|
||||||
composition.on('add', addListener);
|
|
||||||
composition.on('remove', removeListener);
|
|
||||||
|
|
||||||
expect(customProvider.on).toHaveBeenCalledWith(
|
|
||||||
domainObject,
|
|
||||||
'add',
|
|
||||||
jasmine.any(Function),
|
|
||||||
jasmine.any(CompositionCollection)
|
|
||||||
);
|
|
||||||
expect(customProvider.on).toHaveBeenCalledWith(
|
|
||||||
domainObject,
|
|
||||||
'remove',
|
|
||||||
jasmine.any(Function),
|
|
||||||
jasmine.any(CompositionCollection)
|
|
||||||
);
|
|
||||||
const add = customProvider.on.calls.all()[0].args[2];
|
|
||||||
const remove = customProvider.on.calls.all()[1].args[2];
|
|
||||||
|
|
||||||
return composition.load()
|
|
||||||
.then(function () {
|
|
||||||
expect(addListener).not.toHaveBeenCalled();
|
|
||||||
expect(removeListener).not.toHaveBeenCalled();
|
|
||||||
add({
|
|
||||||
namespace: 'custom',
|
|
||||||
key: 'thing'
|
|
||||||
});
|
|
||||||
|
|
||||||
return addPromise;
|
|
||||||
}).then(function () {
|
|
||||||
expect(addListener).toHaveBeenCalledWith({
|
|
||||||
identifier: {
|
|
||||||
namespace: 'custom',
|
|
||||||
key: 'thing'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
remove(addListener.calls.mostRecent().args[0]);
|
|
||||||
|
|
||||||
return removePromise;
|
|
||||||
}).then(function () {
|
|
||||||
expect(removeListener).toHaveBeenCalledWith({
|
|
||||||
identifier: {
|
|
||||||
namespace: 'custom',
|
|
||||||
key: 'thing'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('dynamic custom composition', function () {
|
||||||
|
let customProvider;
|
||||||
|
let domainObject;
|
||||||
|
let composition;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
// A dynamic provider, loads an empty composition and exposes
|
||||||
|
// listener functions.
|
||||||
|
customProvider = jasmine.createSpyObj('dynamicProvider', [
|
||||||
|
'appliesTo',
|
||||||
|
'load',
|
||||||
|
'on',
|
||||||
|
'off'
|
||||||
|
]);
|
||||||
|
|
||||||
|
customProvider.appliesTo.and.returnValue('true');
|
||||||
|
customProvider.load.and.returnValue(Promise.resolve([]));
|
||||||
|
|
||||||
|
domainObject = {
|
||||||
|
identifier: {
|
||||||
|
namespace: 'test',
|
||||||
|
key: '1'
|
||||||
|
},
|
||||||
|
type: 'custom-object-type'
|
||||||
|
};
|
||||||
|
compositionAPI.addProvider(customProvider);
|
||||||
|
composition = compositionAPI.get(domainObject);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('supports listening and loading', function () {
|
||||||
|
const addListener = jasmine.createSpy('addListener');
|
||||||
|
const removeListener = jasmine.createSpy('removeListener');
|
||||||
|
const addPromise = new Promise(function (resolve) {
|
||||||
|
addListener.and.callFake(resolve);
|
||||||
|
});
|
||||||
|
const removePromise = new Promise(function (resolve) {
|
||||||
|
removeListener.and.callFake(resolve);
|
||||||
|
});
|
||||||
|
|
||||||
|
composition.on('add', addListener);
|
||||||
|
composition.on('remove', removeListener);
|
||||||
|
|
||||||
|
expect(customProvider.on).toHaveBeenCalledWith(
|
||||||
|
domainObject,
|
||||||
|
'add',
|
||||||
|
jasmine.any(Function),
|
||||||
|
jasmine.any(CompositionCollection)
|
||||||
|
);
|
||||||
|
expect(customProvider.on).toHaveBeenCalledWith(
|
||||||
|
domainObject,
|
||||||
|
'remove',
|
||||||
|
jasmine.any(Function),
|
||||||
|
jasmine.any(CompositionCollection)
|
||||||
|
);
|
||||||
|
const add = customProvider.on.calls.all()[0].args[2];
|
||||||
|
const remove = customProvider.on.calls.all()[1].args[2];
|
||||||
|
|
||||||
|
return composition.load()
|
||||||
|
.then(function () {
|
||||||
|
expect(addListener).not.toHaveBeenCalled();
|
||||||
|
expect(removeListener).not.toHaveBeenCalled();
|
||||||
|
add({
|
||||||
|
namespace: 'custom',
|
||||||
|
key: 'thing'
|
||||||
|
});
|
||||||
|
|
||||||
|
return addPromise;
|
||||||
|
}).then(function () {
|
||||||
|
expect(addListener).toHaveBeenCalledWith({
|
||||||
|
identifier: {
|
||||||
|
namespace: 'custom',
|
||||||
|
key: 'thing'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
remove(addListener.calls.mostRecent().args[0]);
|
||||||
|
|
||||||
|
return removePromise;
|
||||||
|
}).then(function () {
|
||||||
|
expect(removeListener).toHaveBeenCalledWith({
|
||||||
|
identifier: {
|
||||||
|
namespace: 'custom',
|
||||||
|
key: 'thing'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -20,75 +20,118 @@
|
|||||||
* at runtime from the About dialog for additional information.
|
* at runtime from the About dialog for additional information.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
define([
|
import EventEmitter from 'EventEmitter';
|
||||||
'lodash'
|
/**
|
||||||
], function (
|
* @typedef {import('../objects/ObjectAPI').DomainObject} DomainObject
|
||||||
_
|
*/
|
||||||
) {
|
|
||||||
|
/**
|
||||||
|
* @typedef {import('./CompositionAPI').default} CompositionAPI
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {import('../../../openmct').OpenMCT} OpenMCT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} ListenerMap
|
||||||
|
* @property {Array.<any>} add
|
||||||
|
* @property {Array.<any>} remove
|
||||||
|
* @property {Array.<any>} load
|
||||||
|
* @property {Array.<any>} reorder
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A CompositionCollection represents the list of domain objects contained
|
||||||
|
* by another domain object. It provides methods for loading this
|
||||||
|
* list asynchronously, modifying this list, and listening for changes to
|
||||||
|
* this list.
|
||||||
|
*
|
||||||
|
* Usage:
|
||||||
|
* ```javascript
|
||||||
|
* var myViewComposition = MCT.composition.get(myViewObject);
|
||||||
|
* myViewComposition.on('add', addObjectToView);
|
||||||
|
* myViewComposition.on('remove', removeObjectFromView);
|
||||||
|
* myViewComposition.load(); // will trigger `add` for all loaded objects.
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export default class CompositionCollection {
|
||||||
|
domainObject;
|
||||||
|
#provider;
|
||||||
|
#publicAPI;
|
||||||
|
#listeners;
|
||||||
|
#mutables;
|
||||||
|
#onGlobalAdd;
|
||||||
|
#onGlobalRemove;
|
||||||
|
static #globalEvents = new EventEmitter();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A CompositionCollection represents the list of domain objects contained
|
* @constructor
|
||||||
* by another domain object. It provides methods for loading this
|
* @param {DomainObject} domainObject the domain object
|
||||||
* list asynchronously, modifying this list, and listening for changes to
|
|
||||||
* this list.
|
|
||||||
*
|
|
||||||
* Usage:
|
|
||||||
* ```javascript
|
|
||||||
* var myViewComposition = MCT.composition.get(myViewObject);
|
|
||||||
* myViewComposition.on('add', addObjectToView);
|
|
||||||
* myViewComposition.on('remove', removeObjectFromView);
|
|
||||||
* myViewComposition.load(); // will trigger `add` for all loaded objects.
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* @interface CompositionCollection
|
|
||||||
* @param {module:openmct.DomainObject} domainObject the domain object
|
|
||||||
* whose composition will be contained
|
* whose composition will be contained
|
||||||
* @param {module:openmct.CompositionProvider} provider the provider
|
* @param {import('./CompositionProvider').default} provider the provider
|
||||||
* to use to retrieve other domain objects
|
* to use to retrieve other domain objects
|
||||||
* @param {module:openmct.CompositionAPI} api the composition API, for
|
* @param {OpenMCT} publicAPI the composition API, for
|
||||||
* policy checks
|
* policy checks
|
||||||
* @memberof module:openmct
|
|
||||||
*/
|
*/
|
||||||
function CompositionCollection(domainObject, provider, publicAPI) {
|
constructor(domainObject, provider, publicAPI) {
|
||||||
this.domainObject = domainObject;
|
this.domainObject = domainObject;
|
||||||
this.provider = provider;
|
/** @type {import('./CompositionProvider').default} */
|
||||||
this.publicAPI = publicAPI;
|
this.#provider = provider;
|
||||||
this.listeners = {
|
/** @type {OpenMCT} */
|
||||||
|
this.#publicAPI = publicAPI;
|
||||||
|
/** @type {ListenerMap} */
|
||||||
|
this.#listeners = {
|
||||||
add: [],
|
add: [],
|
||||||
remove: [],
|
remove: [],
|
||||||
load: [],
|
load: [],
|
||||||
reorder: []
|
reorder: []
|
||||||
};
|
};
|
||||||
this.onProviderAdd = this.onProviderAdd.bind(this);
|
this.onProviderAdd = this.#onProviderAdd.bind(this);
|
||||||
this.onProviderRemove = this.onProviderRemove.bind(this);
|
this.onProviderRemove = this.#onProviderRemove.bind(this);
|
||||||
this.mutables = {};
|
this.#mutables = {};
|
||||||
|
|
||||||
if (this.domainObject.isMutable) {
|
if (this.domainObject.isMutable) {
|
||||||
this.returnMutables = true;
|
this.returnMutables = true;
|
||||||
let unobserve = this.domainObject.$on('$_destroy', () => {
|
let unobserve = this.domainObject.$on('$_destroy', () => {
|
||||||
Object.values(this.mutables).forEach(mutable => {
|
Object.values(this.#mutables).forEach(mutable => {
|
||||||
this.publicAPI.objects.destroyMutable(mutable);
|
this.#publicAPI.objects.destroyMutable(mutable);
|
||||||
});
|
});
|
||||||
unobserve();
|
unobserve();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const keyString = publicAPI.objects.makeKeyString(domainObject.identifier);
|
||||||
|
this.#onGlobalAdd = this._onGlobalAdd.bind(this);
|
||||||
|
this.#onGlobalRemove = this._onGlobalRemove.bind(this);
|
||||||
|
|
||||||
|
CompositionCollection.#globalEvents.on(`add:${keyString}`, this.#onGlobalAdd);
|
||||||
|
CompositionCollection.#globalEvents.on(`remove:${keyString}`, this.#onGlobalRemove);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onGlobalAdd(object) {
|
||||||
|
this.#emit('add', object);
|
||||||
|
}
|
||||||
|
|
||||||
|
_onGlobalRemove(identifier) {
|
||||||
|
this.#emit('remove', identifier);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Listen for changes to this composition. Supports 'add', 'remove', and
|
* Listen for changes to this composition. Supports 'add', 'remove', and
|
||||||
* 'load' events.
|
* 'load' events.
|
||||||
*
|
*
|
||||||
* @param event event to listen for, either 'add', 'remove' or 'load'.
|
* @param {string} event event to listen for, either 'add', 'remove' or 'load'.
|
||||||
* @param callback to trigger when event occurs.
|
* @param {(...args: any[]) => void} callback to trigger when event occurs.
|
||||||
* @param [context] context to use when invoking callback, optional.
|
* @param {any} [context] to use when invoking callback, optional.
|
||||||
*/
|
*/
|
||||||
CompositionCollection.prototype.on = function (event, callback, context) {
|
on(event, callback, context) {
|
||||||
if (!this.listeners[event]) {
|
if (!this.#listeners[event]) {
|
||||||
throw new Error('Event not supported by composition: ' + event);
|
throw new Error('Event not supported by composition: ' + event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.provider.on && this.provider.off) {
|
if (this.#provider.on && this.#provider.off) {
|
||||||
if (event === 'add') {
|
if (event === 'add') {
|
||||||
this.provider.on(
|
this.#provider.on(
|
||||||
this.domainObject,
|
this.domainObject,
|
||||||
'add',
|
'add',
|
||||||
this.onProviderAdd,
|
this.onProviderAdd,
|
||||||
@@ -97,7 +140,7 @@ define([
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (event === 'remove') {
|
if (event === 'remove') {
|
||||||
this.provider.on(
|
this.#provider.on(
|
||||||
this.domainObject,
|
this.domainObject,
|
||||||
'remove',
|
'remove',
|
||||||
this.onProviderRemove,
|
this.onProviderRemove,
|
||||||
@@ -106,36 +149,34 @@ define([
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (event === 'reorder') {
|
if (event === 'reorder') {
|
||||||
this.provider.on(
|
this.#provider.on(
|
||||||
this.domainObject,
|
this.domainObject,
|
||||||
'reorder',
|
'reorder',
|
||||||
this.onProviderReorder,
|
this.#onProviderReorder,
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.listeners[event].push({
|
this.#listeners[event].push({
|
||||||
callback: callback,
|
callback: callback,
|
||||||
context: context
|
context: context
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a listener. Must be called with same exact parameters as
|
* Remove a listener. Must be called with same exact parameters as
|
||||||
* `off`.
|
* `off`.
|
||||||
*
|
*
|
||||||
* @param event
|
* @param {string} event
|
||||||
* @param callback
|
* @param {(...args: any[]) => void} callback
|
||||||
* @param [context]
|
* @param {any} [context]
|
||||||
*/
|
*/
|
||||||
|
off(event, callback, context) {
|
||||||
CompositionCollection.prototype.off = function (event, callback, context) {
|
if (!this.#listeners[event]) {
|
||||||
if (!this.listeners[event]) {
|
|
||||||
throw new Error('Event not supported by composition: ' + event);
|
throw new Error('Event not supported by composition: ' + event);
|
||||||
}
|
}
|
||||||
|
|
||||||
const index = this.listeners[event].findIndex(l => {
|
const index = this.#listeners[event].findIndex(l => {
|
||||||
return l.callback === callback && l.context === context;
|
return l.callback === callback && l.context === context;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -143,125 +184,117 @@ define([
|
|||||||
throw new Error('Tried to remove a listener that does not exist');
|
throw new Error('Tried to remove a listener that does not exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.listeners[event].splice(index, 1);
|
this.#listeners[event].splice(index, 1);
|
||||||
if (this.listeners[event].length === 0) {
|
if (this.#listeners[event].length === 0) {
|
||||||
this._destroy();
|
this._destroy();
|
||||||
|
|
||||||
// Remove provider listener if this is the last callback to
|
// Remove provider listener if this is the last callback to
|
||||||
// be removed.
|
// be removed.
|
||||||
if (this.provider.off && this.provider.on) {
|
if (this.#provider.off && this.#provider.on) {
|
||||||
if (event === 'add') {
|
if (event === 'add') {
|
||||||
this.provider.off(
|
this.#provider.off(
|
||||||
this.domainObject,
|
this.domainObject,
|
||||||
'add',
|
'add',
|
||||||
this.onProviderAdd,
|
this.onProviderAdd,
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
} else if (event === 'remove') {
|
} else if (event === 'remove') {
|
||||||
this.provider.off(
|
this.#provider.off(
|
||||||
this.domainObject,
|
this.domainObject,
|
||||||
'remove',
|
'remove',
|
||||||
this.onProviderRemove,
|
this.onProviderRemove,
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
} else if (event === 'reorder') {
|
} else if (event === 'reorder') {
|
||||||
this.provider.off(
|
this.#provider.off(
|
||||||
this.domainObject,
|
this.domainObject,
|
||||||
'reorder',
|
'reorder',
|
||||||
this.onProviderReorder,
|
this.#onProviderReorder,
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a domain object to this composition.
|
* Add a domain object to this composition.
|
||||||
*
|
*
|
||||||
* A call to [load]{@link module:openmct.CompositionCollection#load}
|
* A call to [load]{@link module:openmct.CompositionCollection#load}
|
||||||
* must have resolved before using this method.
|
* must have resolved before using this method.
|
||||||
*
|
*
|
||||||
* @param {module:openmct.DomainObject} child the domain object to add
|
* **TODO:** Remove `skipMutate` parameter.
|
||||||
* @param {boolean} skipMutate true if the underlying provider should
|
*
|
||||||
* not be updated
|
* @param {DomainObject} child the domain object to add
|
||||||
* @memberof module:openmct.CompositionCollection#
|
* @param {boolean} skipMutate
|
||||||
* @name add
|
* **Intended for internal use ONLY.**
|
||||||
|
* true if the underlying provider should not be updated.
|
||||||
*/
|
*/
|
||||||
CompositionCollection.prototype.add = function (child, skipMutate) {
|
add(child) {
|
||||||
if (!skipMutate) {
|
if (!this.#publicAPI.composition.checkPolicy(this.domainObject, child)) {
|
||||||
if (!this.publicAPI.composition.checkPolicy(this.domainObject, child)) {
|
throw `Object of type ${child.type} cannot be added to object of type ${this.domainObject.type}`;
|
||||||
throw `Object of type ${child.type} cannot be added to object of type ${this.domainObject.type}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.provider.add(this.domainObject, child.identifier);
|
|
||||||
} else {
|
|
||||||
if (this.returnMutables && this.publicAPI.objects.supportsMutation(child.identifier)) {
|
|
||||||
let keyString = this.publicAPI.objects.makeKeyString(child.identifier);
|
|
||||||
|
|
||||||
child = this.publicAPI.objects.toMutable(child);
|
|
||||||
this.mutables[keyString] = child;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.emit('add', child);
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
|
this.#provider.add(this.domainObject, child.identifier);
|
||||||
|
if (this.returnMutables && this.#publicAPI.objects.supportsMutation(child.identifier)) {
|
||||||
|
let keyString = this.#publicAPI.objects.makeKeyString(child.identifier);
|
||||||
|
|
||||||
|
child = this.#publicAPI.objects.toMutable(child);
|
||||||
|
this.#mutables[keyString] = child;
|
||||||
|
}
|
||||||
|
|
||||||
|
// const keyString = this.#publicAPI.objects.makeKeyString(this.domainObject.identifier);
|
||||||
|
// CompositionCollection.#globalEvents.emit(`add:${keyString}`, child);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Load the domain objects in this composition.
|
* Load the domain objects in this composition.
|
||||||
*
|
*
|
||||||
* @returns {Promise.<Array.<module:openmct.DomainObject>>} a promise for
|
* @param {AbortSignal} abortSignal
|
||||||
|
* @returns {Promise.<Array.<DomainObject>>} a promise for
|
||||||
* the domain objects in this composition
|
* the domain objects in this composition
|
||||||
* @memberof {module:openmct.CompositionCollection#}
|
* @memberof {module:openmct.CompositionCollection#}
|
||||||
* @name load
|
* @name load
|
||||||
*/
|
*/
|
||||||
CompositionCollection.prototype.load = function (abortSignal) {
|
async load(abortSignal) {
|
||||||
this.cleanUpMutables();
|
this.#cleanUpMutables();
|
||||||
|
const children = await this.#provider.load(this.domainObject);
|
||||||
|
const childObjects = await Promise.all(children.map((c) => this.#publicAPI.objects.get(c, abortSignal)));
|
||||||
|
childObjects.forEach(c => {
|
||||||
|
this.add(c);
|
||||||
|
|
||||||
return this.provider.load(this.domainObject)
|
const keyString = this.#publicAPI.objects.makeKeyString(this.domainObject.identifier);
|
||||||
.then(function (children) {
|
CompositionCollection.#globalEvents.emit(`add:${keyString}`, c);
|
||||||
return Promise.all(children.map((c) => this.publicAPI.objects.get(c, abortSignal)));
|
});
|
||||||
}.bind(this))
|
this.#emit('load');
|
||||||
.then(function (childObjects) {
|
|
||||||
childObjects.forEach(c => this.add(c, true));
|
|
||||||
|
|
||||||
return childObjects;
|
|
||||||
}.bind(this))
|
|
||||||
.then(function (children) {
|
|
||||||
this.emit('load');
|
|
||||||
|
|
||||||
return children;
|
|
||||||
}.bind(this));
|
|
||||||
};
|
|
||||||
|
|
||||||
|
return childObjects;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Remove a domain object from this composition.
|
* Remove a domain object from this composition.
|
||||||
*
|
*
|
||||||
* A call to [load]{@link module:openmct.CompositionCollection#load}
|
* A call to [load]{@link module:openmct.CompositionCollection#load}
|
||||||
* must have resolved before using this method.
|
* must have resolved before using this method.
|
||||||
*
|
*
|
||||||
* @param {module:openmct.DomainObject} child the domain object to remove
|
* **TODO:** Remove `skipMutate` parameter.
|
||||||
* @param {boolean} skipMutate true if the underlying provider should
|
*
|
||||||
* not be updated
|
* @param {DomainObject} child the domain object to remove
|
||||||
* @memberof module:openmct.CompositionCollection#
|
* @param {boolean} skipMutate
|
||||||
|
* **Intended for internal use ONLY.**
|
||||||
|
* true if the underlying provider should not be updated.
|
||||||
* @name remove
|
* @name remove
|
||||||
*/
|
*/
|
||||||
CompositionCollection.prototype.remove = function (child, skipMutate) {
|
remove(child) {
|
||||||
if (!skipMutate) {
|
this.#provider.remove(this.domainObject, child.identifier);
|
||||||
this.provider.remove(this.domainObject, child.identifier);
|
if (this.returnMutables) {
|
||||||
} else {
|
let keyString = this.#publicAPI.objects.makeKeyString(child);
|
||||||
if (this.returnMutables) {
|
if (this.#mutables[keyString] !== undefined && this.#mutables[keyString].isMutable) {
|
||||||
let keyString = this.publicAPI.objects.makeKeyString(child);
|
this.#publicAPI.objects.destroyMutable(this.#mutables[keyString]);
|
||||||
if (this.mutables[keyString] !== undefined && this.mutables[keyString].isMutable) {
|
delete this.#mutables[keyString];
|
||||||
this.publicAPI.objects.destroyMutable(this.mutables[keyString]);
|
|
||||||
delete this.mutables[keyString];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.emit('remove', child);
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
|
// const keyString = this.#publicAPI.objects.makeKeyString(this.domainObject.identifier);
|
||||||
|
// CompositionCollection.#globalEvents.emit(`remove:${keyString}`, child.identifier);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Reorder the domain objects in this composition.
|
* Reorder the domain objects in this composition.
|
||||||
*
|
*
|
||||||
@@ -270,67 +303,79 @@ define([
|
|||||||
*
|
*
|
||||||
* @param {number} oldIndex
|
* @param {number} oldIndex
|
||||||
* @param {number} newIndex
|
* @param {number} newIndex
|
||||||
* @memberof module:openmct.CompositionCollection#
|
|
||||||
* @name remove
|
* @name remove
|
||||||
*/
|
*/
|
||||||
CompositionCollection.prototype.reorder = function (oldIndex, newIndex, skipMutate) {
|
reorder(oldIndex, newIndex, _skipMutate) {
|
||||||
this.provider.reorder(this.domainObject, oldIndex, newIndex);
|
this.#provider.reorder(this.domainObject, oldIndex, newIndex);
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle reorder from provider.
|
* Destroy mutationListener
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
CompositionCollection.prototype.onProviderReorder = function (reorderMap) {
|
_destroy() {
|
||||||
this.emit('reorder', reorderMap);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle adds from provider.
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
CompositionCollection.prototype.onProviderAdd = function (childId) {
|
|
||||||
return this.publicAPI.objects.get(childId).then(function (child) {
|
|
||||||
this.add(child, true);
|
|
||||||
|
|
||||||
return child;
|
|
||||||
}.bind(this));
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle removal from provider.
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
CompositionCollection.prototype.onProviderRemove = function (child) {
|
|
||||||
this.remove(child, true);
|
|
||||||
};
|
|
||||||
|
|
||||||
CompositionCollection.prototype._destroy = function () {
|
|
||||||
if (this.mutationListener) {
|
if (this.mutationListener) {
|
||||||
this.mutationListener();
|
this.mutationListener();
|
||||||
delete this.mutationListener;
|
delete this.mutationListener;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
const keyString = this.#publicAPI.objects.makeKeyString(this.domainObject.identifier);
|
||||||
|
CompositionCollection.#globalEvents.off(`add:${keyString}`, this.#onGlobalAdd);
|
||||||
|
CompositionCollection.#globalEvents.off(`remove:${keyString}`, this.#onGlobalRemove);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Handle reorder from provider.
|
||||||
|
* @private
|
||||||
|
* @param {object} reorderMap
|
||||||
|
*/
|
||||||
|
#onProviderReorder(reorderMap) {
|
||||||
|
this.#emit('reorder', reorderMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle adds from provider.
|
||||||
|
* @private
|
||||||
|
* @param {import('../objects/ObjectAPI').Identifier} childId
|
||||||
|
* @returns {DomainObject}
|
||||||
|
*/
|
||||||
|
#onProviderAdd(childId) {
|
||||||
|
return this.#publicAPI.objects.get(childId).then(function (child) {
|
||||||
|
this.add(child, true);
|
||||||
|
|
||||||
|
return child;
|
||||||
|
}.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle removal from provider.
|
||||||
|
* @param {DomainObject} child
|
||||||
|
*/
|
||||||
|
#onProviderRemove(child) {
|
||||||
|
this.remove(child, true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emit events.
|
* Emit events.
|
||||||
|
*
|
||||||
* @private
|
* @private
|
||||||
|
* @param {string} event
|
||||||
|
* @param {...args.<any>} payload
|
||||||
*/
|
*/
|
||||||
CompositionCollection.prototype.emit = function (event, ...payload) {
|
#emit(event, ...payload) {
|
||||||
this.listeners[event].forEach(function (l) {
|
this.#listeners[event].forEach(function (l) {
|
||||||
if (l.context) {
|
if (l.context) {
|
||||||
l.callback.apply(l.context, payload);
|
l.callback.apply(l.context, payload);
|
||||||
} else {
|
} else {
|
||||||
l.callback(...payload);
|
l.callback(...payload);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
CompositionCollection.prototype.cleanUpMutables = function () {
|
/**
|
||||||
Object.values(this.mutables).forEach(mutable => {
|
* Destroy all mutables.
|
||||||
this.publicAPI.objects.destroyMutable(mutable);
|
* @private
|
||||||
|
*/
|
||||||
|
#cleanUpMutables() {
|
||||||
|
Object.values(this.#mutables).forEach(mutable => {
|
||||||
|
this.#publicAPI.objects.destroyMutable(mutable);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
}
|
||||||
return CompositionCollection;
|
|
||||||
});
|
|
||||||
|
|||||||
200
src/api/composition/CompositionProvider.js
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* 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 _ from 'lodash';
|
||||||
|
import objectUtils from "../objects/object-utils";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {import('../objects/ObjectAPI').DomainObject} DomainObject
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {import('../objects/ObjectAPI').Identifier} Identifier
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {import('./CompositionAPI').default} CompositionAPI
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {import('../../../openmct').OpenMCT} OpenMCT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A CompositionProvider provides the underlying implementation of
|
||||||
|
* composition-related behavior for certain types of domain object.
|
||||||
|
*
|
||||||
|
* By default, a composition provider will not support composition
|
||||||
|
* modification. You can add support for mutation of composition by
|
||||||
|
* defining `add` and/or `remove` methods.
|
||||||
|
*
|
||||||
|
* If the composition of an object can change over time-- perhaps via
|
||||||
|
* server updates or mutation via the add/remove methods, then one must
|
||||||
|
* trigger events as necessary.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export default class CompositionProvider {
|
||||||
|
#publicAPI;
|
||||||
|
#listeningTo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {OpenMCT} publicAPI
|
||||||
|
* @param {CompositionAPI} compositionAPI
|
||||||
|
*/
|
||||||
|
constructor(publicAPI, compositionAPI) {
|
||||||
|
this.#publicAPI = publicAPI;
|
||||||
|
this.#listeningTo = {};
|
||||||
|
|
||||||
|
compositionAPI.addPolicy(this.#cannotContainItself.bind(this));
|
||||||
|
compositionAPI.addPolicy(this.#supportsComposition.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
get listeningTo() {
|
||||||
|
return this.#listeningTo;
|
||||||
|
}
|
||||||
|
|
||||||
|
get publicAPI() {
|
||||||
|
return this.#publicAPI;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if this provider should be used to load composition for a
|
||||||
|
* particular domain object.
|
||||||
|
* @method appliesTo
|
||||||
|
* @param {import('../objects/ObjectAPI').DomainObject} domainObject the domain object
|
||||||
|
* to check
|
||||||
|
* @returns {boolean} true if this provider can provide composition for a given domain object
|
||||||
|
*/
|
||||||
|
appliesTo(domainObject) {
|
||||||
|
throw new Error("This method must be implemented by a subclass.");
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Load any domain objects contained in the composition of this domain
|
||||||
|
* object.
|
||||||
|
* @param {DomainObject} domainObject the domain object
|
||||||
|
* for which to load composition
|
||||||
|
* @returns {Promise<Identifier[]>} a promise for
|
||||||
|
* the Identifiers in this composition
|
||||||
|
* @method load
|
||||||
|
*/
|
||||||
|
load(domainObject) {
|
||||||
|
throw new Error("This method must be implemented by a subclass.");
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Attach listeners for changes to the composition of a given domain object.
|
||||||
|
* Supports `add` and `remove` events.
|
||||||
|
*
|
||||||
|
* @param {DomainObject} domainObject to listen to
|
||||||
|
* @param {string} event the event to bind to, either `add` or `remove`.
|
||||||
|
* @param {Function} callback callback to invoke when event is triggered.
|
||||||
|
* @param {any} [context] to use when invoking callback.
|
||||||
|
*/
|
||||||
|
on(domainObject,
|
||||||
|
event,
|
||||||
|
callback,
|
||||||
|
context) {
|
||||||
|
throw new Error("This method must be implemented by a subclass.");
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Remove a listener that was previously added for a given domain object.
|
||||||
|
* event name, callback, and context must be the same as when the listener
|
||||||
|
* was originally attached.
|
||||||
|
*
|
||||||
|
* @param {DomainObject} domainObject to remove listener for
|
||||||
|
* @param {string} event event to stop listening to: `add` or `remove`.
|
||||||
|
* @param {Function} callback callback to remove.
|
||||||
|
* @param {any} context of callback to remove.
|
||||||
|
*/
|
||||||
|
off(domainObject,
|
||||||
|
event,
|
||||||
|
callback,
|
||||||
|
context) {
|
||||||
|
throw new Error("This method must be implemented by a subclass.");
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Remove a domain object from another domain object's composition.
|
||||||
|
*
|
||||||
|
* This method is optional; if not present, adding to a domain object's
|
||||||
|
* composition using this provider will be disallowed.
|
||||||
|
*
|
||||||
|
* @param {DomainObject} domainObject the domain object
|
||||||
|
* which should have its composition modified
|
||||||
|
* @param {Identifier} childId the domain object to remove
|
||||||
|
* @method remove
|
||||||
|
*/
|
||||||
|
remove(domainObject, childId) {
|
||||||
|
throw new Error("This method must be implemented by a subclass.");
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Add a domain object to another domain object's composition.
|
||||||
|
*
|
||||||
|
* This method is optional; if not present, adding to a domain object's
|
||||||
|
* composition using this provider will be disallowed.
|
||||||
|
*
|
||||||
|
* @param {DomainObject} parent the domain object
|
||||||
|
* which should have its composition modified
|
||||||
|
* @param {Identifier} childId the domain object to add
|
||||||
|
* @method add
|
||||||
|
*/
|
||||||
|
add(parent, childId) {
|
||||||
|
throw new Error("This method must be implemented by a subclass.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {DomainObject} parent
|
||||||
|
* @param {Identifier} childId
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
includes(parent, childId) {
|
||||||
|
throw new Error("This method must be implemented by a subclass.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {DomainObject} domainObject
|
||||||
|
* @param {number} oldIndex
|
||||||
|
* @param {number} newIndex
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
reorder(domainObject, oldIndex, newIndex) {
|
||||||
|
throw new Error("This method must be implemented by a subclass.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @param {DomainObject} parent
|
||||||
|
* @param {DomainObject} child
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
#cannotContainItself(parent, child) {
|
||||||
|
return !(parent.identifier.namespace === child.identifier.namespace
|
||||||
|
&& parent.identifier.key === child.identifier.key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @param {DomainObject} parent
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
#supportsComposition(parent, _child) {
|
||||||
|
return this.#publicAPI.composition.supportsComposition(parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -19,102 +19,79 @@
|
|||||||
* this source code distribution or the Licensing information page available
|
* this source code distribution or the Licensing information page available
|
||||||
* at runtime from the About dialog for additional information.
|
* at runtime from the About dialog for additional information.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
import objectUtils from "../objects/object-utils";
|
||||||
|
import CompositionProvider from './CompositionProvider';
|
||||||
|
|
||||||
define([
|
/**
|
||||||
'lodash',
|
* @typedef {import('../objects/ObjectAPI').DomainObject} DomainObject
|
||||||
'objectUtils'
|
*/
|
||||||
], function (
|
|
||||||
_,
|
|
||||||
objectUtils
|
|
||||||
) {
|
|
||||||
/**
|
|
||||||
* A CompositionProvider provides the underlying implementation of
|
|
||||||
* composition-related behavior for certain types of domain object.
|
|
||||||
*
|
|
||||||
* By default, a composition provider will not support composition
|
|
||||||
* modification. You can add support for mutation of composition by
|
|
||||||
* defining `add` and/or `remove` methods.
|
|
||||||
*
|
|
||||||
* If the composition of an object can change over time-- perhaps via
|
|
||||||
* server updates or mutation via the add/remove methods, then one must
|
|
||||||
* trigger events as necessary.
|
|
||||||
*
|
|
||||||
* @interface CompositionProvider
|
|
||||||
* @memberof module:openmct
|
|
||||||
*/
|
|
||||||
|
|
||||||
function DefaultCompositionProvider(publicAPI, compositionAPI) {
|
/**
|
||||||
this.publicAPI = publicAPI;
|
* @typedef {import('../objects/ObjectAPI').Identifier} Identifier
|
||||||
this.listeningTo = {};
|
*/
|
||||||
this.onMutation = this.onMutation.bind(this);
|
|
||||||
|
|
||||||
this.cannotContainItself = this.cannotContainItself.bind(this);
|
/**
|
||||||
this.supportsComposition = this.supportsComposition.bind(this);
|
* @typedef {import('./CompositionAPI').default} CompositionAPI
|
||||||
|
*/
|
||||||
|
|
||||||
compositionAPI.addPolicy(this.cannotContainItself);
|
/**
|
||||||
compositionAPI.addPolicy(this.supportsComposition);
|
* @typedef {import('../../../openmct').OpenMCT} OpenMCT
|
||||||
}
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
DefaultCompositionProvider.prototype.cannotContainItself = function (parent, child) {
|
|
||||||
return !(parent.identifier.namespace === child.identifier.namespace
|
|
||||||
&& parent.identifier.key === child.identifier.key);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
DefaultCompositionProvider.prototype.supportsComposition = function (parent, child) {
|
|
||||||
return this.publicAPI.composition.supportsComposition(parent);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A CompositionProvider provides the underlying implementation of
|
||||||
|
* composition-related behavior for certain types of domain object.
|
||||||
|
*
|
||||||
|
* By default, a composition provider will not support composition
|
||||||
|
* modification. You can add support for mutation of composition by
|
||||||
|
* defining `add` and/or `remove` methods.
|
||||||
|
*
|
||||||
|
* If the composition of an object can change over time-- perhaps via
|
||||||
|
* server updates or mutation via the add/remove methods, then one must
|
||||||
|
* trigger events as necessary.
|
||||||
|
* @extends CompositionProvider
|
||||||
|
*/
|
||||||
|
export default class DefaultCompositionProvider extends CompositionProvider {
|
||||||
/**
|
/**
|
||||||
* Check if this provider should be used to load composition for a
|
* Check if this provider should be used to load composition for a
|
||||||
* particular domain object.
|
* particular domain object.
|
||||||
* @param {module:openmct.DomainObject} domainObject the domain object
|
* @override
|
||||||
|
* @param {DomainObject} domainObject the domain object
|
||||||
* to check
|
* to check
|
||||||
* @returns {boolean} true if this provider can provide
|
* @returns {boolean} true if this provider can provide composition for a given domain object
|
||||||
* composition for a given domain object
|
|
||||||
* @memberof module:openmct.CompositionProvider#
|
|
||||||
* @method appliesTo
|
|
||||||
*/
|
*/
|
||||||
DefaultCompositionProvider.prototype.appliesTo = function (domainObject) {
|
appliesTo(domainObject) {
|
||||||
return Boolean(domainObject.composition);
|
return Boolean(domainObject.composition);
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load any domain objects contained in the composition of this domain
|
* Load any domain objects contained in the composition of this domain
|
||||||
* object.
|
* object.
|
||||||
* @param {module:openmct.DomainObject} domainObject the domain object
|
* @override
|
||||||
|
* @param {DomainObject} domainObject the domain object
|
||||||
* for which to load composition
|
* for which to load composition
|
||||||
* @returns {Promise.<Array.<module:openmct.Identifier>>} a promise for
|
* @returns {Promise<Identifier[]>} a promise for
|
||||||
* the Identifiers in this composition
|
* the Identifiers in this composition
|
||||||
* @memberof module:openmct.CompositionProvider#
|
|
||||||
* @method load
|
|
||||||
*/
|
*/
|
||||||
DefaultCompositionProvider.prototype.load = function (domainObject) {
|
load(domainObject) {
|
||||||
return Promise.all(domainObject.composition);
|
return Promise.all(domainObject.composition);
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attach listeners for changes to the composition of a given domain object.
|
* Attach listeners for changes to the composition of a given domain object.
|
||||||
* Supports `add` and `remove` events.
|
* Supports `add` and `remove` events.
|
||||||
*
|
*
|
||||||
* @param {module:openmct.DomainObject} domainObject to listen to
|
* @override
|
||||||
* @param String event the event to bind to, either `add` or `remove`.
|
* @param {DomainObject} domainObject to listen to
|
||||||
* @param Function callback callback to invoke when event is triggered.
|
* @param {string} event the event to bind to, either `add` or `remove`.
|
||||||
* @param [context] context to use when invoking callback.
|
* @param {Function} callback callback to invoke when event is triggered.
|
||||||
|
* @param {any} [context] to use when invoking callback.
|
||||||
*/
|
*/
|
||||||
DefaultCompositionProvider.prototype.on = function (
|
on(domainObject,
|
||||||
domainObject,
|
|
||||||
event,
|
event,
|
||||||
callback,
|
callback,
|
||||||
context
|
context) {
|
||||||
) {
|
//this.establishTopicListener();
|
||||||
this.establishTopicListener();
|
|
||||||
|
|
||||||
|
/** @type {string} */
|
||||||
const keyString = objectUtils.makeKeyString(domainObject.identifier);
|
const keyString = objectUtils.makeKeyString(domainObject.identifier);
|
||||||
let objectListeners = this.listeningTo[keyString];
|
let objectListeners = this.listeningTo[keyString];
|
||||||
|
|
||||||
@@ -131,24 +108,24 @@ define([
|
|||||||
callback: callback,
|
callback: callback,
|
||||||
context: context
|
context: context
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a listener that was previously added for a given domain object.
|
* Remove a listener that was previously added for a given domain object.
|
||||||
* event name, callback, and context must be the same as when the listener
|
* event name, callback, and context must be the same as when the listener
|
||||||
* was originally attached.
|
* was originally attached.
|
||||||
*
|
*
|
||||||
* @param {module:openmct.DomainObject} domainObject to remove listener for
|
* @override
|
||||||
* @param String event event to stop listening to: `add` or `remove`.
|
* @param {DomainObject} domainObject to remove listener for
|
||||||
* @param Function callback callback to remove.
|
* @param {string} event event to stop listening to: `add` or `remove`.
|
||||||
* @param [context] context of callback to remove.
|
* @param {Function} callback callback to remove.
|
||||||
|
* @param {any} context of callback to remove.
|
||||||
*/
|
*/
|
||||||
DefaultCompositionProvider.prototype.off = function (
|
off(domainObject,
|
||||||
domainObject,
|
|
||||||
event,
|
event,
|
||||||
callback,
|
callback,
|
||||||
context
|
context) {
|
||||||
) {
|
|
||||||
|
/** @type {string} */
|
||||||
const keyString = objectUtils.makeKeyString(domainObject.identifier);
|
const keyString = objectUtils.makeKeyString(domainObject.identifier);
|
||||||
const objectListeners = this.listeningTo[keyString];
|
const objectListeners = this.listeningTo[keyString];
|
||||||
|
|
||||||
@@ -160,57 +137,68 @@ define([
|
|||||||
if (!objectListeners.add.length && !objectListeners.remove.length && !objectListeners.reorder.length) {
|
if (!objectListeners.add.length && !objectListeners.remove.length && !objectListeners.reorder.length) {
|
||||||
delete this.listeningTo[keyString];
|
delete this.listeningTo[keyString];
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a domain object from another domain object's composition.
|
* Remove a domain object from another domain object's composition.
|
||||||
*
|
*
|
||||||
* This method is optional; if not present, adding to a domain object's
|
* This method is optional; if not present, adding to a domain object's
|
||||||
* composition using this provider will be disallowed.
|
* composition using this provider will be disallowed.
|
||||||
*
|
*
|
||||||
* @param {module:openmct.DomainObject} domainObject the domain object
|
* @override
|
||||||
|
* @param {DomainObject} domainObject the domain object
|
||||||
* which should have its composition modified
|
* which should have its composition modified
|
||||||
* @param {module:openmct.DomainObject} child the domain object to remove
|
* @param {Identifier} childId the domain object to remove
|
||||||
* @memberof module:openmct.CompositionProvider#
|
|
||||||
* @method remove
|
* @method remove
|
||||||
*/
|
*/
|
||||||
DefaultCompositionProvider.prototype.remove = function (domainObject, childId) {
|
remove(domainObject, childId) {
|
||||||
let composition = domainObject.composition.filter(function (child) {
|
let composition = domainObject.composition.filter(function (child) {
|
||||||
return !(childId.namespace === child.namespace
|
return !(childId.namespace === child.namespace
|
||||||
&& childId.key === child.key);
|
&& childId.key === child.key);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.publicAPI.objects.mutate(domainObject, 'composition', composition);
|
this.publicAPI.objects.mutate(domainObject, 'composition', composition);
|
||||||
};
|
|
||||||
|
|
||||||
|
this.objectListeners.remove?.forEach(listener => listener.callback.apply(listener.context, childId));
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Add a domain object to another domain object's composition.
|
* Add a domain object to another domain object's composition.
|
||||||
*
|
*
|
||||||
* This method is optional; if not present, adding to a domain object's
|
* This method is optional; if not present, adding to a domain object's
|
||||||
* composition using this provider will be disallowed.
|
* composition using this provider will be disallowed.
|
||||||
*
|
*
|
||||||
* @param {module:openmct.DomainObject} domainObject the domain object
|
* @override
|
||||||
|
* @param {DomainObject} parent the domain object
|
||||||
* which should have its composition modified
|
* which should have its composition modified
|
||||||
* @param {module:openmct.DomainObject} child the domain object to add
|
* @param {Identifier} childId the domain object to add
|
||||||
* @memberof module:openmct.CompositionProvider#
|
|
||||||
* @method add
|
* @method add
|
||||||
*/
|
*/
|
||||||
DefaultCompositionProvider.prototype.add = function (parent, childId) {
|
add(parent, childId) {
|
||||||
if (!this.includes(parent, childId)) {
|
if (!this.includes(parent, childId)) {
|
||||||
parent.composition.push(childId);
|
parent.composition.push(childId);
|
||||||
this.publicAPI.objects.mutate(parent, 'composition', parent.composition);
|
this.publicAPI.objects.mutate(parent, 'composition', parent.composition);
|
||||||
|
|
||||||
|
this.objectListeners.add?.forEach(listener => listener.callback.apply(listener.context, childId));
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @override
|
||||||
|
* @param {DomainObject} parent
|
||||||
|
* @param {Identifier} childId
|
||||||
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
DefaultCompositionProvider.prototype.includes = function (parent, childId) {
|
includes(parent, childId) {
|
||||||
return parent.composition.some(composee =>
|
return parent.composition.some(composee => this.publicAPI.objects.areIdsEqual(composee, childId));
|
||||||
this.publicAPI.objects.areIdsEqual(composee, childId));
|
}
|
||||||
};
|
|
||||||
|
|
||||||
DefaultCompositionProvider.prototype.reorder = function (domainObject, oldIndex, newIndex) {
|
/**
|
||||||
|
* @override
|
||||||
|
* @param {DomainObject} domainObject
|
||||||
|
* @param {number} oldIndex
|
||||||
|
* @param {number} newIndex
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
reorder(domainObject, oldIndex, newIndex) {
|
||||||
let newComposition = domainObject.composition.slice();
|
let newComposition = domainObject.composition.slice();
|
||||||
let removeId = oldIndex > newIndex ? oldIndex + 1 : oldIndex;
|
let removeId = oldIndex > newIndex ? oldIndex + 1 : oldIndex;
|
||||||
let insertPosition = oldIndex < newIndex ? newIndex + 1 : newIndex;
|
let insertPosition = oldIndex < newIndex ? newIndex + 1 : newIndex;
|
||||||
@@ -241,6 +229,7 @@ define([
|
|||||||
|
|
||||||
this.publicAPI.objects.mutate(domainObject, 'composition', newComposition);
|
this.publicAPI.objects.mutate(domainObject, 'composition', newComposition);
|
||||||
|
|
||||||
|
/** @type {string} */
|
||||||
let id = objectUtils.makeKeyString(domainObject.identifier);
|
let id = objectUtils.makeKeyString(domainObject.identifier);
|
||||||
const listeners = this.listeningTo[id];
|
const listeners = this.listeningTo[id];
|
||||||
|
|
||||||
@@ -257,66 +246,5 @@ define([
|
|||||||
listener.callback(reorderPlan);
|
listener.callback(reorderPlan);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Listens on general mutation topic, using injector to fetch to avoid
|
|
||||||
* circular dependencies.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
DefaultCompositionProvider.prototype.establishTopicListener = function () {
|
|
||||||
if (this.topicListener) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.publicAPI.objects.eventEmitter.on('mutation', this.onMutation);
|
|
||||||
this.topicListener = () => {
|
|
||||||
this.publicAPI.objects.eventEmitter.off('mutation', this.onMutation);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles mutation events. If there are active listeners for the mutated
|
|
||||||
* object, detects changes to composition and triggers necessary events.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
DefaultCompositionProvider.prototype.onMutation = function (oldDomainObject) {
|
|
||||||
const id = objectUtils.makeKeyString(oldDomainObject.identifier);
|
|
||||||
const listeners = this.listeningTo[id];
|
|
||||||
|
|
||||||
if (!listeners) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const oldComposition = listeners.composition.map(objectUtils.makeKeyString);
|
|
||||||
const newComposition = oldDomainObject.composition.map(objectUtils.makeKeyString);
|
|
||||||
|
|
||||||
const added = _.difference(newComposition, oldComposition).map(objectUtils.parseKeyString);
|
|
||||||
const removed = _.difference(oldComposition, newComposition).map(objectUtils.parseKeyString);
|
|
||||||
|
|
||||||
function notify(value) {
|
|
||||||
return function (listener) {
|
|
||||||
if (listener.context) {
|
|
||||||
listener.callback.call(listener.context, value);
|
|
||||||
} else {
|
|
||||||
listener.callback(value);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
listeners.composition = newComposition.map(objectUtils.parseKeyString);
|
|
||||||
|
|
||||||
added.forEach(function (addedChild) {
|
|
||||||
listeners.add.forEach(notify(addedChild));
|
|
||||||
});
|
|
||||||
|
|
||||||
removed.forEach(function (removedChild) {
|
|
||||||
listeners.remove.forEach(notify(removedChild));
|
|
||||||
});
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
return DefaultCompositionProvider;
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -23,13 +23,11 @@
|
|||||||
import FormController from './FormController';
|
import FormController from './FormController';
|
||||||
import FormProperties from './components/FormProperties.vue';
|
import FormProperties from './components/FormProperties.vue';
|
||||||
|
|
||||||
import EventEmitter from 'EventEmitter';
|
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
export default class FormsAPI extends EventEmitter {
|
export default class FormsAPI {
|
||||||
constructor(openmct) {
|
constructor(openmct) {
|
||||||
super();
|
|
||||||
|
|
||||||
this.openmct = openmct;
|
this.openmct = openmct;
|
||||||
this.formController = new FormController(openmct);
|
this.formController = new FormController(openmct);
|
||||||
}
|
}
|
||||||
@@ -92,29 +90,75 @@ export default class FormsAPI extends EventEmitter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Show form inside an Overlay dialog with given form structure
|
* Show form inside an Overlay dialog with given form structure
|
||||||
|
* @public
|
||||||
|
* @param {Array<Section>} formStructure a form structure, array of section
|
||||||
|
* @param {Object} options
|
||||||
|
* @property {function} onChange a callback function when any changes detected
|
||||||
|
*/
|
||||||
|
showForm(formStructure, {
|
||||||
|
onChange
|
||||||
|
} = {}) {
|
||||||
|
let overlay;
|
||||||
|
|
||||||
|
const self = this;
|
||||||
|
|
||||||
|
const overlayEl = document.createElement('div');
|
||||||
|
overlayEl.classList.add('u-contents');
|
||||||
|
|
||||||
|
overlay = self.openmct.overlays.overlay({
|
||||||
|
element: overlayEl,
|
||||||
|
size: 'dialog'
|
||||||
|
});
|
||||||
|
|
||||||
|
let formSave;
|
||||||
|
let formCancel;
|
||||||
|
const promise = new Promise((resolve, reject) => {
|
||||||
|
formSave = resolve;
|
||||||
|
formCancel = reject;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.showCustomForm(formStructure, {
|
||||||
|
element: overlayEl,
|
||||||
|
onChange
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
overlay.dismiss();
|
||||||
|
formSave(response);
|
||||||
|
})
|
||||||
|
.catch((response) => {
|
||||||
|
overlay.dismiss();
|
||||||
|
formCancel(response);
|
||||||
|
});
|
||||||
|
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show form as a child of the element provided with given form structure
|
||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
* @param {Array<Section>} formStructure a form structure, array of section
|
* @param {Array<Section>} formStructure a form structure, array of section
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
* @property {HTMLElement} element Parent Element to render a Form
|
* @property {HTMLElement} element Parent Element to render a Form
|
||||||
* @property {function} onChange a callback function when any changes detected
|
* @property {function} onChange a callback function when any changes detected
|
||||||
* @property {function} onSave a callback function when form is submitted
|
|
||||||
* @property {function} onDismiss a callback function when form is dismissed
|
|
||||||
*/
|
*/
|
||||||
showForm(formStructure, {
|
showCustomForm(formStructure, {
|
||||||
element,
|
element,
|
||||||
onChange
|
onChange
|
||||||
} = {}) {
|
} = {}) {
|
||||||
const changes = {};
|
if (element === undefined) {
|
||||||
let overlay;
|
throw Error('Required element parameter not provided');
|
||||||
let onDismiss;
|
}
|
||||||
let onSave;
|
|
||||||
|
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
|
const changes = {};
|
||||||
|
let formSave;
|
||||||
|
let formCancel;
|
||||||
|
|
||||||
const promise = new Promise((resolve, reject) => {
|
const promise = new Promise((resolve, reject) => {
|
||||||
onSave = onFormAction(resolve);
|
formSave = onFormAction(resolve);
|
||||||
onDismiss = onFormAction(reject);
|
formCancel = onFormAction(reject);
|
||||||
});
|
});
|
||||||
|
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
@@ -126,26 +170,17 @@ export default class FormsAPI extends EventEmitter {
|
|||||||
return {
|
return {
|
||||||
formStructure,
|
formStructure,
|
||||||
onChange: onFormPropertyChange,
|
onChange: onFormPropertyChange,
|
||||||
onDismiss,
|
onCancel: formCancel,
|
||||||
onSave
|
onSave: formSave
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
template: '<FormProperties :model="formStructure" @onChange="onChange" @onDismiss="onDismiss" @onSave="onSave"></FormProperties>'
|
template: '<FormProperties :model="formStructure" @onChange="onChange" @onCancel="onCancel" @onSave="onSave"></FormProperties>'
|
||||||
}).$mount();
|
}).$mount();
|
||||||
|
|
||||||
const formElement = vm.$el;
|
const formElement = vm.$el;
|
||||||
if (element) {
|
element.append(formElement);
|
||||||
element.append(formElement);
|
|
||||||
} else {
|
|
||||||
overlay = self.openmct.overlays.overlay({
|
|
||||||
element: vm.$el,
|
|
||||||
size: 'dialog',
|
|
||||||
onDestroy: () => vm.$destroy()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function onFormPropertyChange(data) {
|
function onFormPropertyChange(data) {
|
||||||
self.emit('onFormPropertyChange', data);
|
|
||||||
if (onChange) {
|
if (onChange) {
|
||||||
onChange(data);
|
onChange(data);
|
||||||
}
|
}
|
||||||
@@ -158,17 +193,14 @@ export default class FormsAPI extends EventEmitter {
|
|||||||
key = property.join('.');
|
key = property.join('.');
|
||||||
}
|
}
|
||||||
|
|
||||||
changes[key] = data.value;
|
_.set(changes, key, data.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onFormAction(callback) {
|
function onFormAction(callback) {
|
||||||
return () => {
|
return () => {
|
||||||
if (element) {
|
formElement.remove();
|
||||||
formElement.remove();
|
vm.$destroy();
|
||||||
} else {
|
|
||||||
overlay.dismiss();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(changes);
|
callback(changes);
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ describe('The Forms API', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('when container element is provided', (done) => {
|
it('when container element is provided', (done) => {
|
||||||
openmct.forms.showForm(formStructure, { element }).catch(() => {
|
openmct.forms.showCustomForm(formStructure, { element }).catch(() => {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
const titleElement = element.querySelector('.c-overlay__dialog-title');
|
const titleElement = element.querySelector('.c-overlay__dialog-title');
|
||||||
|
|||||||
@@ -73,7 +73,7 @@
|
|||||||
tabindex="0"
|
tabindex="0"
|
||||||
class="c-button js-cancel-button"
|
class="c-button js-cancel-button"
|
||||||
aria-label="Cancel"
|
aria-label="Cancel"
|
||||||
@click="onDismiss"
|
@click="onCancel"
|
||||||
>
|
>
|
||||||
{{ cancelLabel }}
|
{{ cancelLabel }}
|
||||||
</button>
|
</button>
|
||||||
@@ -164,8 +164,8 @@ export default {
|
|||||||
|
|
||||||
this.$emit('onChange', data);
|
this.$emit('onChange', data);
|
||||||
},
|
},
|
||||||
onDismiss() {
|
onCancel() {
|
||||||
this.$emit('onDismiss');
|
this.$emit('onCancel');
|
||||||
},
|
},
|
||||||
onSave() {
|
onSave() {
|
||||||
this.$emit('onSave');
|
this.$emit('onSave');
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
id="fileElem"
|
id="fileElem"
|
||||||
ref="fileInput"
|
ref="fileInput"
|
||||||
type="file"
|
type="file"
|
||||||
accept=".json"
|
:accept="acceptableFileTypes"
|
||||||
style="display:none"
|
style="display:none"
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
@@ -72,6 +72,13 @@ export default {
|
|||||||
},
|
},
|
||||||
removable() {
|
removable() {
|
||||||
return (this.fileInfo || this.model.value) && this.model.removable;
|
return (this.fileInfo || this.model.value) && this.model.removable;
|
||||||
|
},
|
||||||
|
acceptableFileTypes() {
|
||||||
|
if (this.model.type) {
|
||||||
|
return this.model.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'application/json';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
@@ -80,7 +87,13 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
handleFiles() {
|
handleFiles() {
|
||||||
const fileList = this.$refs.fileInput.files;
|
const fileList = this.$refs.fileInput.files;
|
||||||
this.readFile(fileList[0]);
|
const file = fileList[0];
|
||||||
|
|
||||||
|
if (this.acceptableFileTypes === 'application/json') {
|
||||||
|
this.readFile(file);
|
||||||
|
} else {
|
||||||
|
this.handleRawFile(file);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
readFile(file) {
|
readFile(file) {
|
||||||
const self = this;
|
const self = this;
|
||||||
@@ -104,6 +117,21 @@ export default {
|
|||||||
|
|
||||||
fileReader.readAsText(file);
|
fileReader.readAsText(file);
|
||||||
},
|
},
|
||||||
|
handleRawFile(file) {
|
||||||
|
const fileInfo = {
|
||||||
|
name: file.name,
|
||||||
|
body: file
|
||||||
|
};
|
||||||
|
|
||||||
|
this.fileInfo = Object.assign({}, fileInfo);
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
model: this.model,
|
||||||
|
value: fileInfo
|
||||||
|
};
|
||||||
|
|
||||||
|
this.$emit('onChange', data);
|
||||||
|
},
|
||||||
selectFile() {
|
selectFile() {
|
||||||
this.$refs.fileInput.click();
|
this.$refs.fileInput.click();
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<mct-tree
|
<mct-tree
|
||||||
|
id="locator-tree"
|
||||||
:is-selector-tree="true"
|
:is-selector-tree="true"
|
||||||
:initial-selection="model.parent"
|
:initial-selection="model.parent"
|
||||||
@tree-item-selection="handleItemSelection"
|
@tree-item-selection="handleItemSelection"
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
v-model="selected"
|
v-model="selected"
|
||||||
required="model.required"
|
required="model.required"
|
||||||
name="mctControl"
|
name="mctControl"
|
||||||
|
:aria-label="model.ariaLabel || model.name"
|
||||||
@change="onChange($event)"
|
@change="onChange($event)"
|
||||||
>
|
>
|
||||||
<option
|
<option
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
:class="model.cssClass"
|
:class="model.cssClass"
|
||||||
>
|
>
|
||||||
<textarea
|
<textarea
|
||||||
|
:id="`${model.key}-textarea`"
|
||||||
v-model="field"
|
v-model="field"
|
||||||
type="text"
|
type="text"
|
||||||
:size="model.size"
|
:size="model.size"
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
<ToggleSwitch
|
<ToggleSwitch
|
||||||
id="switchId"
|
id="switchId"
|
||||||
:checked="isChecked"
|
:checked="isChecked"
|
||||||
|
:name="model.name"
|
||||||
@change="toggleCheckBox"
|
@change="toggleCheckBox"
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -3,39 +3,52 @@
|
|||||||
class="c-menu"
|
class="c-menu"
|
||||||
:class="options.menuClass"
|
:class="options.menuClass"
|
||||||
>
|
>
|
||||||
<ul v-if="options.actions.length && options.actions[0].length">
|
<ul
|
||||||
|
v-if="options.actions.length && options.actions[0].length"
|
||||||
|
role="menu"
|
||||||
|
>
|
||||||
<template
|
<template
|
||||||
v-for="(actionGroups, index) in options.actions"
|
v-for="(actionGroups, index) in options.actions"
|
||||||
>
|
>
|
||||||
<li
|
|
||||||
v-for="action in actionGroups"
|
|
||||||
:key="action.name"
|
|
||||||
:class="[action.cssClass, action.isDisabled ? 'disabled' : '']"
|
|
||||||
:title="action.description"
|
|
||||||
:data-testid="action.testId || false"
|
|
||||||
@click="action.onItemClicked"
|
|
||||||
>
|
|
||||||
{{ action.name }}
|
|
||||||
</li>
|
|
||||||
<div
|
<div
|
||||||
v-if="index !== options.actions.length - 1"
|
|
||||||
:key="index"
|
:key="index"
|
||||||
class="c-menu__section-separator"
|
role="group"
|
||||||
>
|
>
|
||||||
</div>
|
<li
|
||||||
<li
|
v-for="action in actionGroups"
|
||||||
v-if="actionGroups.length === 0"
|
:key="action.name"
|
||||||
:key="index"
|
role="menuitem"
|
||||||
>
|
:class="[action.cssClass, action.isDisabled ? 'disabled' : '']"
|
||||||
No actions defined.
|
:title="action.description"
|
||||||
</li>
|
:data-testid="action.testId || false"
|
||||||
</template>
|
@click="action.onItemClicked"
|
||||||
|
>
|
||||||
|
{{ action.name }}
|
||||||
|
</li>
|
||||||
|
<div
|
||||||
|
v-if="index !== options.actions.length - 1"
|
||||||
|
:key="index"
|
||||||
|
role="separator"
|
||||||
|
class="c-menu__section-separator"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
<li
|
||||||
|
v-if="actionGroups.length === 0"
|
||||||
|
:key="index"
|
||||||
|
>
|
||||||
|
No actions defined.
|
||||||
|
</li>
|
||||||
|
</div></template>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<ul v-else>
|
<ul
|
||||||
|
v-else
|
||||||
|
role="menu"
|
||||||
|
>
|
||||||
<li
|
<li
|
||||||
v-for="action in options.actions"
|
v-for="action in options.actions"
|
||||||
:key="action.name"
|
:key="action.name"
|
||||||
|
role="menuitem"
|
||||||
:class="[action.cssClass, action.isDisabled ? 'disabled' : '']"
|
:class="[action.cssClass, action.isDisabled ? 'disabled' : '']"
|
||||||
:title="action.description"
|
:title="action.description"
|
||||||
:data-testid="action.testId || false"
|
:data-testid="action.testId || false"
|
||||||
|
|||||||
@@ -5,45 +5,54 @@
|
|||||||
>
|
>
|
||||||
<ul
|
<ul
|
||||||
v-if="options.actions.length && options.actions[0].length"
|
v-if="options.actions.length && options.actions[0].length"
|
||||||
|
role="menu"
|
||||||
class="c-super-menu__menu"
|
class="c-super-menu__menu"
|
||||||
>
|
>
|
||||||
<template
|
<template
|
||||||
v-for="(actionGroups, index) in options.actions"
|
v-for="(actionGroups, index) in options.actions"
|
||||||
>
|
>
|
||||||
<li
|
|
||||||
v-for="action in actionGroups"
|
|
||||||
:key="action.name"
|
|
||||||
:class="[action.cssClass, action.isDisabled ? 'disabled' : '']"
|
|
||||||
:title="action.description"
|
|
||||||
:data-testid="action.testId || false"
|
|
||||||
@click="action.onItemClicked"
|
|
||||||
@mouseover="toggleItemDescription(action)"
|
|
||||||
@mouseleave="toggleItemDescription()"
|
|
||||||
>
|
|
||||||
{{ action.name }}
|
|
||||||
</li>
|
|
||||||
<div
|
<div
|
||||||
v-if="index !== options.actions.length - 1"
|
|
||||||
:key="index"
|
:key="index"
|
||||||
class="c-menu__section-separator"
|
role="group"
|
||||||
>
|
>
|
||||||
</div>
|
<li
|
||||||
<li
|
v-for="action in actionGroups"
|
||||||
v-if="actionGroups.length === 0"
|
:key="action.name"
|
||||||
:key="index"
|
role="menuitem"
|
||||||
>
|
:class="[action.cssClass, action.isDisabled ? 'disabled' : '']"
|
||||||
No actions defined.
|
:title="action.description"
|
||||||
</li>
|
:data-testid="action.testId || false"
|
||||||
</template>
|
@click="action.onItemClicked"
|
||||||
|
@mouseover="toggleItemDescription(action)"
|
||||||
|
@mouseleave="toggleItemDescription()"
|
||||||
|
>
|
||||||
|
{{ action.name }}
|
||||||
|
</li>
|
||||||
|
<div
|
||||||
|
v-if="index !== options.actions.length - 1"
|
||||||
|
:key="index"
|
||||||
|
role="separator"
|
||||||
|
class="c-menu__section-separator"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
<li
|
||||||
|
v-if="actionGroups.length === 0"
|
||||||
|
:key="index"
|
||||||
|
>
|
||||||
|
No actions defined.
|
||||||
|
</li>
|
||||||
|
</div></template>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<ul
|
<ul
|
||||||
v-else
|
v-else
|
||||||
class="c-super-menu__menu"
|
class="c-super-menu__menu"
|
||||||
|
role="menu"
|
||||||
>
|
>
|
||||||
<li
|
<li
|
||||||
v-for="action in options.actions"
|
v-for="action in options.actions"
|
||||||
:key="action.name"
|
:key="action.name"
|
||||||
|
role="menuitem"
|
||||||
:class="action.cssClass"
|
:class="action.cssClass"
|
||||||
:title="action.description"
|
:title="action.description"
|
||||||
:data-testid="action.testId || false"
|
:data-testid="action.testId || false"
|
||||||
|
|||||||
@@ -31,7 +31,31 @@
|
|||||||
* @namespace platform/api/notifications
|
* @namespace platform/api/notifications
|
||||||
*/
|
*/
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import EventEmitter from 'EventEmitter';
|
import EventEmitter from 'eventemitter3';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} NotificationProperties
|
||||||
|
* @property {function} dismiss Dismiss the notification
|
||||||
|
* @property {NotificationModel} model The Notification model
|
||||||
|
* @property {(progressPerc: number, progressText: string) => void} [progress] Update the progress of the notification
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {EventEmitter & NotificationProperties} Notification
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} NotificationLink
|
||||||
|
* @property {function} onClick The function to be called when the link is clicked
|
||||||
|
* @property {string} cssClass A CSS class name to style the link
|
||||||
|
* @property {string} text The text to be displayed for the link
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {object} NotificationOptions
|
||||||
|
* @property {number} [autoDismissTimeout] Milliseconds to wait before automatically dismissing the notification
|
||||||
|
* @property {NotificationLink} [link] A link for the notification
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A representation of a banner notification. Banner notifications
|
* A representation of a banner notification. Banner notifications
|
||||||
@@ -40,13 +64,17 @@ import EventEmitter from 'EventEmitter';
|
|||||||
* dialogs so that the same information can be provided in a dialog
|
* dialogs so that the same information can be provided in a dialog
|
||||||
* and then minimized to a banner notification if needed, or vice-versa.
|
* and then minimized to a banner notification if needed, or vice-versa.
|
||||||
*
|
*
|
||||||
|
* @see DialogModel
|
||||||
* @typedef {object} NotificationModel
|
* @typedef {object} NotificationModel
|
||||||
* @property {string} message The message to be displayed by the notification
|
* @property {string} message The message to be displayed by the notification
|
||||||
* @property {number | 'unknown'} [progress] The progress of some ongoing task. Should be a number between 0 and 100, or
|
* @property {number | 'unknown'} [progress] The progress of some ongoing task. Should be a number between 0 and 100, or
|
||||||
* with the string literal 'unknown'.
|
* with the string literal 'unknown'.
|
||||||
* @property {string} [progressText] A message conveying progress of some ongoing task.
|
* @property {string} [progressText] A message conveying progress of some ongoing task.
|
||||||
|
* @property {string} [severity] The severity of the notification. Should be one of 'info', 'alert', or 'error'.
|
||||||
* @see DialogModel
|
* @property {string} [timestamp] The time at which the notification was created. Should be a string in ISO 8601 format.
|
||||||
|
* @property {boolean} [minimized] Whether or not the notification has been minimized
|
||||||
|
* @property {boolean} [autoDismiss] Whether the notification should be automatically dismissed after a short period of time.
|
||||||
|
* @property {NotificationOptions} options The notification options
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const DEFAULT_AUTO_DISMISS_TIMEOUT = 3000;
|
const DEFAULT_AUTO_DISMISS_TIMEOUT = 3000;
|
||||||
@@ -55,18 +83,19 @@ const MINIMIZE_ANIMATION_TIMEOUT = 300;
|
|||||||
/**
|
/**
|
||||||
* The notification service is responsible for informing the user of
|
* The notification service is responsible for informing the user of
|
||||||
* events via the use of banner notifications.
|
* events via the use of banner notifications.
|
||||||
* @memberof ui/notification
|
*/
|
||||||
* @constructor */
|
|
||||||
|
|
||||||
export default class NotificationAPI extends EventEmitter {
|
export default class NotificationAPI extends EventEmitter {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
/** @type {Notification[]} */
|
||||||
this.notifications = [];
|
this.notifications = [];
|
||||||
|
/** @type {{severity: "info" | "alert" | "error"}} */
|
||||||
this.highest = { severity: "info" };
|
this.highest = { severity: "info" };
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* A context in which to hold the active notification and a
|
* A context in which to hold the active notification and a
|
||||||
* handle to its timeout.
|
* handle to its timeout.
|
||||||
|
* @type {Notification | undefined}
|
||||||
*/
|
*/
|
||||||
this.activeNotification = undefined;
|
this.activeNotification = undefined;
|
||||||
}
|
}
|
||||||
@@ -75,16 +104,12 @@ export default class NotificationAPI extends EventEmitter {
|
|||||||
* Info notifications are low priority informational messages for the user. They will be auto-destroy after a brief
|
* Info notifications are low priority informational messages for the user. They will be auto-destroy after a brief
|
||||||
* period of time.
|
* period of time.
|
||||||
* @param {string} message The message to display to the user
|
* @param {string} message The message to display to the user
|
||||||
* @param {Object} [options] object with following properties
|
* @param {NotificationOptions} [options] The notification options
|
||||||
* autoDismissTimeout: {number} in miliseconds to automatically dismisses notification
|
* @returns {Notification}
|
||||||
* link: {Object} Add a link to notifications for navigation
|
|
||||||
* onClick: callback function
|
|
||||||
* cssClass: css class name to add style on link
|
|
||||||
* text: text to display for link
|
|
||||||
* @returns {InfoNotification}
|
|
||||||
*/
|
*/
|
||||||
info(message, options = {}) {
|
info(message, options = {}) {
|
||||||
let notificationModel = {
|
/** @type {NotificationModel} */
|
||||||
|
const notificationModel = {
|
||||||
message: message,
|
message: message,
|
||||||
autoDismiss: true,
|
autoDismiss: true,
|
||||||
severity: "info",
|
severity: "info",
|
||||||
@@ -97,7 +122,7 @@ export default class NotificationAPI extends EventEmitter {
|
|||||||
/**
|
/**
|
||||||
* Present an alert to the user.
|
* Present an alert to the user.
|
||||||
* @param {string} message The message to display to the user.
|
* @param {string} message The message to display to the user.
|
||||||
* @param {Object} [options] object with following properties
|
* @param {NotificationOptions} [options] object with following properties
|
||||||
* autoDismissTimeout: {number} in milliseconds to automatically dismisses notification
|
* autoDismissTimeout: {number} in milliseconds to automatically dismisses notification
|
||||||
* link: {Object} Add a link to notifications for navigation
|
* link: {Object} Add a link to notifications for navigation
|
||||||
* onClick: callback function
|
* onClick: callback function
|
||||||
@@ -106,7 +131,7 @@ export default class NotificationAPI extends EventEmitter {
|
|||||||
* @returns {Notification}
|
* @returns {Notification}
|
||||||
*/
|
*/
|
||||||
alert(message, options = {}) {
|
alert(message, options = {}) {
|
||||||
let notificationModel = {
|
const notificationModel = {
|
||||||
message: message,
|
message: message,
|
||||||
severity: "alert",
|
severity: "alert",
|
||||||
options
|
options
|
||||||
@@ -147,7 +172,8 @@ export default class NotificationAPI extends EventEmitter {
|
|||||||
message: message,
|
message: message,
|
||||||
progressPerc: progressPerc,
|
progressPerc: progressPerc,
|
||||||
progressText: progressText,
|
progressText: progressText,
|
||||||
severity: "info"
|
severity: "info",
|
||||||
|
options: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
return this._notify(notificationModel);
|
return this._notify(notificationModel);
|
||||||
@@ -165,8 +191,13 @@ export default class NotificationAPI extends EventEmitter {
|
|||||||
* dismissed.
|
* dismissed.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
* @param {Notification | undefined} notification
|
||||||
*/
|
*/
|
||||||
_minimize(notification) {
|
_minimize(notification) {
|
||||||
|
if (!notification) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//Check this is a known notification
|
//Check this is a known notification
|
||||||
let index = this.notifications.indexOf(notification);
|
let index = this.notifications.indexOf(notification);
|
||||||
|
|
||||||
@@ -204,8 +235,13 @@ export default class NotificationAPI extends EventEmitter {
|
|||||||
* dismiss
|
* dismiss
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
* @param {Notification | undefined} notification
|
||||||
*/
|
*/
|
||||||
_dismiss(notification) {
|
_dismiss(notification) {
|
||||||
|
if (!notification) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//Check this is a known notification
|
//Check this is a known notification
|
||||||
let index = this.notifications.indexOf(notification);
|
let index = this.notifications.indexOf(notification);
|
||||||
|
|
||||||
@@ -236,10 +272,11 @@ export default class NotificationAPI extends EventEmitter {
|
|||||||
* dismiss or minimize where appropriate.
|
* dismiss or minimize where appropriate.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
* @param {Notification | undefined} notification
|
||||||
*/
|
*/
|
||||||
_dismissOrMinimize(notification) {
|
_dismissOrMinimize(notification) {
|
||||||
let model = notification.model;
|
let model = notification?.model;
|
||||||
if (model.severity === "info") {
|
if (model?.severity === "info") {
|
||||||
this._dismiss(notification);
|
this._dismiss(notification);
|
||||||
} else {
|
} else {
|
||||||
this._minimize(notification);
|
this._minimize(notification);
|
||||||
@@ -251,10 +288,11 @@ export default class NotificationAPI extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
_setHighestSeverity() {
|
_setHighestSeverity() {
|
||||||
let severity = {
|
let severity = {
|
||||||
"info": 1,
|
info: 1,
|
||||||
"alert": 2,
|
alert: 2,
|
||||||
"error": 3
|
error: 3
|
||||||
};
|
};
|
||||||
|
|
||||||
this.highest.severity = this.notifications.reduce((previous, notification) => {
|
this.highest.severity = this.notifications.reduce((previous, notification) => {
|
||||||
if (severity[notification.model.severity] > severity[previous]) {
|
if (severity[notification.model.severity] > severity[previous]) {
|
||||||
return notification.model.severity;
|
return notification.model.severity;
|
||||||
@@ -312,8 +350,11 @@ export default class NotificationAPI extends EventEmitter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
|
* @param {NotificationModel} notificationModel
|
||||||
|
* @returns {Notification}
|
||||||
*/
|
*/
|
||||||
_createNotification(notificationModel) {
|
_createNotification(notificationModel) {
|
||||||
|
/** @type {Notification} */
|
||||||
let notification = new EventEmitter();
|
let notification = new EventEmitter();
|
||||||
notification.model = notificationModel;
|
notification.model = notificationModel;
|
||||||
notification.dismiss = () => {
|
notification.dismiss = () => {
|
||||||
@@ -333,6 +374,7 @@ export default class NotificationAPI extends EventEmitter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
|
* @param {Notification | undefined} notification
|
||||||
*/
|
*/
|
||||||
_setActiveNotification(notification) {
|
_setActiveNotification(notification) {
|
||||||
this.activeNotification = notification;
|
this.activeNotification = notification;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
* this source code distribution or the Licensing information page available
|
* this source code distribution or the Licensing information page available
|
||||||
* at runtime from the About dialog for additional information.
|
* at runtime from the About dialog for additional information.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
const DEFAULT_INTERCEPTOR_PRIORITY = 0;
|
||||||
export default class InterceptorRegistry {
|
export default class InterceptorRegistry {
|
||||||
/**
|
/**
|
||||||
* A InterceptorRegistry maintains the definitions for different interceptors that may be invoked on domain objects.
|
* A InterceptorRegistry maintains the definitions for different interceptors that may be invoked on domain objects.
|
||||||
@@ -45,7 +46,6 @@ export default class InterceptorRegistry {
|
|||||||
* @memberof module:openmct.InterceptorRegistry#
|
* @memberof module:openmct.InterceptorRegistry#
|
||||||
*/
|
*/
|
||||||
addInterceptor(interceptorDef) {
|
addInterceptor(interceptorDef) {
|
||||||
//TODO: sort by priority
|
|
||||||
this.interceptors.push(interceptorDef);
|
this.interceptors.push(interceptorDef);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,10 +56,18 @@ export default class InterceptorRegistry {
|
|||||||
* @memberof module:openmct.InterceptorRegistry#
|
* @memberof module:openmct.InterceptorRegistry#
|
||||||
*/
|
*/
|
||||||
getInterceptors(identifier, object) {
|
getInterceptors(identifier, object) {
|
||||||
|
|
||||||
|
function byPriority(interceptorA, interceptorB) {
|
||||||
|
let priorityA = interceptorA.priority ?? DEFAULT_INTERCEPTOR_PRIORITY;
|
||||||
|
let priorityB = interceptorB.priority ?? DEFAULT_INTERCEPTOR_PRIORITY;
|
||||||
|
|
||||||
|
return priorityB - priorityA;
|
||||||
|
}
|
||||||
|
|
||||||
return this.interceptors.filter(interceptor => {
|
return this.interceptors.filter(interceptor => {
|
||||||
return typeof interceptor.appliesTo === 'function'
|
return typeof interceptor.appliesTo === 'function'
|
||||||
&& interceptor.appliesTo(identifier, object);
|
&& interceptor.appliesTo(identifier, object);
|
||||||
});
|
}).sort(byPriority);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,11 +75,7 @@ class MutableDomainObject {
|
|||||||
return eventOff;
|
return eventOff;
|
||||||
}
|
}
|
||||||
$set(path, value) {
|
$set(path, value) {
|
||||||
_.set(this, path, value);
|
MutableDomainObject.mutateObject(this, path, value);
|
||||||
|
|
||||||
if (path !== 'persisted' && path !== 'modified') {
|
|
||||||
_.set(this, 'modified', Date.now());
|
|
||||||
}
|
|
||||||
|
|
||||||
//Emit secret synchronization event first, so that all objects are in sync before subsequent events fired.
|
//Emit secret synchronization event first, so that all objects are in sync before subsequent events fired.
|
||||||
this._globalEventEmitter.emit(qualifiedEventName(this, '$_synchronize_model'), this);
|
this._globalEventEmitter.emit(qualifiedEventName(this, '$_synchronize_model'), this);
|
||||||
@@ -136,8 +132,11 @@ class MutableDomainObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static mutateObject(object, path, value) {
|
static mutateObject(object, path, value) {
|
||||||
|
if (path !== 'persisted') {
|
||||||
|
_.set(object, 'modified', Date.now());
|
||||||
|
}
|
||||||
|
|
||||||
_.set(object, path, value);
|
_.set(object, path, value);
|
||||||
_.set(object, 'modified', Date.now());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import InMemorySearchProvider from './InMemorySearchProvider';
|
|||||||
/**
|
/**
|
||||||
* Uniquely identifies a domain object.
|
* Uniquely identifies a domain object.
|
||||||
*
|
*
|
||||||
* @typedef Identifier
|
* @typedef {object} Identifier
|
||||||
* @property {string} namespace the namespace to/from which this domain
|
* @property {string} namespace the namespace to/from which this domain
|
||||||
* object should be loaded/stored.
|
* object should be loaded/stored.
|
||||||
* @property {string} key a unique identifier for the domain object
|
* @property {string} key a unique identifier for the domain object
|
||||||
@@ -50,8 +50,8 @@ import InMemorySearchProvider from './InMemorySearchProvider';
|
|||||||
* A few common properties are defined for domain objects. Beyond these,
|
* A few common properties are defined for domain objects. Beyond these,
|
||||||
* individual types of domain objects may add more as they see fit.
|
* individual types of domain objects may add more as they see fit.
|
||||||
*
|
*
|
||||||
* @typedef DomainObject
|
* @typedef {object} DomainObject
|
||||||
* @property {module:openmct.ObjectAPI~Identifier} identifier a key/namespace pair which
|
* @property {Identifier} identifier a key/namespace pair which
|
||||||
* uniquely identifies this domain object
|
* uniquely identifies this domain object
|
||||||
* @property {string} type the type of domain object
|
* @property {string} type the type of domain object
|
||||||
* @property {string} name the human-readable name for this domain object
|
* @property {string} name the human-readable name for this domain object
|
||||||
@@ -59,19 +59,19 @@ import InMemorySearchProvider from './InMemorySearchProvider';
|
|||||||
* object
|
* object
|
||||||
* @property {number} [modified] the time, in milliseconds since the UNIX
|
* @property {number} [modified] the time, in milliseconds since the UNIX
|
||||||
* epoch, at which this domain object was last modified
|
* epoch, at which this domain object was last modified
|
||||||
* @property {module:openmct.ObjectAPI~Identifier[]} [composition] if
|
* @property {Identifier[]} [composition] if
|
||||||
* present, this will be used by the default composition provider
|
* present, this will be used by the default composition provider
|
||||||
* to load domain objects
|
* to load domain objects
|
||||||
* @memberof module:openmct
|
* @memberof module:openmct.ObjectAPI~
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @readonly
|
* @readonly
|
||||||
* @enum {String} SEARCH_TYPES
|
* @enum {string} SEARCH_TYPES
|
||||||
* @property {String} OBJECTS Search for objects
|
* @property {string} OBJECTS Search for objects
|
||||||
* @property {String} ANNOTATIONS Search for annotations
|
* @property {string} ANNOTATIONS Search for annotations
|
||||||
* @property {String} TAGS Search for tags
|
* @property {string} TAGS Search for tags
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilities for loading, saving, and manipulating domain objects.
|
* Utilities for loading, saving, and manipulating domain objects.
|
||||||
@@ -96,7 +96,7 @@ export default class ObjectAPI {
|
|||||||
this.cache = {};
|
this.cache = {};
|
||||||
this.interceptorRegistry = new InterceptorRegistry();
|
this.interceptorRegistry = new InterceptorRegistry();
|
||||||
|
|
||||||
this.SYNCHRONIZED_OBJECT_TYPES = ['notebook', 'plan', 'annotation'];
|
this.SYNCHRONIZED_OBJECT_TYPES = ['notebook', 'restricted-notebook', 'plan', 'annotation'];
|
||||||
|
|
||||||
this.errors = {
|
this.errors = {
|
||||||
Conflict: ConflictError
|
Conflict: ConflictError
|
||||||
@@ -189,34 +189,36 @@ export default class ObjectAPI {
|
|||||||
/**
|
/**
|
||||||
* Get a domain object.
|
* Get a domain object.
|
||||||
*
|
*
|
||||||
* @method get
|
|
||||||
* @memberof module:openmct.ObjectProvider#
|
|
||||||
* @param {string} key the key for the domain object to load
|
* @param {string} key the key for the domain object to load
|
||||||
* @param {AbortController.signal} abortSignal (optional) signal to abort fetch requests
|
* @param {AbortSignal} abortSignal (optional) signal to abort fetch requests
|
||||||
* @returns {Promise} a promise which will resolve when the domain object
|
* @param {boolean} [forceRemote=false] defaults to false. If true, will skip cached and
|
||||||
|
* dirty/in-transaction objects use and the provider.get method
|
||||||
|
* @returns {Promise<DomainObject>} a promise which will resolve when the domain object
|
||||||
* has been saved, or be rejected if it cannot be saved
|
* has been saved, or be rejected if it cannot be saved
|
||||||
*/
|
*/
|
||||||
get(identifier, abortSignal) {
|
get(identifier, abortSignal, forceRemote = false) {
|
||||||
let keystring = this.makeKeyString(identifier);
|
let keystring = this.makeKeyString(identifier);
|
||||||
|
|
||||||
if (this.cache[keystring] !== undefined) {
|
if (!forceRemote) {
|
||||||
return this.cache[keystring];
|
if (this.cache[keystring] !== undefined) {
|
||||||
}
|
return this.cache[keystring];
|
||||||
|
}
|
||||||
|
|
||||||
identifier = utils.parseKeyString(identifier);
|
identifier = utils.parseKeyString(identifier);
|
||||||
let dirtyObject;
|
|
||||||
if (this.isTransactionActive()) {
|
|
||||||
dirtyObject = this.transaction.getDirtyObject(identifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dirtyObject) {
|
if (this.isTransactionActive()) {
|
||||||
return Promise.resolve(dirtyObject);
|
let dirtyObject = this.transaction.getDirtyObject(identifier);
|
||||||
|
|
||||||
|
if (dirtyObject) {
|
||||||
|
return Promise.resolve(dirtyObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const provider = this.getProvider(identifier);
|
const provider = this.getProvider(identifier);
|
||||||
|
|
||||||
if (!provider) {
|
if (!provider) {
|
||||||
throw new Error('No Provider Matched');
|
throw new Error(`No Provider Matched for keyString "${this.makeKeyString(identifier)}}"`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!provider.get) {
|
if (!provider.get) {
|
||||||
@@ -354,53 +356,96 @@ export default class ObjectAPI {
|
|||||||
* @returns {Promise} a promise which will resolve when the domain object
|
* @returns {Promise} a promise which will resolve when the domain object
|
||||||
* has been saved, or be rejected if it cannot be saved
|
* has been saved, or be rejected if it cannot be saved
|
||||||
*/
|
*/
|
||||||
save(domainObject) {
|
async save(domainObject) {
|
||||||
let provider = this.getProvider(domainObject.identifier);
|
const provider = this.getProvider(domainObject.identifier);
|
||||||
let savedResolve;
|
|
||||||
let savedReject;
|
|
||||||
let result;
|
let result;
|
||||||
|
let lastPersistedTime;
|
||||||
|
|
||||||
if (!this.isPersistable(domainObject.identifier)) {
|
if (!this.isPersistable(domainObject.identifier)) {
|
||||||
result = Promise.reject('Object provider does not support saving');
|
result = Promise.reject('Object provider does not support saving');
|
||||||
} else if (this.#hasAlreadyBeenPersisted(domainObject)) {
|
} else if (this.#hasAlreadyBeenPersisted(domainObject)) {
|
||||||
result = Promise.resolve(true);
|
result = Promise.resolve(true);
|
||||||
} else {
|
} else {
|
||||||
const persistedTime = Date.now();
|
const username = await this.#getCurrentUsername();
|
||||||
if (domainObject.persisted === undefined) {
|
const isNewObject = domainObject.persisted === undefined;
|
||||||
result = new Promise((resolve, reject) => {
|
let savedResolve;
|
||||||
savedResolve = resolve;
|
let savedReject;
|
||||||
savedReject = reject;
|
let savedObjectPromise;
|
||||||
});
|
|
||||||
domainObject.persisted = persistedTime;
|
result = new Promise((resolve, reject) => {
|
||||||
const newObjectPromise = provider.create(domainObject);
|
savedResolve = resolve;
|
||||||
if (newObjectPromise) {
|
savedReject = reject;
|
||||||
newObjectPromise.then(response => {
|
});
|
||||||
this.mutate(domainObject, 'persisted', persistedTime);
|
|
||||||
savedResolve(response);
|
this.#mutate(domainObject, 'modifiedBy', username);
|
||||||
}).catch((error) => {
|
|
||||||
savedReject(error);
|
if (isNewObject) {
|
||||||
});
|
this.#mutate(domainObject, 'createdBy', username);
|
||||||
} else {
|
|
||||||
result = Promise.reject(`[ObjectAPI][save] Object provider returned ${newObjectPromise} when creating new object.`);
|
const createdTime = Date.now();
|
||||||
}
|
this.#mutate(domainObject, 'created', createdTime);
|
||||||
|
|
||||||
|
const persistedTime = Date.now();
|
||||||
|
this.#mutate(domainObject, 'persisted', persistedTime);
|
||||||
|
|
||||||
|
savedObjectPromise = provider.create(domainObject);
|
||||||
} else {
|
} else {
|
||||||
domainObject.persisted = persistedTime;
|
lastPersistedTime = domainObject.persisted;
|
||||||
this.mutate(domainObject, 'persisted', persistedTime);
|
const persistedTime = Date.now();
|
||||||
result = provider.update(domainObject);
|
this.#mutate(domainObject, 'persisted', persistedTime);
|
||||||
|
savedObjectPromise = provider.update(domainObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (savedObjectPromise) {
|
||||||
|
savedObjectPromise.then(response => {
|
||||||
|
savedResolve(response);
|
||||||
|
}).catch((error) => {
|
||||||
|
if (!isNewObject) {
|
||||||
|
this.#mutate(domainObject, 'persisted', lastPersistedTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
savedReject(error);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
result = Promise.reject(`[ObjectAPI][save] Object provider returned ${savedObjectPromise} when ${isNewObject ? 'creating new' : 'updating'} object.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.catch((error) => {
|
return result.catch(async (error) => {
|
||||||
if (error instanceof this.errors.Conflict) {
|
if (error instanceof this.errors.Conflict) {
|
||||||
this.openmct.notifications.error(`Conflict detected while saving ${this.makeKeyString(domainObject.identifier)}`);
|
// Synchronized objects will resolve their own conflicts
|
||||||
|
if (this.SYNCHRONIZED_OBJECT_TYPES.includes(domainObject.type)) {
|
||||||
|
this.openmct.notifications.info(`Conflict detected while saving "${this.makeKeyString(domainObject.name)}", attempting to resolve`);
|
||||||
|
} else {
|
||||||
|
this.openmct.notifications.error(`Conflict detected while saving ${this.makeKeyString(domainObject.identifier)}`);
|
||||||
|
|
||||||
|
if (this.isTransactionActive()) {
|
||||||
|
this.endTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.refresh(domainObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async #getCurrentUsername() {
|
||||||
|
const user = await this.openmct.user.getCurrentUser();
|
||||||
|
let username;
|
||||||
|
|
||||||
|
if (user !== undefined) {
|
||||||
|
username = user.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* After entering into edit mode, creates a new instance of Transaction to keep track of changes in Objects
|
* After entering into edit mode, creates a new instance of Transaction to keep track of changes in Objects
|
||||||
|
*
|
||||||
|
* @returns {Transaction} a new Transaction that was just created
|
||||||
*/
|
*/
|
||||||
startTransaction() {
|
startTransaction() {
|
||||||
if (this.isTransactionActive()) {
|
if (this.isTransactionActive()) {
|
||||||
@@ -408,6 +453,8 @@ export default class ObjectAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.transaction = new Transaction(this);
|
this.transaction = new Transaction(this);
|
||||||
|
|
||||||
|
return this.transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -480,14 +527,16 @@ export default class ObjectAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modify a domain object.
|
* Modify a domain object. Internal to ObjectAPI, won't call save after.
|
||||||
|
* @private
|
||||||
|
*
|
||||||
* @param {module:openmct.DomainObject} object the object to mutate
|
* @param {module:openmct.DomainObject} object the object to mutate
|
||||||
* @param {string} path the property to modify
|
* @param {string} path the property to modify
|
||||||
* @param {*} value the new value for this property
|
* @param {*} value the new value for this property
|
||||||
* @method mutate
|
* @method mutate
|
||||||
* @memberof module:openmct.ObjectAPI#
|
* @memberof module:openmct.ObjectAPI#
|
||||||
*/
|
*/
|
||||||
mutate(domainObject, path, value) {
|
#mutate(domainObject, path, value) {
|
||||||
if (!this.supportsMutation(domainObject.identifier)) {
|
if (!this.supportsMutation(domainObject.identifier)) {
|
||||||
throw `Error: Attempted to mutate immutable object ${domainObject.name}`;
|
throw `Error: Attempted to mutate immutable object ${domainObject.name}`;
|
||||||
}
|
}
|
||||||
@@ -508,6 +557,18 @@ export default class ObjectAPI {
|
|||||||
//Destroy temporary mutable object
|
//Destroy temporary mutable object
|
||||||
this.destroyMutable(mutableDomainObject);
|
this.destroyMutable(mutableDomainObject);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modify a domain object and save.
|
||||||
|
* @param {module:openmct.DomainObject} object the object to mutate
|
||||||
|
* @param {string} path the property to modify
|
||||||
|
* @param {*} value the new value for this property
|
||||||
|
* @method mutate
|
||||||
|
* @memberof module:openmct.ObjectAPI#
|
||||||
|
*/
|
||||||
|
mutate(domainObject, path, value) {
|
||||||
|
this.#mutate(domainObject, path, value);
|
||||||
|
|
||||||
if (this.isTransactionActive()) {
|
if (this.isTransactionActive()) {
|
||||||
this.transaction.add(domainObject);
|
this.transaction.add(domainObject);
|
||||||
@@ -677,6 +738,46 @@ export default class ObjectAPI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse and construct an `objectPath` from a `navigationPath`.
|
||||||
|
*
|
||||||
|
* A `navigationPath` is a string of the form `"/browse/<keyString>/<keyString>/..."` that is used
|
||||||
|
* by the Open MCT router to navigate to a specific object.
|
||||||
|
*
|
||||||
|
* Throws an error if the `navigationPath` is malformed.
|
||||||
|
*
|
||||||
|
* @param {string} navigationPath
|
||||||
|
* @returns {DomainObject[]} objectPath
|
||||||
|
*/
|
||||||
|
async getRelativeObjectPath(navigationPath) {
|
||||||
|
if (!navigationPath.startsWith('/browse/')) {
|
||||||
|
throw new Error(`Malformed navigation path: "${navigationPath}"`);
|
||||||
|
}
|
||||||
|
|
||||||
|
navigationPath = navigationPath.replace('/browse/', '');
|
||||||
|
|
||||||
|
if (!navigationPath || navigationPath === '/') {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove any query params and split on '/'
|
||||||
|
const keyStrings = navigationPath.split('?')?.[0].split('/');
|
||||||
|
|
||||||
|
if (keyStrings[0] !== 'ROOT') {
|
||||||
|
keyStrings.unshift('ROOT');
|
||||||
|
}
|
||||||
|
|
||||||
|
const objectPath = (await Promise.all(
|
||||||
|
keyStrings.map(
|
||||||
|
keyString => this.supportsMutation(keyString)
|
||||||
|
? this.getMutable(utils.parseKeyString(keyString))
|
||||||
|
: this.get(utils.parseKeyString(keyString))
|
||||||
|
)
|
||||||
|
)).reverse();
|
||||||
|
|
||||||
|
return objectPath;
|
||||||
|
}
|
||||||
|
|
||||||
isObjectPathToALink(domainObject, objectPath) {
|
isObjectPathToALink(domainObject, objectPath) {
|
||||||
return objectPath !== undefined
|
return objectPath !== undefined
|
||||||
&& objectPath.length > 1
|
&& objectPath.length > 1
|
||||||
@@ -684,7 +785,7 @@ export default class ObjectAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isTransactionActive() {
|
isTransactionActive() {
|
||||||
return Boolean(this.transaction && this.openmct.editor.isEditing());
|
return this.transaction !== undefined && this.transaction !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
#hasAlreadyBeenPersisted(domainObject) {
|
#hasAlreadyBeenPersisted(domainObject) {
|
||||||
|
|||||||
@@ -8,13 +8,27 @@ describe("The Object API", () => {
|
|||||||
let mockDomainObject;
|
let mockDomainObject;
|
||||||
const TEST_NAMESPACE = "test-namespace";
|
const TEST_NAMESPACE = "test-namespace";
|
||||||
const TEST_KEY = "test-key";
|
const TEST_KEY = "test-key";
|
||||||
|
const USERNAME = 'Joan Q Public';
|
||||||
const FIFTEEN_MINUTES = 15 * 60 * 1000;
|
const FIFTEEN_MINUTES = 15 * 60 * 1000;
|
||||||
|
|
||||||
beforeEach((done) => {
|
beforeEach((done) => {
|
||||||
typeRegistry = jasmine.createSpyObj('typeRegistry', [
|
typeRegistry = jasmine.createSpyObj('typeRegistry', [
|
||||||
'get'
|
'get'
|
||||||
]);
|
]);
|
||||||
|
const userProvider = {
|
||||||
|
isLoggedIn() {
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
getCurrentUser() {
|
||||||
|
return Promise.resolve({
|
||||||
|
getName() {
|
||||||
|
return USERNAME;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
openmct = createOpenMct();
|
openmct = createOpenMct();
|
||||||
|
openmct.user.setProvider(userProvider);
|
||||||
objectAPI = openmct.objects;
|
objectAPI = openmct.objects;
|
||||||
|
|
||||||
openmct.editor = {};
|
openmct.editor = {};
|
||||||
@@ -63,19 +77,63 @@ describe("The Object API", () => {
|
|||||||
mockProvider.update.and.returnValue(Promise.resolve(true));
|
mockProvider.update.and.returnValue(Promise.resolve(true));
|
||||||
objectAPI.addProvider(TEST_NAMESPACE, mockProvider);
|
objectAPI.addProvider(TEST_NAMESPACE, mockProvider);
|
||||||
});
|
});
|
||||||
it("Calls 'create' on provider if object is new", () => {
|
it("Adds a 'created' timestamp to new objects", async () => {
|
||||||
objectAPI.save(mockDomainObject);
|
await objectAPI.save(mockDomainObject);
|
||||||
|
expect(mockDomainObject.created).not.toBeUndefined();
|
||||||
|
});
|
||||||
|
it("Calls 'create' on provider if object is new", async () => {
|
||||||
|
await objectAPI.save(mockDomainObject);
|
||||||
expect(mockProvider.create).toHaveBeenCalled();
|
expect(mockProvider.create).toHaveBeenCalled();
|
||||||
expect(mockProvider.update).not.toHaveBeenCalled();
|
expect(mockProvider.update).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
it("Calls 'update' on provider if object is not new", () => {
|
it("Calls 'update' on provider if object is not new", async () => {
|
||||||
mockDomainObject.persisted = Date.now() - FIFTEEN_MINUTES;
|
mockDomainObject.persisted = Date.now() - FIFTEEN_MINUTES;
|
||||||
mockDomainObject.modified = Date.now();
|
mockDomainObject.modified = Date.now();
|
||||||
|
|
||||||
objectAPI.save(mockDomainObject);
|
await objectAPI.save(mockDomainObject);
|
||||||
expect(mockProvider.create).not.toHaveBeenCalled();
|
expect(mockProvider.create).not.toHaveBeenCalled();
|
||||||
expect(mockProvider.update).toHaveBeenCalled();
|
expect(mockProvider.update).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
describe("the persisted timestamp for existing objects", () => {
|
||||||
|
let persistedTimestamp;
|
||||||
|
beforeEach(() => {
|
||||||
|
persistedTimestamp = Date.now() - FIFTEEN_MINUTES;
|
||||||
|
mockDomainObject.persisted = persistedTimestamp;
|
||||||
|
mockDomainObject.modified = Date.now();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("is updated", async () => {
|
||||||
|
await objectAPI.save(mockDomainObject);
|
||||||
|
expect(mockDomainObject.persisted).toBeDefined();
|
||||||
|
expect(mockDomainObject.persisted > persistedTimestamp).toBe(true);
|
||||||
|
});
|
||||||
|
it("is >= modified timestamp", async () => {
|
||||||
|
await objectAPI.save(mockDomainObject);
|
||||||
|
expect(mockDomainObject.persisted >= mockDomainObject.modified).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe("the persisted timestamp for new objects", () => {
|
||||||
|
it("is updated", async () => {
|
||||||
|
await objectAPI.save(mockDomainObject);
|
||||||
|
expect(mockDomainObject.persisted).toBeDefined();
|
||||||
|
});
|
||||||
|
it("is >= modified timestamp", async () => {
|
||||||
|
await objectAPI.save(mockDomainObject);
|
||||||
|
expect(mockDomainObject.persisted >= mockDomainObject.modified).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Sets the current user for 'createdBy' on new objects", async () => {
|
||||||
|
await objectAPI.save(mockDomainObject);
|
||||||
|
expect(mockDomainObject.createdBy).toBe(USERNAME);
|
||||||
|
});
|
||||||
|
it("Sets the current user for 'modifedBy' on existing objects", async () => {
|
||||||
|
mockDomainObject.persisted = Date.now() - FIFTEEN_MINUTES;
|
||||||
|
mockDomainObject.modified = Date.now();
|
||||||
|
|
||||||
|
await objectAPI.save(mockDomainObject);
|
||||||
|
expect(mockDomainObject.modifiedBy).toBe(USERNAME);
|
||||||
|
});
|
||||||
|
|
||||||
it("Does not persist if the object is unchanged", () => {
|
it("Does not persist if the object is unchanged", () => {
|
||||||
mockDomainObject.persisted =
|
mockDomainObject.persisted =
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class Overlay extends EventEmitter {
|
|||||||
dismissable = true,
|
dismissable = true,
|
||||||
element,
|
element,
|
||||||
onDestroy,
|
onDestroy,
|
||||||
|
onDismiss,
|
||||||
size
|
size
|
||||||
} = {}) {
|
} = {}) {
|
||||||
super();
|
super();
|
||||||
@@ -32,7 +33,7 @@ class Overlay extends EventEmitter {
|
|||||||
OverlayComponent: OverlayComponent
|
OverlayComponent: OverlayComponent
|
||||||
},
|
},
|
||||||
provide: {
|
provide: {
|
||||||
dismiss: this.dismiss.bind(this),
|
dismiss: this.notifyAndDismiss.bind(this),
|
||||||
element,
|
element,
|
||||||
buttons,
|
buttons,
|
||||||
dismissable: this.dismissable
|
dismissable: this.dismissable
|
||||||
@@ -43,6 +44,10 @@ class Overlay extends EventEmitter {
|
|||||||
if (onDestroy) {
|
if (onDestroy) {
|
||||||
this.once('destroy', onDestroy);
|
this.once('destroy', onDestroy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (onDismiss) {
|
||||||
|
this.once('dismiss', onDismiss);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dismiss() {
|
dismiss() {
|
||||||
@@ -51,6 +56,12 @@ class Overlay extends EventEmitter {
|
|||||||
this.component.$destroy();
|
this.component.$destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Ensures that any callers are notified that the overlay is dismissed
|
||||||
|
notifyAndDismiss() {
|
||||||
|
this.emit('dismiss');
|
||||||
|
this.dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
**/
|
**/
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ class OverlayAPI {
|
|||||||
dismissLastOverlay() {
|
dismissLastOverlay() {
|
||||||
let lastOverlay = this.activeOverlays[this.activeOverlays.length - 1];
|
let lastOverlay = this.activeOverlays[this.activeOverlays.length - 1];
|
||||||
if (lastOverlay && lastOverlay.dismissable) {
|
if (lastOverlay && lastOverlay.dismissable) {
|
||||||
lastOverlay.dismiss();
|
lastOverlay.notifyAndDismiss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||