Skip to content
Snippets Groups Projects
Commit f92aebe6 authored by Reinder Kraaij's avatar Reinder Kraaij :eye:
Browse files

Merge branch 'TMSS-2810---GetFields-Tests' into 'master'

TMSS-2810 "Multiple TMSS FrontEnd Unit tests Fixed"

See merge request !1188
parents b7e29cc0 649c73ce
No related branches found
No related tags found
1 merge request!1188TMSS-2810 "Multiple TMSS FrontEnd Unit tests Fixed"
Showing
with 20008 additions and 18744 deletions
......@@ -408,6 +408,7 @@ integration_test_TMSS_Frontend:
artifacts:
name: front-end-junit-report
when: always
expire_in: never
paths:
- build/gnucxx11_opt/SAS/TMSS/frontend/tmss_webapp/coverage/
reports:
......@@ -944,6 +945,31 @@ sonarcloud_check_TMSS_Frontend:
- ls -al build/gnucxx11_opt/SAS/TMSS/frontend/tmss_webapp/coverage
- sonar-scanner -Dproject.settings=SAS/TMSS/frontend/tmss_webapp/sonar-project.properties
eslint_TMSSFrontEnd:
stage: quality-control
image: ci_tmss:$CI_COMMIT_SHORT_SHA
allow_failure: true
script:
- echo "Eslinting TMSS FrontEnd..."
- cd /builds/ro/lofar/SAS/TMSS/frontend/tmss_webapp
- npm install
- npx eslint --format gitlab . || true
- ls -al
- echo "done"
needs:
- prepare_ci_tmss_docker_image
artifacts:
name: front-end-json-eslint-quality-report
when: always
expire_in: never
reports:
codequality: gl-codequality.json
package_check_TMSS_Frontend:
stage: quality-control
image: ci_tmss:$CI_COMMIT_SHORT_SHA
......
module.exports = {
"env": {
"browser": true,
"es2021": true,
"node": true,
"jasmine": true,
"jest": true,
"es6": true,
},
"extends": ["eslint:recommended", "plugin:react/recommended"],
"plugins": [
"react"
],
"parserOptions": {
"parser": "@babel/eslint-parser",
"ecmaVersion": "latest",
"sourceType": "module",
},
"rules": {
"react/prop-types": "off",
"react/react-in-jsx-scope": "off",
"react/jsx-uses-react": "off",
"react/boolean-prop-naming": "warn",
"react/button-has-type": "warn",
"react/default-props-match-prop-types": "warn",
"react/destructuring-assignment": "warn",
"react/display-name": "warn",
"react/forbid-component-props": "warn",
"react/forbid-dom-props": "warn",
"react/forbid-elements": "warn",
"react/forbid-prop-types": "warn",
"react/forbid-foreign-prop-types": "warn",
"react/no-access-state-in-setstate": "warn",
"react/no-array-index-key": "warn",
"react/no-children-prop": "warn",
"react/no-danger": "warn",
"react/no-danger-with-children": "warn",
"react/no-deprecated": "warn",
"react/no-did-mount-set-state": "warn",
"react/no-did-update-set-state": "warn",
"react/no-direct-mutation-state": "warn",
"react/no-find-dom-node": "warn",
"react/no-is-mounted": "warn",
"react/no-multi-comp": "warn",
"react/no-redundant-should-component-update": "warn",
"react/no-render-return-value": "warn",
"react/no-set-state": "warn",
"react/no-typos": "warn",
"react/no-string-refs": "warn",
"react/no-this-in-sfc": "warn",
"react/no-unescaped-entities": "warn",
"react/no-unknown-property": "warn",
"react/no-unused-prop-types": "warn",
"react/no-unused-state": "warn",
"react/no-will-update-set-state": "warn",
"react/prefer-es6-class": "warn",
"react/require-default-props": "warn",
"react/require-optimization": "warn",
"react/require-render-return": "warn",
"react/self-closing-comp": "warn",
"react/sort-comp": "warn",
"react/sort-prop-types": "warn",
"react/style-prop-object": "warn",
"react/void-dom-elements-no-children": "warn",
"react/jsx-boolean-value": "warn",
"react/jsx-child-element-spacing": "warn",
"react/jsx-closing-bracket-location": "warn",
"react/jsx-closing-tag-location": "warn",
"react/jsx-curly-spacing": "warn",
"react/jsx-equals-spacing": "warn",
"react/jsx-first-prop-new-line": "warn",
"react/jsx-handler-names": "warn",
"react/jsx-indent": "warn",
"react/jsx-indent-props": "warn",
"react/jsx-key": "warn",
"react/jsx-max-depth": "warn",
"react/jsx-max-props-per-line": "warn",
"react/jsx-no-bind": "warn",
"react/jsx-no-comment-textnodes": "warn",
"react/jsx-no-duplicate-props": "warn",
"react/jsx-no-literals": "warn",
"react/jsx-no-target-blank": "warn",
"react/jsx-no-undef": "warn",
"react/jsx-one-expression-per-line": "warn",
"react/jsx-curly-brace-presence": "warn",
"react/jsx-pascal-case": "warn",
"react/jsx-props-no-multi-spaces": "warn",
"react/jsx-sort-default-props": "warn",
"react/jsx-sort-props": "warn",
"react/jsx-space-before-closing": "warn",
"react/jsx-tag-spacing": "warn",
"react/jsx-uses-vars": "warn",
"react/jsx-wrap-multilines": "warn",
// Default ESLint
"for-direction": "warn",
"getter-return": "warn",
"no-await-in-loop": "warn",
"no-compare-neg-zero": "warn",
"no-cond-assign": "warn",
"no-console": "warn",
"no-constant-condition": "warn",
"no-control-regex": "warn",
"no-debugger": "warn",
"no-dupe-args": "warn",
"no-dupe-keys": "warn",
"no-duplicate-case": "warn",
"no-empty": "warn",
"no-empty-character-class": "warn",
"no-ex-assign": "warn",
"no-extra-boolean-cast": "warn",
"no-extra-parens": "warn",
"no-extra-semi": "warn",
"no-func-assign": "warn",
"no-inner-declarations": "warn",
"no-invalid-regexp": "warn",
"no-irregular-whitespace": "warn",
"no-obj-calls": "warn",
"no-prototype-builtins": "warn",
"no-regex-spaces": "warn",
"no-sparse-arrays": "warn",
"no-template-curly-in-string": "warn",
"no-unexpected-multiline": "warn",
"no-unreachable": "warn",
"no-unsafe-finally": "warn",
"no-unsafe-negation": "warn",
"use-isnan": "warn",
"valid-jsdoc": "warn",
"valid-typeof": "warn",
"accessor-pairs": "warn",
"array-callback-return": "warn",
"block-scoped-var": "warn",
"class-methods-use-this": "warn",
"complexity": "warn",
"consistent-return": "warn",
"curly": "warn",
"default-case": "warn",
"dot-location": "warn",
"dot-notation": "warn",
"eqeqeq": "warn",
"guard-for-in": "warn",
"max-classes-per-file": "warn",
"no-alert": "warn",
"no-caller": "warn",
"no-case-declarations": "warn",
"no-div-regex": "warn",
"no-else-return": "warn",
"no-empty-function": "warn",
"no-empty-pattern": "warn",
"no-eq-null": "warn",
"no-eval": "warn",
"no-extend-native": "warn",
"no-extra-bind": "warn",
"no-extra-label": "warn",
"no-fallthrough": "warn",
"no-floating-decimal": "warn",
"no-global-assign": "warn",
"no-implicit-coercion": "warn",
"no-implicit-globals": "warn",
"no-implied-eval": "warn",
"no-invalid-this": "warn",
"no-iterator": "warn",
"no-labels": "warn",
"no-lone-blocks": "warn",
"no-loop-func": "warn",
"no-magic-numbers": "warn",
"no-multi-spaces": "warn",
"no-multi-str": "warn",
"no-new": "warn",
"no-new-func": "warn",
"no-new-wrappers": "warn",
"no-octal": "warn",
"no-octal-escape": "warn",
"no-param-reassign": "warn",
"no-proto": "warn",
"no-redeclare": "warn",
"no-restricted-properties": "warn",
"no-return-assign": "warn",
"no-return-await": "warn",
"no-script-url": "warn",
"no-self-assign": "warn",
"no-self-compare": "warn",
"no-sequences": "warn",
"no-throw-literal": "warn",
"no-unmodified-loop-condition": "warn",
"no-unused-expressions": "warn",
"no-unused-labels": "warn",
"no-useless-call": "warn",
"no-useless-concat": "warn",
"no-useless-escape": "warn",
"no-useless-return": "warn",
"no-void": "warn",
"no-warning-comments": "warn",
"no-with": "warn",
"prefer-promise-reject-errors": "warn",
"radix": "warn",
"require-await": "warn",
"vars-on-top": "warn",
"wrap-iife": "warn",
"yoda": "warn",
"strict": "warn",
"init-declarations": "warn",
"no-catch-shadow": "warn",
"no-delete-var": "warn",
"no-label-var": "warn",
"no-restricted-globals": "warn",
"no-shadow": "warn",
"no-shadow-restricted-names": "warn",
"no-undef": "warn",
"no-undef-init": "warn",
"no-undefined": "warn",
"no-unused-vars": "warn",
"no-use-before-define": "warn",
"callback-return": "warn",
"global-require": "warn",
"handle-callback-err": "warn",
"no-buffer-constructor": "warn",
"no-mixed-requires": "warn",
"no-new-require": "warn",
"no-path-concat": "warn",
"no-process-env": "warn",
"no-process-exit": "warn",
"no-restricted-modules": "warn",
"no-sync": "warn",
"array-bracket-newline": "warn",
"array-bracket-spacing": "warn",
"array-element-newline": "warn",
"block-spacing": "warn",
"brace-style": "warn",
"camelcase": "warn",
"capitalized-comments": "warn",
"comma-dangle": "warn",
"comma-spacing": "warn",
"comma-style": "warn",
"computed-property-spacing": "warn",
"consistent-this": "warn",
"eol-last": "warn",
"func-call-spacing": "warn",
"func-name-matching": "warn",
"func-names": "warn",
"func-style": "warn",
"function-paren-newline": "warn",
"id-blacklist": "warn",
"id-length": "warn",
"id-match": "warn",
"implicit-arrow-linebreak": "warn",
"indent": "warn",
"jsx-quotes": "warn",
"key-spacing": "warn",
"keyword-spacing": "warn",
"line-comment-position": "warn",
"linebreak-style": "warn",
"lines-around-comment": "warn",
"lines-between-class-members": "warn",
"max-depth": "warn",
"max-len": "warn",
"max-lines": "warn",
"max-nested-callbacks": "warn",
"max-params": "warn",
"max-statements": "warn",
"max-statements-per-line": "warn",
"multiline-comment-style": "warn",
"multiline-ternary": "warn",
"new-cap": "warn",
"new-parens": "warn",
"newline-per-chained-call": "warn",
"no-array-constructor": "warn",
"no-bitwise": "warn",
"no-continue": "warn",
"no-inline-comments": "off",
"no-lonely-if": "warn",
"no-mixed-operators": "warn",
"no-mixed-spaces-and-tabs": "warn",
"no-multi-assign": "warn",
"no-multiple-empty-lines": "warn",
"no-negated-condition": "warn",
"no-nested-ternary": "warn",
"no-new-object": "warn",
"no-plusplus": "warn",
"no-restricted-syntax": "warn",
"no-tabs": "warn",
"no-ternary": "warn",
"no-trailing-spaces": "warn",
"no-underscore-dangle": "warn",
"no-unneeded-ternary": "warn",
"no-whitespace-before-property": "warn",
"nonblock-statement-body-position": "warn",
"object-curly-newline": "warn",
"object-curly-spacing": "warn",
"object-property-newline": "warn",
"one-var": "warn",
"one-var-declaration-per-line": "warn",
"operator-assignment": "warn",
"operator-linebreak": "warn",
"padded-blocks": "warn",
"padding-line-between-statements": "warn",
"prefer-object-spread": "warn",
"quote-props": "warn",
"quotes": "warn",
"require-jsdoc": "warn",
"semi": "warn",
"semi-spacing": "warn",
"semi-style": "warn",
"sort-keys": "warn",
"sort-vars": "warn",
"space-before-blocks": "warn",
"space-before-function-paren": "warn",
"space-in-parens": "warn",
"space-infix-ops": "warn",
"space-unary-ops": "warn",
"spaced-comment": "warn",
"switch-colon-spacing": "warn",
"template-tag-spacing": "warn",
"unicode-bom": "warn",
"wrap-regex": "warn",
"arrow-body-style": "warn",
"arrow-parens": "warn",
"arrow-spacing": "warn",
"constructor-super": "warn",
"generator-star-spacing": "warn",
"no-class-assign": "warn",
"no-confusing-arrow": "warn",
"no-const-assign": "warn",
"no-dupe-class-members": "warn",
"no-duplicate-imports": "warn",
"no-new-symbol": "warn",
"no-restricted-imports": "warn",
"no-this-before-super": "warn",
"no-useless-computed-key": "warn",
"no-useless-constructor": "warn",
"no-useless-rename": "warn",
"no-var": "warn",
"object-shorthand": "warn",
"prefer-arrow-callback": "warn",
"prefer-const": "warn",
"prefer-destructuring": "warn",
"prefer-numeric-literals": "warn",
"prefer-rest-params": "warn",
"prefer-spread": "warn",
"prefer-template": "warn",
"require-yield": "warn",
"rest-spread-spacing": "warn",
"sort-imports": "warn",
"symbol-description": "warn",
"template-curly-spacing": "warn",
"yield-star-spacing": "warn",
}
}
\ No newline at end of file
This diff is collapsed.
......@@ -8,15 +8,13 @@
"@fortawesome/fontawesome-free": "^5.13.1",
"@json-editor/json-editor": "^2.10.1",
"@kevincobain2000/json-to-html-table": "^1.0.1",
"@testing-library/jest-dom": "^6.1.3",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.5.1",
"@microlink/react-json-view": "^1.22.2",
"ag-grid-community": "^24.1.0",
"ag-grid-react": "^24.1.1",
"axios": "^1.4.0",
"use-axios": "^1.0.0",
"bootstrap": "^4.5.0",
"chart.js": "^4.4.0",
"chartjs-plugin-annotation": "^3.0.1",
"cleave.js": "^1.6.0",
"flatpickr": "^4.6.13",
"font-awesome": "^4.7.0",
......@@ -24,7 +22,6 @@
"html2canvas": "^1.0.0-rc.7",
"immer": "^10.0.3",
"interactjs": "^1.10.19",
"jest-mock-console": "^2.0.0",
"jquery": "^3.7.1",
"json-schema-ref-parser": "^1.0.0-alpha.21",
"jspdf": "^2.5.1",
......@@ -34,13 +31,13 @@
"match-sorter": "^4.2.1",
"moment": "^2.29.4",
"node-polyfill-webpack-plugin": "^2.0.0",
"sass": "^1.68.0",
"npm-check-updates": "^16.10.16",
"papaparse": "^5.3.2",
"pptr-testing-library": "^0.7.0",
"primeflex": "^3.3.1",
"primeicons": "6.0.1",
"primereact": "9.6.2",
"prop-types": "^15.7.2",
"pptr-testing-library": "^0.7.0",
"puppeteer": "^18.0.5",
"react": "^18.2.0",
"react-app-polyfill": "^1.0.6",
......@@ -50,16 +47,15 @@
"react-bootstrap-datetimepicker": "0.0.22",
"react-calendar-timeline": "^0.28.0",
"react-chartjs-2": "^5.2.0",
"chartjs-plugin-annotation": "^3.0.1",
"react-dom": "^18.2.0",
"react-flatpickr": "^3.10.12",
"react-frame-component": "^4.1.2",
"react-json-to-table": "^0.1.7",
"@microlink/react-json-view": "^1.22.2",
"react-live-clock": "^6.1.14",
"react-loader-spinner": "^5.4.5",
"react-moment": "^1.1.3",
"react-redux": "^7.2.4",
"react-router-dom": "^5.2.0",
"react-scripts": "^5.0.1",
"react-table": "^7.2.1",
"react-table-plugins": "^1.3.1",
"react-to-print": "^2.12.4",
......@@ -69,49 +65,43 @@
"reactstrap": "^9.2.0",
"redux": "^4.2.1",
"replace-in-file": "^7.0.1",
"sass": "^1.68.0",
"shortcut-buttons-flatpickr": "^0.4.0",
"styled-components": "^5.1.1",
"suneditor": "^2.36.5",
"suneditor-react": "^3.6.1",
"typescript": "^3.9.5",
"yup": "^1.2.0",
"jest-canvas-mock": "^2.5.0",
"jest-expect-message": "^1.1.3",
"jest-junit": "^16.0.0",
"npm-check-updates": "^16.10.16",
"react-live-clock": "^6.1.14",
"react-moment": "^1.1.3"
"use-axios": "^1.0.0",
"yup": "^1.2.0"
},
"overrides": {
"ag-grid-react": {
"react":"^18",
"react-dom":"^18"
"react": "^18",
"react-dom": "^18"
},
"react-json-view":{
"react":"^18",
"react-dom":"^18"
"react-json-view": {
"react": "^18",
"react-dom": "^18"
},
"@microlink/react-json-view":{
"react":"^18"
"@microlink/react-json-view": {
"react": "^18"
},
"react-loader-spinner":{
"react":"^18",
"react-dom":"^18"
"react-loader-spinner": {
"react": "^18",
"react-dom": "^18"
},
"use-memo-one":{
"react":"^18"
"use-memo-one": {
"react": "^18"
},
"create-react-context":{
"react":"^18"
"create-react-context": {
"react": "^18"
},
"use-isomorphic-layout-effect":{
"react":"^18"
"use-isomorphic-layout-effect": {
"react": "^18"
},
"react-calendar-timeline":{
"react":"^18"
"react-calendar-timeline": {
"react": "^18"
}
},
"scripts": {
"preinstall": "npx npm-force-resolutions",
......@@ -143,12 +133,24 @@
},
"devDependencies": {
"@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining": "^7.17.12",
"@babel/plugin-proposal-private-property-in-object": "7.21.0-placeholder-for-preset-env.2",
"@babel/preset-env": "^7.22.4",
"@testing-library/jest-dom": "^6.1.3",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.5.1",
"babel-jest": "^29.5.0",
"babel-polyfill": "^6.26.0",
"customize-cra": "^1.0.0",
"eslint": "^8.51.0",
"eslint-formatter-gitlab": "^5.0.0",
"eslint-plugin-react": "^7.33.2",
"jest-canvas-mock": "^2.5.0",
"jest-expect-message": "^1.1.3",
"jest-junit": "^16.0.0",
"jest-mock-console": "^2.0.0",
"react-app-rewired": "^2.2.1",
"@babel/preset-env": "^7.22.4",
"babel-jest": "^29.5.0",
"@babel/plugin-proposal-private-property-in-object": "7.21.0-placeholder-for-preset-env.2"
"react-scripts": "^5.0.1",
"react-test-renderer": "^18.2.0"
},
"resolutions": {
"immer": "^9.0.12",
......
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Scheduling Unit create page default Renders with all standard service mocks 1`] = `
Array [
<div
className="page-header"
>
<div
className="title"
>
<h2
className="page-title"
>
Scheduling Unit - Add
</h2>
</div>
<div
className="page-action-menu undefined"
>
<button
className="p-link"
title="Click to close Scheduling Unit creation"
>
<i
className="fa fa-window-close undefined"
onClick={[Function]}
onMouseOver={[Function]}
/>
</button>
</div>
</div>,
<div
style={
Object {
"display": "flex",
"height": "100",
"justifyContent": "center",
"width": "100%",
}
}
>
<div
aria-busy={true}
aria-label="three-dots-loading"
data-testid="three-dots-loading"
role="status"
style={
Object {
"display": "flex",
}
}
>
<svg
data-testid="three-dots-svg"
fill="#004B93"
height={80}
viewBox="0 0 120 30"
width={80}
xmlns="http://www.w3.org/2000/svg"
>
<circle
cx="15"
cy="15"
r={15}
>
<animate
attributeName="r"
begin="0s"
calcMode="linear"
dur="0.8s"
from="15"
repeatCount="indefinite"
to="15"
values="15;9;15"
/>
<animate
attributeName="fill-opacity"
begin="0s"
calcMode="linear"
dur="0.8s"
from="1"
repeatCount="indefinite"
to="1"
values="1;.5;1"
/>
</circle>
<circle
attributeName="fill-opacity"
cx="60"
cy="15"
from="1"
r={9}
to="0.3"
>
<animate
attributeName="r"
begin="0s"
calcMode="linear"
dur="0.8s"
from="9"
repeatCount="indefinite"
to="9"
values="9;15;9"
/>
<animate
attributeName="fill-opacity"
begin="0s"
calcMode="linear"
dur="0.8s"
from="0.5"
repeatCount="indefinite"
to="0.5"
values=".5;1;.5"
/>
</circle>
<circle
cx="105"
cy="15"
r={15}
>
<animate
attributeName="r"
begin="0s"
calcMode="linear"
dur="0.8s"
from="15"
repeatCount="indefinite"
to="15"
values="15;9;15"
/>
<animate
attributeName="fill-opacity"
begin="0s"
calcMode="linear"
dur="0.8s"
from="1"
repeatCount="indefinite"
to="1"
values="1;.5;1"
/>
</circle>
</svg>
</div>
</div>,
<div
className="p-grid"
data-testid="confirm_dialog"
>
<div
className="custom-dlg p-grid"
data-testid="confirm_dialog"
style={
Object {
"opacity": 1,
}
}
/>
</div>,
]
`;
import React from 'react';
import {cleanup, fireEvent, screen,act,waitFor} from '@testing-library/react';
import { cleanup, fireEvent, screen, act, waitFor } from '@testing-library/react';
import renderer from 'react-test-renderer';
import '@testing-library/jest-dom';
import {SchedulingUnitCreate} from './create';
import { SchedulingUnitCreate } from './create';
import ScheduleService from '../../services/schedule.service';
import UtilService from '../../services/util.service';
import ProjectService from '../../services/project.service';
......@@ -13,8 +13,8 @@ import SUServiceMock from '../../__mocks__/scheduleunit.service.data';
import ProjectServiceMock from '../../__mocks__/project.service.data';
import TaskServiceMock from '../../__mocks__/task.service.data';
import UtilServiceMock from '../../__mocks__/util.service.data';
import {clickItem, removeReact18ConsoleErrors, renderPage, setMultiSelectValue} from "../../utils/test.helper";
import {setSchedulingUnitStrategy} from "./schedulingunit.test.helper";
import { clickItem, removeReact18ConsoleErrors, renderPage, setMultiSelectValue } from "../../utils/test.helper";
import { setSchedulingUnitStrategy } from "./schedulingunit.test.helper";
let projectListSpy, observStrategiesSpy, taskTemplatesSpy, utilSpy, taskFilterDefSpy, suConstraintTemplateSpy,
stationGroupSpy, templatePurposesSpy, templateStatesSpy, rolesSpy, scheduleSetByIdSpy;
......@@ -64,64 +64,80 @@ function createStandardPageMocks() {
async function setSchedulingUnitBasics(pageContent) {
const nameElement = pageContent.queryByTestId('name');
act(() => fireEvent.change(nameElement, {target: {value: "Wolverine"}}));
act(() => fireEvent.change(nameElement, { target: { value: "Wolverine" } }));
const descriptionElement = pageContent.queryByTestId('description');
act(() => fireEvent.change(descriptionElement, {target: {value: "Big claws"}}));
act(() => fireEvent.change(descriptionElement, { target: { value: "Big claws" } }));
await setMultiSelectValue(pageContent, "project", "high")
await setMultiSelectValue(pageContent, "schedSet", "Test Scheduling Set")
}
describe('Scheduling Unit create page default', () => {
let pageContent;
beforeEach(async () => {
createStandardPageMocks();
pageContent = await renderPage(<SchedulingUnitCreate location={{pathname: '/schedulingunit/create'}}/>);
})
});
afterEach(() => {
jest.clearAllMocks();
cleanup();
});
test("Renders with all standard service mocks", async () => {
expect(pageContent.queryByText('Scheduling Unit - Add')).not.toBe(null);
expect(projectListSpy).toHaveBeenCalled();
expect(observStrategiesSpy).toHaveBeenCalled();
expect(suConstraintTemplateSpy).toHaveBeenCalled();
expect(rolesSpy).toHaveBeenCalled();
expect(taskTemplatesSpy).toHaveBeenCalled();
expect(stationGroupSpy).toHaveBeenCalled();
expect(utilSpy).toHaveBeenCalled();
expect(taskFilterDefSpy).toHaveBeenCalled();
expect(templatePurposesSpy).toHaveBeenCalled();
expect(templateStatesSpy).toHaveBeenCalled();
});
test("Renders with all standard service mocks", () => {
// TODO : Fix Unit test Changes a text field
test.skip("Changes a text field", async () => {
const nameInputEl = pageContent.queryByTestId('name');
fireEvent.change(nameInputEl, {target: {value: 'SU High 1'}});
expect(nameInputEl.value).toBe("SU High 1");
});
const page = renderer
.create(<SchedulingUnitCreate location={{ pathname: '/schedulingunit/create' }} />)
.toJSON();
expect(page).toMatchSnapshot();
})
// TODO : Fix Unit Test Selects a project, loads the project's sets and selects the test scheduling set
test.skip("Selects a project, loads the project's sets and selects the test scheduling set", async () => {
let scheduleSetListSpy = jest.spyOn(ScheduleService, 'getSchedulingSets').mockImplementation((filter) => {
let allSUSets = SUServiceMock.scheduleSetList;
let project = filter.replace("project=", "");
return Promise.resolve(allSUSets.filter(set => set.project_id === project));
});
await setSchedulingUnitBasics(pageContent);
expect(scheduleSetListSpy).toHaveBeenCalled()
expect(pageContent.queryByTestId("project").textContent).toContain("high");
expect(pageContent.queryByTestId("schedSet").textContent).toContain("Test Scheduling Set");
expect(pageContent.queryByTestId('save-btn')).toHaveAttribute("disabled");
test("Verify Mock Calls", async () => {
let pageContent = await renderPage(<SchedulingUnitCreate location={{ pathname: '/schedulingunit/create' }} />);
expect(projectListSpy).toHaveBeenCalled();
expect(observStrategiesSpy).toHaveBeenCalled();
expect(suConstraintTemplateSpy).toHaveBeenCalled();
expect(rolesSpy).toHaveBeenCalled();
expect(taskTemplatesSpy).toHaveBeenCalled();
expect(stationGroupSpy).toHaveBeenCalled();
expect(utilSpy).toHaveBeenCalled();
expect(taskFilterDefSpy).toHaveBeenCalled();
expect(templatePurposesSpy).toHaveBeenCalled();
expect(templateStatesSpy).toHaveBeenCalled();
});
test("Changes a text field", async () => {
let pageContent = await renderPage(<SchedulingUnitCreate location={{ pathname: '/schedulingunit/create' }} />);
await waitFor (() => expect (pageContent.queryByTestId('name')).toBeInTheDocument());
const nameInputEl = pageContent.queryByTestId('name');
fireEvent.change(nameInputEl, {target: {value: 'SU High 1'}});
expect(nameInputEl.value).toBe("SU High 1");
});
test("Selects a project, loads the project's sets and selects the test scheduling set", async () => {
let pageContent = await renderPage(<SchedulingUnitCreate location={{ pathname: '/schedulingunit/create' }} />);
let scheduleSetListSpy = jest.spyOn(ScheduleService, 'getSchedulingSets').mockImplementation((filter) => {
let allSUSets = SUServiceMock.scheduleSetList;
let project = filter.replace("project=", "");
return Promise.resolve(allSUSets.filter(set => set.project_id === project));
});
await waitFor (() => expect (pageContent.queryByTestId('name')).toBeInTheDocument());
await setSchedulingUnitBasics(pageContent);
expect(scheduleSetListSpy).toHaveBeenCalled()
expect(pageContent.queryByTestId("project").textContent).toContain("high");
expect(pageContent.queryByTestId("schedSet").textContent).toContain("Test Scheduling Set");
expect(pageContent.queryByTestId('save-btn')).toHaveAttribute("disabled");
});
});
/*
// TODO : Fix Unit Test Scheduling Unit create page with an observation strategy template (multiple)
......
......@@ -123,7 +123,7 @@ describe('Scheduling Units Excel View create page default', () => {
// TODO : Fix Unit Test Scheduling Units Excel View create page with an observation strategy template
describe('Scheduling Units Excel View create page with an observation strategy template', () => {
let pageContent;
......
import {render,act} from "@testing-library/react";
import TimelineItemPopover, {getFieldsHtml} from "./TimelineItemPopover";
import { render, act } from "@testing-library/react";
import TimelineItemPopover, { getFieldsHtml } from "./TimelineItemPopover";
import moment from "moment";
import {removeReact18ConsoleErrors} from "../../../utils/test.helper";
import { removeReact18ConsoleErrors } from "../../../utils/test.helper";
import UIConstants from "../../../utils/ui.constants";
import renderer from 'react-test-renderer';
removeReact18ConsoleErrors()
describe("TimelineItemPopover", () => {
......@@ -24,22 +24,21 @@ describe("TimelineItemPopover", () => {
on_sky_duration: 2.5,
duration: 3.5,
};
// TODO : Fix Unit Test Render type SCHEDULE for a schedulable item
test("Render type SCHEDULE for a schedulable item", () => {
let pagecontent
act(async () => {
pagecontent = render(<TimelineItemPopover mouseOverItem={mouseOverItemSchedule}/>);
pagecontent = render(<TimelineItemPopover mouseOverItem={mouseOverItemSchedule} />);
});
const renderedFields = pagecontent.container.querySelectorAll(".entry");
const fieldLabels = ["Project:", "Scheduling Unit:", "Scheduler:", "Start Time:", "End Time:", "Antenna Set:", "Stations:", "Status:", "Exposure Time:", "Duration:"];
const fieldValues = [mouseOverItemSchedule.project, mouseOverItemSchedule.name, mouseOverItemSchedule.scheduler,
mouseOverItemSchedule.suStartTime.format(UIConstants.CALENDAR_DATETIME_FORMAT), mouseOverItemSchedule.suStopTime.format(UIConstants.CALENDAR_DATETIME_FORMAT), mouseOverItemSchedule.antenna_set,
`${mouseOverItemSchedule.stations.groups} : ${mouseOverItemSchedule.stations.counts}`, mouseOverItemSchedule.status, mouseOverItemSchedule.on_sky_duration.toString(), mouseOverItemSchedule.duration.toString(),
mouseOverItemSchedule.suStartTime.format(UIConstants.CALENDAR_DATETIME_FORMAT), mouseOverItemSchedule.suStopTime.format(UIConstants.CALENDAR_DATETIME_FORMAT), mouseOverItemSchedule.antenna_set,
`${mouseOverItemSchedule.stations.groups} : ${mouseOverItemSchedule.stations.counts}`, mouseOverItemSchedule.status, mouseOverItemSchedule.on_sky_duration.toString(), mouseOverItemSchedule.duration.toString(),
];
renderedFields.forEach((field, index) => {
......@@ -67,17 +66,17 @@ describe("TimelineItemPopover", () => {
duration: 2,
planned: true,
};
let pagecontent
act(async () => {
pagecontent = render(<TimelineItemPopover mouseOverItem={mouseOverItem}/>);
pagecontent = render(<TimelineItemPopover mouseOverItem={mouseOverItem} />);
});
const renderedFields = pagecontent.container.querySelectorAll(".entry");
const fieldLabels = ["Name:", "Description:", "Type:", "Stations:", "Project:", "Start Time:", "End Time:", "Duration:", "Planned:"];
const fieldValues = [mouseOverItem.name, mouseOverItem.desc, mouseOverItem.activity_type, `${mouseOverItemSchedule.stations.groups} : ${mouseOverItemSchedule.stations.counts}`, mouseOverItem.project,
mouseOverItem.displayStartTime.format(UIConstants.CALENDAR_DATETIME_FORMAT), mouseOverItem.displayEndTime.format(UIConstants.CALENDAR_DATETIME_FORMAT),
mouseOverItem.duration.toString(), "Yes"
mouseOverItem.displayStartTime.format(UIConstants.CALENDAR_DATETIME_FORMAT), mouseOverItem.displayEndTime.format(UIConstants.CALENDAR_DATETIME_FORMAT),
mouseOverItem.duration.toString(), "Yes"
];
renderedFields.forEach((field, index) => {
......@@ -103,14 +102,14 @@ describe("TimelineItemPopover", () => {
};
let pagecontent
act(async () => {
pagecontent = render(<TimelineItemPopover mouseOverItem={mouseOverItem}/>);
pagecontent = render(<TimelineItemPopover mouseOverItem={mouseOverItem} />);
});
const renderedFields = pagecontent.container.querySelectorAll(".entry");
const fieldLabels = ["Name:", "Description:", "Type:", "Stations:", "Project:", "Start Time:", "End Time:", "Duration:", "Planned:"];
const fieldValues = [mouseOverItem.name, mouseOverItem.desc, mouseOverItem.activity_type, "-", mouseOverItem.project,
mouseOverItem.real_start_time.format(UIConstants.CALENDAR_DATETIME_FORMAT), mouseOverItem.real_end_time.format(UIConstants.CALENDAR_DATETIME_FORMAT),
mouseOverItem.duration.toString(), "Yes"
mouseOverItem.real_start_time.format(UIConstants.CALENDAR_DATETIME_FORMAT), mouseOverItem.real_end_time.format(UIConstants.CALENDAR_DATETIME_FORMAT),
mouseOverItem.duration.toString(), "Yes"
];
renderedFields.forEach((field, index) => {
......@@ -139,13 +138,13 @@ describe("TimelineItemPopover", () => {
duration: "2 hours",
};
const {container} = render(<TimelineItemPopover mouseOverItem={mouseOverItem}/>);
const { container } = render(<TimelineItemPopover mouseOverItem={mouseOverItem} />);
const renderedFields = container.querySelectorAll(".entry");
const fieldLabels = ["Project:", "Scheduling Unit:", "Task Id:", "Task Name:", "Control Id:", "Start Time:", "End Time:", "HBA/LBA:", "Stations:", "Status:", "Duration:"];
const fieldValues = [mouseOverItem.project, mouseOverItem.name, mouseOverItem.taskId, mouseOverItem.taskName, mouseOverItem.controlId,
mouseOverItem.start_time.format(UIConstants.CALENDAR_DATETIME_FORMAT), mouseOverItem.end_time.format(UIConstants.CALENDAR_DATETIME_FORMAT),
mouseOverItem.band, `${mouseOverItemSchedule.stations.groups} : ${mouseOverItemSchedule.stations.counts}`, mouseOverItem.status, mouseOverItem.duration
mouseOverItem.start_time.format(UIConstants.CALENDAR_DATETIME_FORMAT), mouseOverItem.end_time.format(UIConstants.CALENDAR_DATETIME_FORMAT),
mouseOverItem.band, `${mouseOverItemSchedule.stations.groups} : ${mouseOverItemSchedule.stations.counts}`, mouseOverItem.status, mouseOverItem.duration
];
renderedFields.forEach((field, index) => {
......@@ -156,7 +155,7 @@ describe("TimelineItemPopover", () => {
})
test.each([null, undefined, {}])('Render nothing on invalid input: %s', (mouseOverItem) => {
const {queryByText} = render(<TimelineItemPopover mouseOverItem={mouseOverItem}/>);
const { queryByText } = render(<TimelineItemPopover mouseOverItem={mouseOverItem} />);
expect(queryByText("Reservation Overview")).not.toBeInTheDocument();
expect(queryByText("Scheduling Unit Overview")).not.toBeInTheDocument();
......@@ -165,61 +164,27 @@ describe("TimelineItemPopover", () => {
describe("getFieldsHtml", () => {
const fields = [
{label: "Project:", value: "X-men"},
{label: "Scheduling Unit:", value: "Wolverine"},
{ label: "Project:", value: "X-men" },
{ label: "Scheduling Unit:", value: "Wolverine" },
];
// This is a snapshot test now. This means it validates against a
// Correct taken snapshot.
test('Render fields with the correct label, value, and classNames', () => {
test("Render fields with the correct label, value, and classNames", () => {
const status = "scheduled";
const style = {color: "blue"};
let pagecontent;
act( () => {
pagecontent = render(getFieldsHtml(fields, status, style));
});
// Check if the correct number of fields are rendered
const renderedFields = pagecontent.container.getElementsByClassName("entry");
expect(renderedFields.length).toBe(fields.length);
// Check if the labels and values are rendered correctly
fields.forEach((field, index) => {
const renderedLabel = pagecontent.container.querySelector(`.entry:nth-child(${index + 1}) label`);
const renderedValue = pagecontent.container.querySelector(`.entry:nth-child(${index + 1}) .col-7`);
expect(renderedLabel).toHaveTextContent(field.label);
expect(renderedValue).toHaveTextContent(field.value);
});
// Check if the label has the correct className based on the status
const labelClassName = status ? `col-5 su-${status}-icon` : 'col-5';
const renderedLabels = pagecontent.container.querySelectorAll("label");
renderedLabels.forEach((label) => {
expect(label).toHaveClass(labelClassName);
});
const style = { color: "blue" };
const page = renderer
.create(getFieldsHtml(fields, status, style))
.toJSON();
expect(page).toMatchSnapshot();
})
// Check if the label has the correct style based on the provided style object
const renderedLabelsStyle = renderedLabels[0].style;
expect(renderedLabelsStyle.color).toBe(style.color);
});
test("Render fields without status and style", () => {
const {container} = render(getFieldsHtml(fields));
// Check if the label has the default className 'col-5' (no status provided)
const renderedLabels = container.querySelectorAll("label");
renderedLabels.forEach((label) => {
expect(label).toHaveClass("col-5");
});
// Check if the labels have no additional style (no style provided)
const renderedLabelsStyle = renderedLabels[0].style;
expect(renderedLabelsStyle.length).toBe(0);
});
const page = renderer
.create(getFieldsHtml(fields))
.toJSON();
expect(page).toMatchSnapshot();
})
});
\ No newline at end of file
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`getFieldsHtml Render fields with the correct label, value, and classNames 1`] = `
Array [
<div
className="entry"
>
<label
className="col-5 su-scheduled-icon"
style={
Object {
"color": "blue",
}
}
>
Project:
</label>
<div
className="col-7 initial-line-height"
>
X-men
</div>
</div>,
<div
className="entry"
>
<label
className="col-5 su-scheduled-icon"
style={
Object {
"color": "blue",
}
}
>
Scheduling Unit:
</label>
<div
className="col-7 initial-line-height"
>
Wolverine
</div>
</div>,
]
`;
exports[`getFieldsHtml Render fields without status and style 1`] = `
Array [
<div
className="entry"
>
<label
className="col-5"
style={Object {}}
>
Project:
</label>
<div
className="col-7 initial-line-height"
>
X-men
</div>
</div>,
<div
className="entry"
>
<label
className="col-5"
style={Object {}}
>
Scheduling Unit:
</label>
<div
className="col-7 initial-line-height"
>
Wolverine
</div>
</div>,
]
`;
......@@ -46,12 +46,9 @@ describe('ZoomAndMove', () => {
})
// TODO : Fix unit test renders loading spinner when props are not yet available
it('renders loading spinner when props are not yet available', () => {
let moctm = mockTimelineStore;
const {getByRole}= render(
<ZoomAndMove
timelineStore={moctm}
......
......@@ -5,6 +5,7 @@ import {
splitObjectIfSpanIsMultipleDays
} from "./filters.helper";
import moment from "moment/moment";
import renderer from 'react-test-renderer';
jest.mock('moment', () => {
const originalMoment = jest.requireActual('moment');
......@@ -176,7 +177,7 @@ describe("getTimelineItem", () => {
const suBlueprint = {
id: "blueprint-id",
description:"test blueprint",
description: "test blueprint",
process_start_time: "2023-07-06T10:00:00Z",
on_sky_start_time: "2023-07-06T10:00:00Z",
tasks: tasks,
......@@ -188,12 +189,12 @@ describe("getTimelineItem", () => {
process_stop_time: "2023-07-06T12:00:00Z",
on_sky_stop_time: "2023-07-06T12:00:00Z",
real_start_time: "2023-07-06T12:01:00Z",
real_end_time:"2023-07-06T12:02:00Z",
real_end_time: "2023-07-06T12:02:00Z",
placed: true,
unschedulable_reason: "none",
scheduling_constraints_doc: { scheduler: "fixed" },
antenna_set:"antenna_set_value",
scheduler:"fixed"
antenna_set: "antenna_set_value",
scheduler: "fixed"
};
const displayDate = moment("2023-07-06", "YYYY-MM-DD")
......@@ -205,8 +206,8 @@ describe("getTimelineItem", () => {
id: "blueprint-id-27: Jul 06 - Thu",
suId: "blueprint-id",
group: "27: Jul 06 - Thu",
band :"antenna",
desc:"test blueprint",
band: "antenna",
desc: "test blueprint",
title: "",
project: "bugs",
name: "the_fix_1",
......@@ -216,8 +217,8 @@ describe("getTimelineItem", () => {
start_time: moment("2023-07-06 10:00:00Z"),
end_time: moment("2023-07-06 12:00:00Z"),
real_start_time: "2023-07-06T12:01:00Z",
real_end_time:"2023-07-06T12:02:00Z",
stations:"-",
real_end_time: "2023-07-06T12:02:00Z",
stations: "-",
type: "SCHEDULE",
status: "defined",
scheduler: "fixed",
......@@ -226,7 +227,7 @@ describe("getTimelineItem", () => {
});
it("returns the correct item object when antenna set is not provided", () => {
let suBlueprintWithoutAntennaSet = {
...suBlueprint,
......@@ -239,14 +240,14 @@ describe("getTimelineItem", () => {
}
]
};
suBlueprintWithoutAntennaSet.antenna_set=undefined;
suBlueprintWithoutAntennaSet.antenna_set = undefined;
const item = getTimelineItem(suBlueprintWithoutAntennaSet, displayDate);
expect(item).toEqual({
id: "blueprint-id-27: Jul 06 - Thu",
suId: "blueprint-id",
band :undefined,
desc:"test blueprint",
band: undefined,
desc: "test blueprint",
group: "27: Jul 06 - Thu",
title: "",
project: "bugs",
......@@ -254,22 +255,24 @@ describe("getTimelineItem", () => {
antenna_set: undefined,
scheduler: "fixed",
duration: "1.00Hrs",
stations:"-",
stations: "-",
on_sky_duration: "2.00Hrs",
start_time: moment("2023-07-06 10:00:00Z"),
end_time: moment("2023-07-06 12:00:00Z"),
real_start_time: "2023-07-06T12:01:00Z",
real_end_time:"2023-07-06T12:02:00Z",
real_end_time: "2023-07-06T12:02:00Z",
type: "SCHEDULE",
status: "defined",
unschedulable_reason: "none"
});
});
});
describe('getReservationItem', () => {
let reservation = {
id: '1',
name: 'green grass',
......@@ -289,6 +292,7 @@ describe('getReservationItem', () => {
description: 'with a grass mower'
};
let expectedItem = {
id: "Res-1-Aug 08 - Tue",
start_time: moment('2023-08-08 10:00:00'),
......@@ -307,6 +311,7 @@ describe('getReservationItem', () => {
stations: '-'
};
const displayDate = moment('2023-08-08', 'YYYY-MM-DD');
// TODO : Fix Unit Test should return the correct reservation item (no stations)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment