diff --git a/src/react/components/pages/editorPage/editorFooter.test.tsx b/src/react/components/pages/editorPage/editorFooter.test.tsx deleted file mode 100644 index fdb54a7fe7..0000000000 --- a/src/react/components/pages/editorPage/editorFooter.test.tsx +++ /dev/null @@ -1,166 +0,0 @@ -import { mount, ReactWrapper } from "enzyme"; -import React from "react"; -import EditorFooter, { IEditorFooterProps, IEditorFooterState } from "./editorFooter"; -import MockFactory from "../../../../common/mockFactory"; - -describe("Footer Component", () => { - - const originalTags = MockFactory.createTestTags(); - - function createComponent(props: IEditorFooterProps): ReactWrapper { - return mount( - , - ); - } - - it("tags are initialized correctly", () => { - const wrapper = createComponent({ - tags: originalTags, - lockedTags: [], - }); - const stateTags = wrapper.state().tags; - expect(stateTags).toEqual(originalTags); - }); - - it("tags are empty", () => { - const wrapper = createComponent({ - tags: [], - lockedTags: [], - }); - const stateTags = wrapper.state()["tags"]; - expect(stateTags).toEqual([]); - }); - - it("create a new tag from text box", () => { - const onChangeHandler = jest.fn(); - const wrapper = createComponent({ - tags: originalTags, - lockedTags: [], - onTagsChanged: onChangeHandler, - }); - const newTagName = "My new tag"; - wrapper.find("input").simulate("change", { target: { value: newTagName } }); - wrapper.find("input").simulate("keyDown", { keyCode: 13 }); - expect(onChangeHandler).toBeCalled(); - - const tags = wrapper.state().tags; - expect(tags).toHaveLength(originalTags.length + 1); - expect(tags[tags.length - 1].name).toEqual(newTagName); - }); - - it("create a new tag when no tags exist", () => { - const onChangeHandler = jest.fn(); - const wrapper = createComponent({ - tags: null, - lockedTags: [], - onTagsChanged: onChangeHandler, - }); - const newTagName = "My new tag"; - wrapper.find("input").simulate("change", { target: { value: newTagName } }); - wrapper.find("input").simulate("keyDown", { keyCode: 13 }); - expect(onChangeHandler).toBeCalled(); - - const tags = wrapper.state().tags; - expect(tags).toHaveLength(1); - expect(tags[0].name).toEqual(newTagName); - }); - - it("remove a tag", () => { - const onChangeHandler = jest.fn(); - const wrapper = createComponent({ - tags: originalTags, - lockedTags: [], - onTagsChanged: onChangeHandler, - }); - expect(wrapper.state().tags).toHaveLength(originalTags.length); - wrapper.find("a.ReactTags__remove") - .last().simulate("click"); - expect(onChangeHandler).toBeCalled(); - const tags = wrapper.state().tags; - expect(tags).toHaveLength(originalTags.length - 1); - expect(tags[0].name).toEqual(originalTags[0].name); - expect(tags[0].color).toEqual(originalTags[0].color); - }); - - it("clicking 'ok' in modal closes and calls onChangeHandler", () => { - const onChangeHandler = jest.fn(); - const wrapper = createComponent({ - tags: originalTags, - lockedTags: [], - onTagsChanged: onChangeHandler, - }); - wrapper.find("div.tag") - .first() - .simulate("click", { target: { innerText: originalTags[0].name }, shiftKey: true}); - wrapper.find("button.btn.btn-success").simulate("click"); - expect(onChangeHandler).toBeCalled(); - }); - - it("clicking 'cancel' in modal closes and does not call onChangeHandler", () => { - const onChangeHandler = jest.fn(); - const wrapper = createComponent({ - tags: originalTags, - lockedTags: [], - onTagsChanged: onChangeHandler, - }); - wrapper.find("div.tag") - .first() - .simulate("click", { target: { innerText: originalTags[0].name }, shiftKey: true}); - wrapper.find("button.btn.btn-secondary").simulate("click"); - - expect(onChangeHandler).not.toBeCalled(); - }); - - it("clicking tag calls onTagClickHandler ", () => { - const onChangeHandler = jest.fn(); - const onTagClickHandler = jest.fn(); - const wrapper = createComponent({ - tags: originalTags, - lockedTags: [], - onTagsChanged: onChangeHandler, - onTagClicked: onTagClickHandler, - }); - wrapper.find("div.tag") - .first() - .simulate("click", { target: { innerText: originalTags[0].name }}); - - expect(onTagClickHandler).toBeCalledWith(originalTags[0]); - }); - - it("clicking tag with ctrl does not call onTagClickHandler ", () => { - const onChangeHandler = jest.fn(); - const onTagClickHandler = jest.fn(); - const wrapper = createComponent({ - tags: originalTags, - lockedTags: [], - onTagsChanged: onChangeHandler, - onTagClicked: onTagClickHandler, - }); - wrapper.find("div.tag") - .first() - .simulate("click", { target: { innerText: originalTags[0].name }, shiftKey: true}); - - expect(onTagClickHandler).not.toBeCalled(); - }); - - it("componentDidUpdate check", async () => { - const onChangeHandler = jest.fn(); - const onTagClickHandler = jest.fn(); - const wrapper = createComponent({ - tags: originalTags, - lockedTags: [], - onTagsChanged: onChangeHandler, - onTagClicked: onTagClickHandler, - }); - - wrapper.setProps({tags: [...originalTags, {color: "#808000", name: "NEWTAG"}]}); - - await MockFactory.flushUi(); - wrapper.update(); - - const tagChild = wrapper.find("div.tag"); - - expect(tagChild.length).toEqual(originalTags.length + 1); - expect(tagChild.last().text()).toMatch("NEWTAG"); - }); -}); diff --git a/src/react/components/pages/editorPage/editorFooter.tsx b/src/react/components/pages/editorPage/editorFooter.tsx deleted file mode 100644 index 5078e429a5..0000000000 --- a/src/react/components/pages/editorPage/editorFooter.tsx +++ /dev/null @@ -1,134 +0,0 @@ -import React from "react"; -import { TagEditorModal, TagsInput } from "vott-react"; -import { strings } from "../../../../common/strings"; -import { ITag } from "../../../../models/applicationState"; - -/** - * Properties for Editor Footer - * @member tags - Array of tags for TagsInput component - * @member lockedTags - Tags currently locked for applying to regions - * @member displayHotKeys - Determines whether indices for first 10 tags are shown on tag buttons - * @member onTagsChanged - Function to call when tags are changed - * @member onTagClicked - Function to call when tags are clicked - */ -export interface IEditorFooterProps { - tags: ITag[]; - lockedTags: string[]; - onTagsChanged?: (value) => void; - onTagClicked?: (value) => void; - onCtrlTagClicked?: (value) => void; - onCtrlShiftTagClicked?: (value) => void; -} - -/** - * State for Editor Footer - * @member tags - Array of tags for TagsInput component - */ -export interface IEditorFooterState { - tags: ITag[]; - selectedTag: ITag; -} - -/** - * @name - Editor Footer - * @description - Footer of the editor page. Contains EditorTagsInput component - */ -export default class EditorFooter extends React.Component { - - public state = { - tags: this.props.tags, - selectedTag: null, - }; - - private tagsInput: React.RefObject = React.createRef(); - private tagEditorModal: React.RefObject = React.createRef(); - - public componentDidUpdate(prevProp: IEditorFooterProps) { - if (prevProp.tags !== this.props.tags) { - this.setState({ - tags: this.props.tags, - }); - } - } - - public render() { - return ( -
- - -
- ); - } - - private onTagClicked = (tag: ITag) => { - this.props.onTagClicked(tag); - this.blurTagsInput(); - } - - private onShiftTagClicked = (tag: ITag) => { - this.setState({ - selectedTag: tag, - }, () => { - this.tagEditorModal.current.open(tag); - }); - } - - private onTagModalOk = (oldTag: ITag, newTag: ITag) => { - this.tagsInput.current.updateTag(oldTag, newTag); - this.tagEditorModal.current.close(); - } - - private onTagsChanged = (tags) => { - this.setState({ - tags, - }, () => { - this.props.onTagsChanged(this.state); - this.blurTagsInput(); - }); - } - - /** - * Shows the display index of the tag in the span of the first 10 tags - * Also adds necessary stylings to all locked tags - * @param name Name of tag - * @param index Index of tag - */ - private getTagSpan = (name: string, index: number) => { - let className = "tag-span"; - let displayName = name; - if (index < 10) { - const displayIndex = (index === 9) ? 0 : index + 1; - displayName = `[${displayIndex}] ` + name; - className += " tag-span-index"; - } - if (this.props.lockedTags.find((t) => t === name)) { - className += " locked-tag"; - } - return ( - {displayName} - ); - } - - private blurTagsInput() { - const inputElement: HTMLElement = document.querySelector(".ReactTags__tagInputField"); - if (inputElement) { - setImmediate(() => inputElement.blur()); - } - } -}