mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-11 01:43:23 +01:00
Add unit test.
This commit is contained in:
parent
fa943b302f
commit
6ef810b77c
@ -17,29 +17,39 @@
|
|||||||
*/
|
*/
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import ActionConfig from '../../../../classes/action/action-config';
|
import ActionConfig from '../../../../classes/action/action-config';
|
||||||
|
import Editor from '../../../../classes/model/editor';
|
||||||
import { ToolbarMenuItem } from '../../../toolbar';
|
import { ToolbarMenuItem } from '../../../toolbar';
|
||||||
|
|
||||||
const UndoAndRedo = (props: {
|
type UndoAndRedo = {
|
||||||
configuration: ActionConfig;
|
configuration: ActionConfig;
|
||||||
disabledCondition: (event) => boolean;
|
disabledCondition: (event) => boolean;
|
||||||
}) => {
|
model: Editor;
|
||||||
|
};
|
||||||
|
|
||||||
|
const UndoAndRedo = ({ configuration, disabledCondition, model }: UndoAndRedo) => {
|
||||||
const [disabled, setDisabled] = useState(true);
|
const [disabled, setDisabled] = useState(true);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (model?.isMapLoadded()) {
|
||||||
const handleUpdate: any = (event) => {
|
const handleUpdate: any = (event) => {
|
||||||
const isDisabled = props.disabledCondition(event);
|
const isDisabled = disabledCondition(event);
|
||||||
setDisabled(!isDisabled);
|
setDisabled(!isDisabled);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
designer.removeEvent('modelUpdate', handleUpdate);
|
designer.removeEvent('modelUpdate', handleUpdate);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (model.getDesigner()) {
|
||||||
designer.addEvent('modelUpdate', handleUpdate);
|
designer.addEvent('modelUpdate', handleUpdate);
|
||||||
}, []);
|
}
|
||||||
|
}
|
||||||
|
}, [model?.isMapLoadded()]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ToolbarMenuItem
|
<ToolbarMenuItem
|
||||||
configuration={{
|
configuration={{
|
||||||
...props.configuration,
|
...configuration,
|
||||||
disabled: () => disabled,
|
disabled: () => disabled,
|
||||||
}}
|
}}
|
||||||
></ToolbarMenuItem>
|
></ToolbarMenuItem>
|
||||||
|
@ -116,6 +116,7 @@ const AppBar = ({ model, mapInfo, capability, onAction, accountConfig }: AppBarP
|
|||||||
onClick: () => designer.undo(),
|
onClick: () => designer.undo(),
|
||||||
}}
|
}}
|
||||||
disabledCondition={(event) => event.undoSteps > 0}
|
disabledCondition={(event) => event.undoSteps > 0}
|
||||||
|
model={model}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
visible: !capability.isHidden('undo-changes'),
|
visible: !capability.isHidden('undo-changes'),
|
||||||
@ -133,6 +134,7 @@ const AppBar = ({ model, mapInfo, capability, onAction, accountConfig }: AppBarP
|
|||||||
onClick: () => designer.redo(),
|
onClick: () => designer.redo(),
|
||||||
}}
|
}}
|
||||||
disabledCondition={(event) => event.redoSteps > 0}
|
disabledCondition={(event) => event.redoSteps > 0}
|
||||||
|
model={model}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
visible: !capability.isHidden('redo-changes'),
|
visible: !capability.isHidden('redo-changes'),
|
||||||
|
@ -31,7 +31,6 @@ const initialization = (designer: Designer) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const persistence = new LocalStorageManager('samples/{id}.wxml', false, false);
|
const persistence = new LocalStorageManager('samples/{id}.wxml', false, false);
|
||||||
const mapId = 'welcome';
|
|
||||||
const options: EditorOptions = {
|
const options: EditorOptions = {
|
||||||
mode: 'edition-owner',
|
mode: 'edition-owner',
|
||||||
locale: 'en',
|
locale: 'en',
|
||||||
|
@ -273,20 +273,21 @@ describe('Toolbar', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// describe('AppBar', () => {
|
describe('AppBar', () => {
|
||||||
// it('When render it displays a menu', () => {
|
it('When render it displays a menu', () => {
|
||||||
// const capacity = new Capability('edition-owner', false);
|
const capacity = new Capability('edition-owner', false);
|
||||||
// const model = new Editor(null);
|
const model = new Editor(null);
|
||||||
|
|
||||||
// render(
|
render(
|
||||||
// <IntlProvider>
|
<IntlProvider locale="en">
|
||||||
// <AppBar
|
<AppBar
|
||||||
// mapInfo={new MapInfoImpl('welcome', 'Develop Map Title', false)}
|
mapInfo={new MapInfoImpl('welcome', 'Develop Map Title', false)}
|
||||||
// capability={capacity}
|
capability={capacity}
|
||||||
// model={model}
|
model={model}
|
||||||
// />,
|
/>
|
||||||
// </IntlProvider>
|
,
|
||||||
// );
|
</IntlProvider>,
|
||||||
// screen.getByRole('menubar');
|
);
|
||||||
// });
|
screen.getByRole('menubar');
|
||||||
// });
|
});
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user