Add app bar tests.

This commit is contained in:
Paulo Gustavo Veiga 2022-10-11 21:09:02 -07:00
parent 015e23f137
commit e72531ad03
11 changed files with 232 additions and 67 deletions

View File

@ -1,6 +0,0 @@
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
]
}

View File

@ -0,0 +1,25 @@
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": false,
"targets": {
"esmodules": true
}
},
"@babel/preset-typescript",
]
],
"env": {
"test": {
"plugins": [
"transform-require-context"
],
},
},
"plugins": [
"@babel/plugin-proposal-class-properties"
],
"sourceType": "module"
}

View File

@ -0,0 +1,12 @@
const config = {
testEnvironment: 'jsdom',
verbose: true,
preset: 'ts-jest',
moduleFileExtensions: ['js', 'ts','tsx'],
transform: {
'^.+\\.js?$': 'babel-jest',
".+\\.(svg|css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$": "jest-transform-stub"
},
};
module.exports = config;

View File

@ -19,12 +19,13 @@
"devDependencies": {
"@babel/preset-env": "^7.18.6",
"@babel/preset-react": "^7.18.6",
"@formatjs/cli": "^4.8.1",
"@babel/preset-typescript": "^7.16.5",
"@formatjs/cli": "^4.8.1",
"@testing-library/react": "^12.0.0",
"@types/jest": "^29.0.0",
"@typescript-eslint/eslint-plugin": "^4.8.1",
"@typescript-eslint/parser": "^4.8.1",
"babel-plugin-transform-require-context": "^0.1.1",
"babel-polyfill": "^6.26.0",
"clean-webpack-plugin": "^4.0.0",
"compression-webpack-plugin": "^9.2.0",
@ -37,6 +38,7 @@
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "^4.2.0",
"html-webpack-plugin": "^5.5.0",
"jest-transform-stub": "^2.0.0",
"prettier": "^2.2.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
@ -53,27 +55,14 @@
"react-color": "^2.19.3"
},
"peerDependencies": {
"@emotion/react": "^11.10.4",
"@emotion/styled": "^11.10.4",
"@mui/icons-material": "^5.9.3",
"@mui/material": "^5.9.3",
"@types/styled-components": "^5.1.26",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-intl": "^5.24.3",
"styled-components": "^5.3.5",
"@emotion/react": "^11.10.4",
"@emotion/styled": "^11.10.4",
"@mui/icons-material": "^5.9.3",
"@mui/material": "^5.9.3"
},
"jest": {
"testEnvironment": "jsdom",
"verbose": true,
"preset": "ts-jest",
"moduleFileExtensions": [
"js",
"ts",
"tsx"
],
"transform": {
"^.+\\.js?$": "babel-jest"
}
"styled-components": "^5.3.5"
}
}

View File

@ -29,6 +29,7 @@ type ActionType =
| 'account'
| 'edition-toolbar'
| 'sign-up'
| 'starred'
| 'keyboard-shortcuts';
export default ActionType;

View File

@ -181,5 +181,6 @@ const ActionConfigByRenderMode: Record<ActionType, CapabilitySupport> = {
hidden: ['viewonly', 'edition-viewer', 'edition-editor', 'edition-owner'],
},
},
starred: undefined,
};
export default Capability;

View File

@ -19,20 +19,27 @@ import { Designer, MindplotWebComponent, PersistenceManager } from '@wisemapping
import Capability from '../../action/capability';
class Editor {
private component: MindplotWebComponent;
constructor(mindplotComponent: MindplotWebComponent) {
private component: MindplotWebComponent | null;
constructor(mindplotComponent: MindplotWebComponent | null) {
this.component = mindplotComponent;
}
isMapLoadded(): boolean {
return this.component.getDesigner()?.getMindmap() != null;
return this.component?.getDesigner()?.getMindmap() != null;
}
save(minor: boolean) {
if (!this.component) {
throw new Error('Designer object has not been initialized.');
}
this.component.save(minor);
}
getDesigner(): Designer | undefined {
if (!this.component) {
throw new Error('Designer object has not been initialized.');
}
return this.component?.getDesigner();
}

View File

@ -26,16 +26,14 @@ const UndoAndRedo = (props: {
const [disabled, setDisabled] = useState(true);
useEffect(() => {
const handleUpdate: any = (event) => {
if (props.disabledCondition(event)) {
setDisabled(false);
} else {
setDisabled(true);
}
};
const isDisabled = props.disabledCondition(event);
setDisabled(!isDisabled);
designer.addEvent('modelUpdate', handleUpdate);
return () => {
designer.removeEvent('modelUpdate', handleUpdate);
};
};
}, []);
return (

View File

@ -30,6 +30,7 @@ import RestoreOutlinedIcon from '@mui/icons-material/RestoreOutlined';
import SaveOutlinedIcon from '@mui/icons-material/SaveOutlined';
import PrintOutlinedIcon from '@mui/icons-material/PrintOutlined';
import FileDownloadOutlinedIcon from '@mui/icons-material/FileDownloadOutlined';
import StarRateRoundedIcon from '@mui/icons-material/StarRateRounded';
import CloudUploadOutlinedIcon from '@mui/icons-material/CloudUploadOutlined';
import HelpOutlineOutlinedIcon from '@mui/icons-material/InfoOutlined';
import ArrowBackIosNewOutlinedIcon from '@mui/icons-material/ArrowBackIosNewOutlined';
@ -38,19 +39,17 @@ import { $msg } from '@wisemapping/mindplot';
import UndoAndRedo from '../action-widget/button/undo-and-redo';
import Button from '@mui/material/Button';
import LogoTextBlackSvg from '../../../images/logo-text-black.svg';
import IconButton from '@mui/material/IconButton';
/**
* App bar
* @param props.configurations the configurations array
* @returns toolbar wich contains an entry for each configuration in the array
*/
const AppBar = (props: {
interface AppBarProps {
model: Editor;
mapTitle: string;
capability: Capability;
onAction?: (type: ToolbarActionType) => void;
accountConfig?;
}) => {
}
const AppBar = ({ model, mapTitle, capability, onAction, accountConfig }: AppBarProps) => {
const appBarDivisor = {
render: () => <Typography component="div" sx={{ flexGrow: 1 }} />,
};
@ -131,6 +130,21 @@ const AppBar = (props: {
visible: !capability.isHidden('history'),
},
appBarDivisor,
{
tooltip: $msg('SAVE') + ' (' + $msg('CTRL') + ' + S)',
render: () => (
<IconButton size="small" onClick={() => {}}>
<StarRateRoundedIcon
color="action"
style={{
color: 'yellow',
}}
/>
</IconButton>
),
visible: !capability.isHidden('starred'),
disabled: () => !model?.isMapLoadded(),
},
{
icon: <FileDownloadOutlinedIcon />,
tooltip: $msg('EXPORT'),
@ -178,13 +192,7 @@ const AppBar = (props: {
];
};
const config = buildConfig(
props.model,
props.mapTitle,
props.capability,
props.onAction,
props.accountConfig,
);
const config = buildConfig(model, mapTitle, capability, onAction, accountConfig);
return (
<MaterialAppBar
role="menubar"

View File

@ -272,17 +272,10 @@ describe('Toolbar', () => {
});
describe('AppBar', () => {
//Todo: Activate when all the bundle resources are migrated.
// SyntaxError: Cannot use import statement outside a module
// @wisemapping/editor: 17 | */
// @wisemapping/editor: 18 | import { $defined } from '@wisemapping/core - js';
// @wisemapping/editor: > 19 | import Bundle from './lang / Bundle';
//
//
// it('When render it displays a menu', () => {
// const capacity = new Capability('edition-owner', false);
// const model = new Editor(null);
// render(<AppBar mapTitle="Some title" capability={capacity} model={model} />);
// screen.getByRole('menubar');
// });
it('When render it displays a menu', () => {
const capacity = new Capability('edition-owner', false);
const model = new Editor(null);
render(<AppBar mapTitle="Some title" capability={capacity} model={model} />);
screen.getByRole('menubar');
});
});

141
yarn.lock
View File

@ -36,6 +36,11 @@
resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.19.3.tgz#707b939793f867f5a73b2666e6d9a3396eb03151"
integrity sha512-prBHMK4JYYK+wDjJF1q99KK4JLL+egWS4nmNqdlMUgCExMZ+iZW0hGhyC3VEbsPjvaN0TBhW//VIFwBrk8sEiw==
"@babel/compat-data@^7.19.4":
version "7.19.4"
resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.19.4.tgz#95c86de137bf0317f3a570e1b6e996b427299747"
integrity sha512-CHIGpJcUQ5lU9KrPHTjBMhVwQG6CQjxfg36fGXl3qk/Gik1WwWachaXFuo0uCWJT/mStOKtcbFJCaVLihC1CMw==
"@babel/core@^7.1.0", "@babel/core@^7.12.3", "@babel/core@^7.18.13", "@babel/core@^7.7.2", "@babel/core@^7.8.0":
version "7.19.3"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.19.3.tgz#2519f62a51458f43b682d61583c3810e7dcee64c"
@ -238,6 +243,11 @@
resolved "https://registry.yarnpkg.com/@babel/helper-string-parser/-/helper-string-parser-7.18.10.tgz#181f22d28ebe1b3857fa575f5c290b1aaf659b56"
integrity sha512-XtIfWmeNY3i4t7t4D2t02q50HvqHybPqW2ki1kosnvWCwuCMeo81Jf0gwr85jy/neUdg5XDdeFE/80DXiO+njw==
"@babel/helper-string-parser@^7.19.4":
version "7.19.4"
resolved "https://registry.yarnpkg.com/@babel/helper-string-parser/-/helper-string-parser-7.19.4.tgz#38d3acb654b4701a9b77fb0615a96f775c3a9e63"
integrity sha512-nHtDoQcuqFmwYNYPz3Rah5ph2p8PFeFCsZk9A/48dPc/rGocJ5J3hAAZ7pb76VWX3fZKu+uEr/FhH5jLx7umrw==
"@babel/helper-validator-identifier@^7.18.6", "@babel/helper-validator-identifier@^7.19.1":
version "7.19.1"
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.19.1.tgz#7eea834cf32901ffdc1a7ee555e2f9c27e249ca2"
@ -383,6 +393,17 @@
"@babel/plugin-syntax-object-rest-spread" "^7.8.3"
"@babel/plugin-transform-parameters" "^7.18.8"
"@babel/plugin-proposal-object-rest-spread@^7.19.4":
version "7.19.4"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.19.4.tgz#a8fc86e8180ff57290c91a75d83fe658189b642d"
integrity sha512-wHmj6LDxVDnL+3WhXteUBaoM1aVILZODAUjg11kHqG4cOlfgMQGxw6aCgvrXrmaJR3Bn14oZhImyCPZzRpC93Q==
dependencies:
"@babel/compat-data" "^7.19.4"
"@babel/helper-compilation-targets" "^7.19.3"
"@babel/helper-plugin-utils" "^7.19.0"
"@babel/plugin-syntax-object-rest-spread" "^7.8.3"
"@babel/plugin-transform-parameters" "^7.18.8"
"@babel/plugin-proposal-optional-catch-binding@^7.18.6":
version "7.18.6"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-catch-binding/-/plugin-proposal-optional-catch-binding-7.18.6.tgz#f9400d0e6a3ea93ba9ef70b09e72dd6da638a2cb"
@ -589,6 +610,13 @@
dependencies:
"@babel/helper-plugin-utils" "^7.18.9"
"@babel/plugin-transform-block-scoping@^7.19.4":
version "7.19.4"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-block-scoping/-/plugin-transform-block-scoping-7.19.4.tgz#315d70f68ce64426db379a3d830e7ac30be02e9b"
integrity sha512-934S2VLLlt2hRJwPf4MczaOr4hYF0z+VKPwqTNxyKX7NthTiPfhuKFWQZHXRM0vh/wo/VyXB3s4bZUNA08l+tQ==
dependencies:
"@babel/helper-plugin-utils" "^7.19.0"
"@babel/plugin-transform-classes@^7.19.0":
version "7.19.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-classes/-/plugin-transform-classes-7.19.0.tgz#0e61ec257fba409c41372175e7c1e606dc79bb20"
@ -618,6 +646,13 @@
dependencies:
"@babel/helper-plugin-utils" "^7.18.9"
"@babel/plugin-transform-destructuring@^7.19.4":
version "7.19.4"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-destructuring/-/plugin-transform-destructuring-7.19.4.tgz#46890722687b9b89e1369ad0bd8dc6c5a3b4319d"
integrity sha512-t0j0Hgidqf0aM86dF8U+vXYReUgJnlv4bZLsyoPnwZNrGY+7/38o8YjaELrvHeVfTZao15kjR0PVv0nju2iduA==
dependencies:
"@babel/helper-plugin-utils" "^7.19.0"
"@babel/plugin-transform-dotall-regex@^7.18.6", "@babel/plugin-transform-dotall-regex@^7.4.4":
version "7.18.6"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-dotall-regex/-/plugin-transform-dotall-regex-7.18.6.tgz#b286b3e7aae6c7b861e45bed0a2fafd6b1a4fef8"
@ -854,7 +889,7 @@
"@babel/helper-create-regexp-features-plugin" "^7.18.6"
"@babel/helper-plugin-utils" "^7.18.6"
"@babel/preset-env@^7.14.7", "@babel/preset-env@^7.18.6":
"@babel/preset-env@^7.14.7":
version "7.19.3"
resolved "https://registry.yarnpkg.com/@babel/preset-env/-/preset-env-7.19.3.tgz#52cd19abaecb3f176a4ff9cc5e15b7bf06bec754"
integrity sha512-ziye1OTc9dGFOAXSWKUqQblYHNlBOaDl8wzqf2iKXJAltYiR3hKHUKmkt+S9PppW7RQpq4fFCrwwpIDj/f5P4w==
@ -935,6 +970,87 @@
core-js-compat "^3.25.1"
semver "^6.3.0"
"@babel/preset-env@^7.18.6":
version "7.19.4"
resolved "https://registry.yarnpkg.com/@babel/preset-env/-/preset-env-7.19.4.tgz#4c91ce2e1f994f717efb4237891c3ad2d808c94b"
integrity sha512-5QVOTXUdqTCjQuh2GGtdd7YEhoRXBMVGROAtsBeLGIbIz3obCBIfRMT1I3ZKkMgNzwkyCkftDXSSkHxnfVf4qg==
dependencies:
"@babel/compat-data" "^7.19.4"
"@babel/helper-compilation-targets" "^7.19.3"
"@babel/helper-plugin-utils" "^7.19.0"
"@babel/helper-validator-option" "^7.18.6"
"@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression" "^7.18.6"
"@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining" "^7.18.9"
"@babel/plugin-proposal-async-generator-functions" "^7.19.1"
"@babel/plugin-proposal-class-properties" "^7.18.6"
"@babel/plugin-proposal-class-static-block" "^7.18.6"
"@babel/plugin-proposal-dynamic-import" "^7.18.6"
"@babel/plugin-proposal-export-namespace-from" "^7.18.9"
"@babel/plugin-proposal-json-strings" "^7.18.6"
"@babel/plugin-proposal-logical-assignment-operators" "^7.18.9"
"@babel/plugin-proposal-nullish-coalescing-operator" "^7.18.6"
"@babel/plugin-proposal-numeric-separator" "^7.18.6"
"@babel/plugin-proposal-object-rest-spread" "^7.19.4"
"@babel/plugin-proposal-optional-catch-binding" "^7.18.6"
"@babel/plugin-proposal-optional-chaining" "^7.18.9"
"@babel/plugin-proposal-private-methods" "^7.18.6"
"@babel/plugin-proposal-private-property-in-object" "^7.18.6"
"@babel/plugin-proposal-unicode-property-regex" "^7.18.6"
"@babel/plugin-syntax-async-generators" "^7.8.4"
"@babel/plugin-syntax-class-properties" "^7.12.13"
"@babel/plugin-syntax-class-static-block" "^7.14.5"
"@babel/plugin-syntax-dynamic-import" "^7.8.3"
"@babel/plugin-syntax-export-namespace-from" "^7.8.3"
"@babel/plugin-syntax-import-assertions" "^7.18.6"
"@babel/plugin-syntax-json-strings" "^7.8.3"
"@babel/plugin-syntax-logical-assignment-operators" "^7.10.4"
"@babel/plugin-syntax-nullish-coalescing-operator" "^7.8.3"
"@babel/plugin-syntax-numeric-separator" "^7.10.4"
"@babel/plugin-syntax-object-rest-spread" "^7.8.3"
"@babel/plugin-syntax-optional-catch-binding" "^7.8.3"
"@babel/plugin-syntax-optional-chaining" "^7.8.3"
"@babel/plugin-syntax-private-property-in-object" "^7.14.5"
"@babel/plugin-syntax-top-level-await" "^7.14.5"
"@babel/plugin-transform-arrow-functions" "^7.18.6"
"@babel/plugin-transform-async-to-generator" "^7.18.6"
"@babel/plugin-transform-block-scoped-functions" "^7.18.6"
"@babel/plugin-transform-block-scoping" "^7.19.4"
"@babel/plugin-transform-classes" "^7.19.0"
"@babel/plugin-transform-computed-properties" "^7.18.9"
"@babel/plugin-transform-destructuring" "^7.19.4"
"@babel/plugin-transform-dotall-regex" "^7.18.6"
"@babel/plugin-transform-duplicate-keys" "^7.18.9"
"@babel/plugin-transform-exponentiation-operator" "^7.18.6"
"@babel/plugin-transform-for-of" "^7.18.8"
"@babel/plugin-transform-function-name" "^7.18.9"
"@babel/plugin-transform-literals" "^7.18.9"
"@babel/plugin-transform-member-expression-literals" "^7.18.6"
"@babel/plugin-transform-modules-amd" "^7.18.6"
"@babel/plugin-transform-modules-commonjs" "^7.18.6"
"@babel/plugin-transform-modules-systemjs" "^7.19.0"
"@babel/plugin-transform-modules-umd" "^7.18.6"
"@babel/plugin-transform-named-capturing-groups-regex" "^7.19.1"
"@babel/plugin-transform-new-target" "^7.18.6"
"@babel/plugin-transform-object-super" "^7.18.6"
"@babel/plugin-transform-parameters" "^7.18.8"
"@babel/plugin-transform-property-literals" "^7.18.6"
"@babel/plugin-transform-regenerator" "^7.18.6"
"@babel/plugin-transform-reserved-words" "^7.18.6"
"@babel/plugin-transform-shorthand-properties" "^7.18.6"
"@babel/plugin-transform-spread" "^7.19.0"
"@babel/plugin-transform-sticky-regex" "^7.18.6"
"@babel/plugin-transform-template-literals" "^7.18.9"
"@babel/plugin-transform-typeof-symbol" "^7.18.9"
"@babel/plugin-transform-unicode-escapes" "^7.18.10"
"@babel/plugin-transform-unicode-regex" "^7.18.6"
"@babel/preset-modules" "^0.1.5"
"@babel/types" "^7.19.4"
babel-plugin-polyfill-corejs2 "^0.3.3"
babel-plugin-polyfill-corejs3 "^0.6.0"
babel-plugin-polyfill-regenerator "^0.4.1"
core-js-compat "^3.25.1"
semver "^6.3.0"
"@babel/preset-modules@^0.1.5":
version "0.1.5"
resolved "https://registry.yarnpkg.com/@babel/preset-modules/-/preset-modules-0.1.5.tgz#ef939d6e7f268827e1841638dc6ff95515e115d9"
@ -993,7 +1109,7 @@
dependencies:
regenerator-runtime "^0.13.4"
"@babel/template@^7.18.10", "@babel/template@^7.3.3":
"@babel/template@7", "@babel/template@^7.18.10", "@babel/template@^7.3.3":
version "7.18.10"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.18.10.tgz#6f9134835970d1dbf0835c0d100c9f38de0c5e71"
integrity sha512-TI+rCtooWHr3QJ27kJxfjutghu44DLnasDMwpDqCXVTal9RLp3RSYNh4NdBrRP2cQAoG9A8juOQl6P6oZG4JxA==
@ -1027,6 +1143,15 @@
"@babel/helper-validator-identifier" "^7.19.1"
to-fast-properties "^2.0.0"
"@babel/types@^7.19.4":
version "7.19.4"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.19.4.tgz#0dd5c91c573a202d600490a35b33246fed8a41c7"
integrity sha512-M5LK7nAeS6+9j7hAq+b3fQs+pNfUtTGq+yFFfHnauFA8zQtLRfmuipmsKDKKLuyG+wC8ABW43A153YNawNTEtw==
dependencies:
"@babel/helper-string-parser" "^7.19.4"
"@babel/helper-validator-identifier" "^7.19.1"
to-fast-properties "^2.0.0"
"@bcoe/v8-coverage@^0.2.3":
version "0.2.3"
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
@ -4408,6 +4533,13 @@ babel-plugin-syntax-jsx@^6.18.0:
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz#0af32a9a6e13ca7a3fd5069e62d7b0f58d0d8946"
integrity sha512-qrPaCSo9c8RHNRHIotaufGbuOBN8rtdC4QrrFFc43vyWCCz7Kl7GL1PGaXtMGQZUXrkCjNEgxDfmAuAabr/rlw==
babel-plugin-transform-require-context@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-require-context/-/babel-plugin-transform-require-context-0.1.1.tgz#319b545ca83080b5062776b46cc9b8b346fea9a6"
integrity sha512-4ceqYOtzgmq4/QsB8dP7pUrUOCjY/jrRYdt7YkIOWHxtGDQbcf6YZDyLCiPQf6KsEIcIbSQiTRXOsbLiuJfgNQ==
dependencies:
"@babel/template" "7"
babel-polyfill@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-polyfill/-/babel-polyfill-6.26.0.tgz#379937abc67d7895970adc621f284cd966cf2153"
@ -9525,6 +9657,11 @@ jest-snapshot@^27.5.1:
pretty-format "^27.5.1"
semver "^7.3.2"
jest-transform-stub@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/jest-transform-stub/-/jest-transform-stub-2.0.0.tgz#19018b0851f7568972147a5d60074b55f0225a7d"
integrity sha512-lspHaCRx/mBbnm3h4uMMS3R5aZzMwyNpNIJLXj4cEsV0mIUtS4IjYJLSoyjRCtnxb6RIGJ4NL2quZzfIeNhbkg==
jest-util@^27.0.0, jest-util@^27.5.1:
version "27.5.1"
resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-27.5.1.tgz#3ba9771e8e31a0b85da48fe0b0891fb86c01c2f9"