Skip to content

Commit

Permalink
Move test code, add missing dependencies, fix imports and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-schultz committed Jun 28, 2022
1 parent 6dc0269 commit ff8a04a
Show file tree
Hide file tree
Showing 38 changed files with 258 additions and 227 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"private": true,
"license": "Apache 2.0",
"workspaces": [
"silk-react-components",
"workspace",
"libs/gui-elements"
],
Expand Down
4 changes: 4 additions & 0 deletions silk-react-components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@

- bootstrap unit tests for silk-react-components
- add unit tests for SuggestionsList "render"

### Changed

- Move all code to workspace code base
9 changes: 5 additions & 4 deletions silk-workbench/silk-workbench-core/app/views/start.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
Your current workspace contains @projects.size project(s).
</p>

@if(!projects.exists(_.id == exampleName)) {
<button id="start-load-example" class="mdl-button mdl-js-button mdl-button--raised" onclick="loadExample()" style="margin-left: 5px;">Load Example</button>
&nbsp;
}
<span>
<a id="workspace-switch" href="@config.baseUrl/workbench?itemType=project&page=1&limit=10" class="mdl-button mdl-js-button mdl-button--raised">Open workspace</a>
<div class="mdl-tooltip" data-mdl-for="workspace-switch">
Expand All @@ -42,6 +38,11 @@
&nbsp;
<button id="open-workspace-btn" class="mdl-button mdl-js-button mdl-button--raised" onclick="window.location = '@config.baseUrl/workspace'">Open legacy workspace</button>

@if(!projects.exists(_.id == exampleName)) {
<button id="start-load-example" class="mdl-button mdl-js-button mdl-button--raised" onclick="loadExample()" style="margin-left: 5px;">Load Example</button>
&nbsp;
}

<script type="text/javascript">
function loadExample() {
$.post('@config.baseUrl/workspace/@exampleName/importExample')
Expand Down
10 changes: 9 additions & 1 deletion workspace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@
"react-sparklines": "^1.7.0",
"redux": "^4.0.0",
"redux-logger": "^3.0.6",
"store": "^2.0.12"
"store": "^2.0.12",
"@eccenca/superagent": "^1.4.1",
"ecc-utils": "^1.4.0",
"gui-elements-deprecated": "npm:@eccenca/gui-elements@^5.1.1",
"ecc-messagebus": "^3.6.0",
"react-beautiful-dnd": "^13.0.0"
},
"husky": {
"hooks": {
Expand Down Expand Up @@ -96,6 +101,9 @@
]
},
"jest": {
"globals": {
"__DEBUG__": false
},
"roots": [
"<rootDir>/src/",
"<rootDir>/test/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ const silkApi = {
},

transformTargetPropertyEndpoint: function(baseUrl: string, projectId: string, transformTaskId: string, ruleId: string,
searchTerm: string, maxResults: number, fullUris: boolean): string {
searchTerm: string | undefined, maxResults: number, fullUris: boolean): string {
const encodedSearchTerm = searchTerm ? encodeURIComponent(searchTerm) : ""
return `${baseUrl}/transform/tasks/${projectId}/${transformTaskId}/rule/${ruleId}/completions/targetProperties?term=${encodedSearchTerm}&maxResults=${maxResults}&fullUris=${fullUris}`
},
Expand Down
19 changes: 19 additions & 0 deletions workspace/src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,22 @@ import { configure } from "enzyme";
import Adapter from "enzyme-adapter-react-16";

configure({ adapter: new Adapter() });

if (window.document) {
(window.document.body as any).createTextRange = function() {
return {
setEnd: function(){},
setStart: function(){},
getBoundingClientRect: function(){
return {right: 0};
},
getClientRects: function(){
return {
length: 0,
left: 0,
right: 0
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import HierarchicalMapping from '../../src/HierarchicalMapping/HierarchicalMapping';
import HierarchicalMapping from '../../src/app/views/pages/MappingEditor/HierarchicalMapping/HierarchicalMapping';
import {URI} from "ecc-utils";


Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from "react";
import { shallow } from 'enzyme';
import AutoComplete from '../../../src/HierarchicalMapping/components/AutoComplete';
import AutoComplete from '../../../src/app/views/pages/MappingEditor/HierarchicalMapping/components/AutoComplete';
import { AutoCompleteField } from "@eccenca/gui-elements";

const props = {
input: 'text',
ruleId: 'rule',
};
const autocompleteAsyncMock = jest.fn();
jest.doMock('../../../src/HierarchicalMapping/store', () => autocompleteAsyncMock);
jest.doMock('../../../src/app/views/pages/MappingEditor/HierarchicalMapping/store', () => autocompleteAsyncMock);

const getWrapper = (renderer = shallow) => renderer(
<AutoComplete {...props} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ErrorCause,
ErrorIssue,
ErrorView
} from '../../../src/HierarchicalMapping/components/ErrorView';
} from '../../../src/app/views/pages/MappingEditor/HierarchicalMapping/components/ErrorView';
import {clickElement, logPageHtml, logWrapperHtml} from "../utils/TestHelpers";

const props = {
Expand Down Expand Up @@ -35,7 +35,7 @@ describe("ErrorView Component", () => {
clickElement(wrapper, "button")
expect(wrapper.find(ErrorCause)).toHaveLength(1);
});

it("should render ErrorIssue component, when `errorExpanded` and `props.issues` presented", () => {
const wrapper = getWrapper(mount, {
issues: [{
Expand All @@ -47,6 +47,6 @@ describe("ErrorView Component", () => {
clickElement(wrapper, "button")
expect(wrapper.find(ErrorIssue)).toHaveLength(1);
});

});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { shallow } from 'enzyme';
import MessageHandler from '../../../src/HierarchicalMapping/components/MessageHandler';
import MessageHandler from '../../../src/app/views/pages/MappingEditor/HierarchicalMapping/components/MessageHandler';
import { Alert, Error, Info, Success, Warning } from 'gui-elements-deprecated';


Expand All @@ -23,7 +23,7 @@ describe("MessageHandler Component", () => {
});
expect(wrapper.find(Alert)).toHaveLength(1);
});

it("should render Error component, when `errorType` is equal to `error`", () => {
const wrapper = getWrapper(shallow);
wrapper.setState({
Expand All @@ -36,7 +36,7 @@ describe("MessageHandler Component", () => {
});
expect(wrapper.find(Error)).toHaveLength(1);
});

it("should render Info component, when `errorType` is equal to `info`", () => {
const wrapper = getWrapper(shallow);
wrapper.setState({
Expand All @@ -49,7 +49,7 @@ describe("MessageHandler Component", () => {
});
expect(wrapper.find(Info)).toHaveLength(1);
});

it("should render Success component, when `errorType` is equal to `success`", () => {
const wrapper = getWrapper(shallow);
wrapper.setState({
Expand All @@ -62,7 +62,7 @@ describe("MessageHandler Component", () => {
});
expect(wrapper.find(Success)).toHaveLength(1);
});

it("should render Warning component, when `errorType` is equal to `warning`", () => {
const wrapper = getWrapper(shallow);
wrapper.setState({
Expand All @@ -75,6 +75,6 @@ describe("MessageHandler Component", () => {
});
expect(wrapper.find(Warning)).toHaveLength(1);
});

});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { shallow } from 'enzyme';
import { ParentElement } from '../../../src/HierarchicalMapping/components/ParentElement';
import { ThingName } from '../../../src/HierarchicalMapping/components/ThingName';
import { ParentElement } from '../../../src/app/views/pages/MappingEditor/HierarchicalMapping/components/ParentElement';
import { ThingName } from '../../../src/app/views/pages/MappingEditor/HierarchicalMapping/components/ThingName';



Expand All @@ -20,7 +20,7 @@ describe("ParentElement Component", () => {
});
expect(wrapper.find(ThingName)).toHaveLength(1);
});

it("should render html span element, when `type` is NOT presented in `parent` prop", () => {
const wrapper = getWrapper(shallow, {
parent: {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react";
import { shallow } from 'enzyme';
import { ThingName } from '../../../src/HierarchicalMapping/components/ThingName';
import { ParentStructure } from '../../../src/HierarchicalMapping/components/ParentStructure';
import { ParentElement } from '../../../src/HierarchicalMapping/components/ParentElement';
import { ThingName } from '../../../src/app/views/pages/MappingEditor/HierarchicalMapping/components/ThingName';
import { ParentStructure } from '../../../src/app/views/pages/MappingEditor/HierarchicalMapping/components/ParentStructure';
import { ParentElement } from '../../../src/app/views/pages/MappingEditor/HierarchicalMapping/components/ParentElement';



Expand All @@ -21,7 +21,7 @@ describe("ParentStructure Component", () => {
});
expect(wrapper.find(ThingName)).toHaveLength(1);
});

it("should render ParentElement component, when `property` is NOT presented in `parent` prop", () => {
const wrapper = getWrapper(shallow, {
parent: {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { shallow } from 'enzyme';
import { SourcePath } from '../../../src/HierarchicalMapping/components/SourcePath';
import { SourcePath } from '../../../src/app/views/pages/MappingEditor/HierarchicalMapping/components/SourcePath';
import { NotAvailable } from 'gui-elements-deprecated';


Expand All @@ -17,7 +17,7 @@ describe("SourcePath Component", () => {
});
expect(wrapper.find(NotAvailable)).toHaveLength(1);
});

it("should render NotAvailable component, when `sourcePath` is presented in `rule` prop", () => {
const wrapper = getWrapper(shallow, {
rule: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from "react";
import { shallow } from 'enzyme';
import { NotAvailable } from 'gui-elements-deprecated';
import { URIInfo } from '../../../src/HierarchicalMapping/components/URIInfo';
import { URIInfo } from '../../../src/app/views/pages/MappingEditor/HierarchicalMapping/components/URIInfo';

const getVocabInfoAsyncMock = jest.fn();

jest.doMock( '../../../src/HierarchicalMapping/store', () => getVocabInfoAsyncMock);
jest.doMock( '../../../src/app/views/pages/MappingEditor/HierarchicalMapping/store', () => getVocabInfoAsyncMock);
const props = {
uri: '<superUri>',
fallback: 'Fallback text',
Expand All @@ -24,15 +24,15 @@ describe("URIInfo Component", () => {
wrapper.setState({
info: 'Message'
});

expect(wrapper.find('span').text()).toEqual('Message')
});

it("should render fallback text, when text is NOT available from server", () => {
const wrapper = getWrapper(shallow);
expect(wrapper.find('span').text()).toEqual('Fallback text')
});

it("should render NotAvailable component, when fallback not available and `uri` in not string", () => {
const wrapper = getWrapper(shallow, {
...props,
Expand All @@ -41,7 +41,7 @@ describe("URIInfo Component", () => {
});
expect(wrapper.find(NotAvailable)).toHaveLength(1);
});

it("should render text from `uri`, when `props.field` equal to 'label'", () => {
const wrapper = getWrapper(shallow, {
...props,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
MenuItem,
} from 'gui-elements-deprecated';

import MappingHeader from '../../../src/HierarchicalMapping/containers/MappingHeader';
import ArrowBackButton from '../../../src/HierarchicalMapping/elements/buttons/ArrowBack';
import MappingHeader from '../../../src/app/views/pages/MappingEditor/HierarchicalMapping/containers/MappingHeader';
import ArrowBackButton from '../../../src/app/views/pages/MappingEditor/HierarchicalMapping/elements/buttons/ArrowBack';

const onRuleIdChangeFn = jest.fn();
const onToggleTreeNavFn = jest.fn();
Expand Down Expand Up @@ -41,15 +41,15 @@ describe("MappingHeader Component", () => {
beforeEach(() => {
wrapper = getWrapper(shallow);
});

it("should nothing rendered when rule is empty", () => {
const wrapper = getWrapper(shallow, {
...props,
rule: {}
});
expect(wrapper.get(0)).toBeFalsy();
});

it("should render ArrowBackButton, when parent is presented in breadcrumbs", () => {
const wrapper = getWrapper(shallow, {
...props,
Expand All @@ -65,7 +65,7 @@ describe("MappingHeader Component", () => {
});
expect(wrapper.find(ArrowBackButton)).toHaveLength(1);
});

it("should render breadcrumb, when breadcrumbs presented", () => {
const wrapper = getWrapper(shallow, {
...props,
Expand All @@ -81,22 +81,22 @@ describe("MappingHeader Component", () => {
});
expect(wrapper.find(BreadcrumbItem)).toHaveLength(2);
});

it("should menu items rendered", () => {
expect(wrapper.find(MenuItem)).toHaveLength(3);
});

afterEach(() => {
wrapper.unmount();
})
});

describe('on user interaction', () => {
let wrapper;
beforeEach(() => {
wrapper = getWrapper(shallow);
});

it('should ArrowBackButton navigate back', () => {
const wrapper = getWrapper(mount, {
...props,
Expand All @@ -114,7 +114,7 @@ describe("MappingHeader Component", () => {
wrapper.find(selectors.BACK_BTN).simulate('click');
expect(onRuleIdChangeFn).toBeCalledWith({ newRuleId: 'root', parentId: 'children' })
});

it('should BreadCrumb navigate the page', () => {
const wrapper = getWrapper(mount, {
...props,
Expand All @@ -132,25 +132,25 @@ describe("MappingHeader Component", () => {
wrapper.find(selectors.BREADCRUMB_ITEM).last().simulate('click');
expect(onRuleIdChangeFn).toBeCalledWith({ newRuleId: 'someId', parentId: 'root' })
});

it('should tree navigation collapse when click on button', () => {
const wrapper = getWrapper(mount);
wrapper.find(selectors.TREE_NAV).first().simulate('click');
expect(onToggleTreeNavFn).toBeCalled()
});

it('should expand all button working correctly', () => {
const wrapper = getWrapper(mount);
wrapper.find(selectors.EXPAND_ALL_BTN).first().simulate('click');
expect(onToggleDetailsFn).toBeCalledWith({expanded: true})
});

it('should reduce all button working correctly', () => {
const wrapper = getWrapper(mount);
wrapper.find(selectors.REDUCE_ALL_BTN).first().simulate('click');
expect(onToggleDetailsFn).toBeCalledWith({expanded: false})
});

afterEach(() => {
wrapper.unmount();
})
Expand Down
Loading

0 comments on commit ff8a04a

Please sign in to comment.