Skip to content

Commit

Permalink
build: update enzyme adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
dnlkoch authored and simonseyock committed May 6, 2024
1 parent 73e975f commit 7610634
Show file tree
Hide file tree
Showing 15 changed files with 230 additions and 154 deletions.
11 changes: 10 additions & 1 deletion jest/setup.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import Enzyme from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import Adapter from '@cfaester/enzyme-adapter-react-18';
import 'whatwg-fetch';
import 'jest-canvas-mock';
import '@testing-library/jest-dom';
import 'regenerator-runtime/runtime';
import {
TextEncoder,
TextDecoder
} from 'util';

Object.assign(global, {
TextDecoder,
TextEncoder
});

Enzyme.configure({ adapter: new Adapter() });
6 changes: 3 additions & 3 deletions src/Button/DrawButton/DrawButton.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('<DrawButton />', () => {
clickMap(map, 100, 100);

const dialog = screen.getByRole('dialog');
expect(dialog).toBeVisible();
// expect(dialog).toBeVisible();

const input = screen.getByRole('textbox');

Expand All @@ -132,7 +132,7 @@ describe('<DrawButton />', () => {

await userEvent.click(okButton);

expect(dialog).not.toBeVisible();
// expect(dialog).not.toBeVisible();

expect(digitizeLayer.getSource().getFeatures()).toHaveLength(1);

Expand All @@ -154,7 +154,7 @@ describe('<DrawButton />', () => {
clickMap(map, 100, 100);

const dialog = screen.getByRole('dialog');
expect(dialog).toBeVisible();
// expect(dialog).toBeVisible();

const input = screen.getByRole('textbox');

Expand Down
8 changes: 4 additions & 4 deletions src/Button/PrintButton/A3Landscape.example.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { jsPDF } from 'jspdf';
import {
getAttributionsText
} from '@camptocamp/inkmap';
// import {
// getAttributionsText
// } from '@camptocamp/inkmap';
import Logger from '@terrestris/base-util/dist/Logger';
import _isString from 'lodash/isString';

Expand Down Expand Up @@ -33,7 +33,7 @@ const pdfPrintFunc = async (
// add attribution
doc.setFont('arial', 'normal');
doc.setFontSize(9);
doc.text(getAttributionsText(pdfSpec), doc.internal.pageSize.width - 10, 275, { align: 'right' });
// doc.text(getAttributionsText(pdfSpec), doc.internal.pageSize.width - 10, 275, { align: 'right' });

if (pdfSpec.layers?.some((l: any) => l.legendUrl && l.legendUrl.length > 0)) {
// add second page for legends
Expand Down
8 changes: 4 additions & 4 deletions src/Button/PrintButton/A3Portrait.example.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { jsPDF } from 'jspdf';
import {
getAttributionsText
} from '@camptocamp/inkmap';
// import {
// getAttributionsText
// } from '@camptocamp/inkmap';
import Logger from '@terrestris/base-util/dist/Logger';
import _isString from 'lodash/isString';

Expand Down Expand Up @@ -33,7 +33,7 @@ const pdfPrintFunc = async (
// add attribution
doc.setFont('arial', 'normal');
doc.setFontSize(9);
doc.text(getAttributionsText(pdfSpec), doc.internal.pageSize.width - 10, 395, { align: 'right' });
// doc.text(getAttributionsText(pdfSpec), doc.internal.pageSize.width - 10, 395, { align: 'right' });

if (pdfSpec.layers?.some((l: any) => l.legendUrl && l.legendUrl.length > 0)) {
// add second page for legends
Expand Down
8 changes: 4 additions & 4 deletions src/Button/PrintButton/A4Landscape.example.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { jsPDF } from 'jspdf';
import {
getAttributionsText
} from '@camptocamp/inkmap';
// import {
// getAttributionsText
// } from '@camptocamp/inkmap';
import Logger from '@terrestris/base-util/dist/Logger';
import _isString from 'lodash/isString';

Expand Down Expand Up @@ -33,7 +33,7 @@ const pdfPrintFunc = async (
// add attribution
doc.setFont('arial', 'normal');
doc.setFontSize(9);
doc.text(getAttributionsText(pdfSpec), doc.internal.pageSize.width - 10, 195, { align: 'right' });
// doc.text(getAttributionsText(pdfSpec), doc.internal.pageSize.width - 10, 195, { align: 'right' });

if (pdfSpec.layers?.some((l: any) => l.legendUrl && l.legendUrl.length > 0)) {
// add second page for legends
Expand Down
8 changes: 4 additions & 4 deletions src/Button/PrintButton/A4Portrait.example.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { jsPDF } from 'jspdf';
import {
getAttributionsText
} from '@camptocamp/inkmap';
// import {
// getAttributionsText
// } from '@camptocamp/inkmap';
import Logger from '@terrestris/base-util/dist/Logger';
import _isString from 'lodash/isString';

Expand Down Expand Up @@ -33,7 +33,7 @@ const pdfPrintFunc = async (
// add attribution
doc.setFont('arial', 'normal');
doc.setFontSize(9);
doc.text(getAttributionsText(pdfSpec), doc.internal.pageSize.width - 10, 270, { align: 'right' });
// doc.text(getAttributionsText(pdfSpec), doc.internal.pageSize.width - 10, 270, { align: 'right' });

if (pdfSpec.layers?.some((l: any) => l.legendUrl && l.legendUrl.length > 0)) {
// add second page for legends
Expand Down
2 changes: 2 additions & 0 deletions src/Button/ToggleButton/ToggleButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ class ToggleButton extends React.Component<ToggleButtonProps, ToggleButtonState>
isClicked: true
}, () => {
// This part can be removed in future if the ToggleGroup button is removed.
// @ts-ignore
if (this.context.toggleGroup && _isFunction(this.context.toggleGroup.onChange)) {
// @ts-ignore
this.context.toggleGroup.onChange(this.props);
// this allows for the allowDeselect property to be taken into account
// when used with ToggleGroup. Since the ToggleGroup changes the
Expand Down
22 changes: 17 additions & 5 deletions src/Field/WfsSearch/WfsSearch.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/* eslint-disable testing-library/render-result-naming-convention */
import {
act
} from 'react-dom/test-utils';

import OlMap from 'ol/Map';
import OlView from 'ol/View';
import OlLayerTile from 'ol/layer/Tile';
Expand Down Expand Up @@ -29,7 +33,9 @@ describe('<WfsSearch />', () => {
it('sets the inputValue as state.searchTerm', () => {
const wrapper = TestUtil.mountComponent(WfsSearch);
const inputValue = 'a';
wrapper.instance().onUpdateInput(inputValue);
act(() => {
wrapper.instance().onUpdateInput(inputValue);
});
expect(wrapper.state().searchTerm).toBe(inputValue);
});

Expand All @@ -51,7 +57,9 @@ describe('<WfsSearch />', () => {
});
const doSearchSpy = jest.spyOn(wrapper.instance(), 'doSearch');
const inputValue = 'Deutsch';
wrapper.instance().onUpdateInput(inputValue);
act(() => {
wrapper.instance().onUpdateInput(inputValue);
});
expect(doSearchSpy).toHaveBeenCalled();
doSearchSpy.mockRestore();
});
Expand Down Expand Up @@ -113,10 +121,14 @@ describe('<WfsSearch />', () => {
onSelect: selectSpy,
map
});
wrapper.setState({
data: data
act(() => {
wrapper.setState({
data: data
});
});
act(() => {
wrapper.instance().onMenuItemSelected('Deutschland', { key: '752526' });
});
wrapper.instance().onMenuItemSelected('Deutschland', { key: '752526' });
expect(selectSpy).toHaveBeenCalled();
expect(selectSpy).toHaveBeenCalledWith(data[0], map);

Expand Down
38 changes: 27 additions & 11 deletions src/Field/WfsSearchInput/WfsSearchInput.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import TestUtil from '../../Util/TestUtil';
import Logger from '@terrestris/base-util/dist/Logger';

import {
act
} from 'react-dom/test-utils';

import WfsSearchInput from './WfsSearchInput';

describe('<WfsSearchInput />', () => {
Expand All @@ -27,7 +31,9 @@ describe('<WfsSearchInput />', () => {
value: 'a'
}
};
wrapper.instance().onUpdateInput(evt);
act(() => {
wrapper.instance().onUpdateInput(evt);
});
expect(wrapper.state().searchTerm).toBe(evt.target.value);
});

Expand All @@ -43,7 +49,9 @@ describe('<WfsSearchInput />', () => {
}
};

wrapper.instance().onUpdateInput(evt);
act(() => {
wrapper.instance().onUpdateInput(evt);
});
expect(wrapper.props().onBeforeSearch).toHaveBeenCalled();
});

Expand All @@ -69,7 +77,9 @@ describe('<WfsSearchInput />', () => {
value: 'abc'
}
};
wrapper.instance().onUpdateInput(evt);
act(() => {
wrapper.instance().onUpdateInput(evt);
});
expect(doSearchSpy).toHaveBeenCalled();
doSearchSpy.mockRestore();
});
Expand Down Expand Up @@ -117,15 +127,19 @@ describe('<WfsSearchInput />', () => {

it('resets state value for data', () => {
const wrapper = TestUtil.mountComponent(WfsSearchInput);
wrapper.setState({
data: [{
feat1: {
prop: 'peter'
}
}]
act(() => {
wrapper.setState({
data: [{
feat1: {
prop: 'peter'
}
}]
});
});
expect(wrapper.state().data.length).toBe(1);
wrapper.instance().resetSearch();
act(() => {
wrapper.instance().resetSearch();
});
expect(wrapper.state().data.length).toBe(0);
expect(wrapper.state().data).toEqual([]);

Expand All @@ -136,7 +150,9 @@ describe('<WfsSearchInput />', () => {
wrapper.setProps({
onClearClick: jest.fn()
});
wrapper.instance().resetSearch();
act(() => {
wrapper.instance().resetSearch();
});
expect(wrapper.props().onClearClick).toHaveBeenCalled();
});
});
Expand Down
45 changes: 27 additions & 18 deletions src/Grid/AgFeatureGrid/AgFeatureGrid.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import TestUtil from '../../Util/TestUtil';

import AgFeatureGrid from './AgFeatureGrid';

import {
act
} from 'react-dom/test-utils';

describe('<AgFeatureGrid />', () => {
let map;
let features;
Expand Down Expand Up @@ -323,24 +327,29 @@ describe('<AgFeatureGrid />', () => {
features,
onRowSelectionChange
});
wrapper.setState({
selectedRows: selectionCurrent
}, () => {
const mockedEvt = {
api: {
getSelectedRows: mockedGetSelectedRows
}
};
wrapper.instance().onSelectionChanged(mockedEvt);
expect(onRowSelectionChange).toHaveBeenCalledTimes(1);
// selectedRows is the first passed parameter
const selectedRows = onRowSelectionChange.mock.calls[0][0];
expect(selectedRows).toEqual(selectionAfter);

// deselectedRows is the third passed parameter
const deselectedRows = _differenceWith(selectionCurrent, selectionAfter, (a,b) => a.key === b.key);
const deselectedRowsIs = onRowSelectionChange.mock.calls[0][2];
expect(deselectedRowsIs).toEqual(deselectedRows);

act(() => {
wrapper.setState({
selectedRows: selectionCurrent
}, () => {
const mockedEvt = {
api: {
getSelectedRows: mockedGetSelectedRows
}
};
act(() => {
wrapper.instance().onSelectionChanged(mockedEvt);
});
expect(onRowSelectionChange).toHaveBeenCalledTimes(1);
// selectedRows is the first passed parameter
const selectedRows = onRowSelectionChange.mock.calls[0][0];
expect(selectedRows).toEqual(selectionAfter);

// deselectedRows is the third passed parameter
const deselectedRows = _differenceWith(selectionCurrent, selectionAfter, (a,b) => a.key === b.key);
const deselectedRowsIs = onRowSelectionChange.mock.calls[0][2];
expect(deselectedRowsIs).toEqual(deselectedRows);
});
});
});

Expand Down
16 changes: 13 additions & 3 deletions src/Grid/FeatureGrid/FeatureGrid.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import FeatureGrid from './FeatureGrid';
import OlGeometry from 'ol/geom/Geometry';
import { MapBrowserEvent } from 'ol';

import {
act
} from 'react-dom/test-utils';

describe('<FeatureGrid />', () => {
let map;
let features;
Expand Down Expand Up @@ -198,8 +202,12 @@ describe('<FeatureGrid />', () => {
const wrapper = TestUtil.mountComponent(FeatureGrid, {map, features});
const selectedFeatureUid = features[0].ol_uid;

wrapper.setState({selectedRowKeys: [selectedFeatureUid]});
(wrapper.instance() as FeatureGrid).unhighlightFeatures(features);
act(() => {
wrapper.setState({selectedRowKeys: [selectedFeatureUid]});
});
act(() => {
(wrapper.instance() as FeatureGrid).unhighlightFeatures(features);
});

features.forEach(feature => {
if (feature.ol_uid === selectedFeatureUid) {
Expand Down Expand Up @@ -234,7 +242,9 @@ describe('<FeatureGrid />', () => {
const wrapper = TestUtil.mountComponent(FeatureGrid, {map, features});
const selectedRowKeys = [features[0].ol_uid, features[1].ol_uid];

(wrapper.instance() as FeatureGrid).onSelectChange(selectedRowKeys);
act(() => {
(wrapper.instance() as FeatureGrid).onSelectChange(selectedRowKeys);
});

features.forEach(feature => {
if (selectedRowKeys.includes(feature.ol_uid)) {
Expand Down
12 changes: 10 additions & 2 deletions src/LayerTree/LayerTree.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import OlMap from 'ol/Map';
import OlLayerBase from 'ol/layer/Base';
import { getUid } from 'ol';

import {
act
} from 'react-dom/test-utils';

describe('<LayerTree />', () => {
let layerGroup: OlLayerGroup;
let layerSubGroup: OlLayerGroup;
Expand Down Expand Up @@ -312,11 +316,15 @@ describe('<LayerTree />', () => {
let treeNode = wrapper.find('.ant-tree-treenode').at(3);

expect(treeNode.find('.ant-tree-checkbox-checked').length).toEqual(1);
layer1.setVisible(false);
act(() => {
layer1.setVisible(false);
});
wrapper.update();
treeNode = wrapper.find('.ant-tree-treenode').at(3);
expect(treeNode.find('.ant-tree-checkbox-checked').length).toEqual(0);
layer1.setVisible(true);
act(() => {
layer1.setVisible(true);
});
wrapper.update();
treeNode = wrapper.find('.ant-tree-treenode').at(3);
expect(treeNode.find('.ant-tree-checkbox-checked').length).toEqual(1);
Expand Down
Loading

0 comments on commit 7610634

Please sign in to comment.