Skip to content

Commit

Permalink
Fix: Correct failing test cases for zoom records issue in table widge…
Browse files Browse the repository at this point in the history
…ts (geosolutions-it#9567)

This commit addresses the failing test cases related to the issue of zoom records in table widgets.
  • Loading branch information
mahmoudadel54 committed Oct 16, 2023
1 parent 90ba37c commit 6b2667d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
7 changes: 1 addition & 6 deletions web/client/components/widgets/widget/DefaultWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import {connect} from 'react-redux';
import { createSelector } from 'reselect';
import {
ChartWidget,
CounterWidget,
Expand All @@ -16,7 +14,6 @@ import {
TextWidget,
LegendWidget
} from './enhancedWidgets';
import { isDashboardAvailable } from '../../../selectors/dashboard';

const getWidgetOpts = (w) => w?.widgetOpts?.[w.widgetType];

Expand All @@ -30,7 +27,6 @@ const DefaultWidget = ({
exportImage = () => {},
onDelete = () => {},
onEdit = () => {},
isDashboardOpened,
...w
} = {}) => w.widgetType === "text"
? (<TextWidget {...w}
Expand All @@ -45,7 +41,6 @@ const DefaultWidget = ({
dependencies={dependencies}
onDelete={onDelete}
onEdit={onEdit}
isDashboardOpened={isDashboardOpened}
/>
: w.widgetType === "counter"
? <CounterWidget {...w}
Expand Down Expand Up @@ -76,4 +71,4 @@ const DefaultWidget = ({
exportImage={exportImage}
onDelete={onDelete}
onEdit={onEdit} />);
export default connect(createSelector(isDashboardAvailable, (isDashboardOpened)=>({ isDashboardOpened })))(DefaultWidget);
export default DefaultWidget;
28 changes: 17 additions & 11 deletions web/client/components/widgets/widget/__tests__/TableWidget-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import ReactDOM from 'react-dom';
import ReactTestUtils from 'react-dom/test-utils';
import { compose, defaultProps } from 'recompose';
import { waitFor } from '@testing-library/react';
import {Provider} from 'react-redux';
import configureMockStore from 'redux-mock-store';

import describePois from '../../../../test-resources/wfs/describe-pois.json';
import museam from '../../../../test-resources/wfs/museam.json';
Expand All @@ -23,8 +25,12 @@ const TableWidget = compose(
tableWidget
)(TableWidgetComp);

const mockStore = configureMockStore();

describe('TableWidget component', () => {
let store;
beforeEach((done) => {
store = mockStore();
document.body.innerHTML = '<div id="container"></div>';
setTimeout(done);
});
Expand All @@ -34,15 +40,15 @@ describe('TableWidget component', () => {
setTimeout(done);
});
it('TableWidget rendering with defaults', () => {
ReactDOM.render(<TableWidget />, document.getElementById("container"));
ReactDOM.render(<Provider store={store}><TableWidget /></Provider>, document.getElementById("container"));
const container = document.getElementById('container');
const el = container.querySelector('.mapstore-widget-card');
expect(el).toExist();
expect(container.querySelector('.glyphicon-pencil')).toExist();
expect(container.querySelector('.glyphicon-trash')).toExist();
});
it('view only mode', () => {
ReactDOM.render(<TableWidget canEdit={false} />, document.getElementById("container"));
ReactDOM.render(<Provider store={store}><TableWidget canEdit={false} /></Provider>, document.getElementById("container"));
const container = document.getElementById('container');
expect(container.querySelector('.glyphicon-pencil')).toNotExist();
expect(container.querySelector('.glyphicon-trash')).toNotExist();
Expand All @@ -52,27 +58,27 @@ describe('TableWidget component', () => {
onEdit: () => { }
};
const spyonEdit = expect.spyOn(actions, 'onEdit');
ReactDOM.render(<TableWidget onEdit={actions.onEdit} />, document.getElementById("container"));
ReactDOM.render(<Provider store={store}><TableWidget onEdit={actions.onEdit} /></Provider>, document.getElementById("container"));
const container = document.getElementById('container');
const el = container.querySelector('.glyphicon-pencil');
ReactTestUtils.Simulate.click(el); // <-- trigger event callback
expect(spyonEdit).toHaveBeenCalled();
});
it('TableWidget loading', () => {
ReactDOM.render(<TableWidget loading />, document.getElementById("container"));
ReactDOM.render(<Provider store={store}><TableWidget loading /></Provider>, document.getElementById("container"));
const container = document.getElementById('container');
const el = container.querySelector('.loader-container');
expect(el).toExist();
});
it('TableWidget empty', (done) => {
ReactDOM.render(<TableWidget describeFeatureType={describePois} features={[]} />, document.getElementById("container"));
ReactDOM.render(<Provider store={store}><TableWidget describeFeatureType={describePois} features={[]} /></Provider>, document.getElementById("container"));
const container = document.getElementById('container');
waitFor(() =>expect( container.querySelector('.react-grid-Empty')).toBeTruthy())
.then(() => done());
});
it('TableWidget with default gridOpts', () => {
ReactDOM.render(<TableWidget
virtualScroll={false} describeFeatureType={describePois} enableColumnFilters features={museam.features}/>, document.getElementById("container"));
ReactDOM.render(<Provider store={store}><TableWidget
virtualScroll={false} describeFeatureType={describePois} enableColumnFilters features={museam.features}/></Provider>, document.getElementById("container"));
const gridHeaderRows = document.getElementsByClassName('react-grid-HeaderRow');
expect(gridHeaderRows.length).toBe(2);
const headerRowHeight = gridHeaderRows[0]?.getAttribute('height');
Expand All @@ -81,9 +87,9 @@ describe('TableWidget component', () => {
expect(Number(headerFiltersHeight)).toBe(28);
});
it('TableWidget with custom gridOpts', () => {
ReactDOM.render(<TableWidget
ReactDOM.render(<Provider store={store}><TableWidget
gridOpts={{ headerRowHeight: 35, headerFiltersHeight: 35}}
virtualScroll={false} describeFeatureType={describePois} enableColumnFilters features={museam.features}/>, document.getElementById("container"));
virtualScroll={false} describeFeatureType={describePois} enableColumnFilters features={museam.features}/></Provider>, document.getElementById("container"));
const gridHeaderRows = document.getElementsByClassName('react-grid-HeaderRow');
expect(gridHeaderRows.length).toBe(2);
const headerRowHeight = gridHeaderRows[0]?.getAttribute('height');
Expand All @@ -101,7 +107,7 @@ describe('TableWidget component', () => {
"localType": "number"
}]}]};
ReactTestUtils.act(()=>{
ReactDOM.render(<TableWidget enableColumnFilters id={1} updateProperty={(id, path, attribute)=>{
ReactDOM.render(<Provider store={store}><TableWidget enableColumnFilters id={1} updateProperty={(id, path, attribute)=>{
try {
expect(id).toBe(1);
expect(path).toBe("quickFilters.FLOAT");
Expand All @@ -113,7 +119,7 @@ describe('TableWidget component', () => {
done(e);
}
done();
}} describeFeatureType={_d} features={[]} />, document.getElementById("container"));
}} describeFeatureType={_d} features={[]} /></Provider>, document.getElementById("container"));
});
const container = document.getElementById('container');
const filterFields = container.querySelectorAll("input");
Expand Down
9 changes: 6 additions & 3 deletions web/client/plugins/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import {
dashboardResource,
isBrowserMobile,
isDashboardLoading,
showConnectionsSelector
showConnectionsSelector,
isDashboardAvailable
} from '../selectors/dashboard';
import { currentLocaleLanguageSelector, currentLocaleSelector } from '../selectors/locale';
import { isLocalizedLayerStylesEnabledSelector, localizedLayerStylesEnvSelector } from '../selectors/localizedLayerStyles';
Expand Down Expand Up @@ -65,8 +66,9 @@ const WidgetsView = compose(
localizedLayerStylesEnvSelector,
getMaximizedState,
currentLocaleSelector,
isDashboardAvailable,
(resource, widgets, layouts, dependencies, selectionActive, editingWidget, groups, showGroupColor, loading, isMobile, currentLocaleLanguage, isLocalizedLayerStylesEnabled,
env, maximized, currentLocale) => ({
env, maximized, currentLocale, isDashboardOpened) => ({
resource,
loading,
canEdit: isMobile ? !isMobile : resource && !!resource.canEdit,
Expand All @@ -80,7 +82,8 @@ const WidgetsView = compose(
language: isLocalizedLayerStylesEnabled ? currentLocaleLanguage : null,
env,
maximized,
currentLocale
currentLocale,
isDashboardOpened
})
), {
editWidget,
Expand Down
5 changes: 3 additions & 2 deletions web/client/plugins/DashboardEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { createPlugin } from '../utils/PluginsUtils';


import { dashboardHasWidgets, getWidgetsDependenciesGroups } from '../selectors/widgets';
import { isDashboardEditing, showConnectionsSelector, isDashboardLoading, buttonCanEdit } from '../selectors/dashboard';
import { isDashboardEditing, showConnectionsSelector, isDashboardLoading, buttonCanEdit, isDashboardAvailable } from '../selectors/dashboard';
import { dashboardSelector, dashboardsLocalizedSelector } from './widgetbuilder/commons';

import { createWidget, toggleConnection } from '../actions/widgets';
Expand Down Expand Up @@ -152,7 +152,8 @@ const Plugin = connect(
createSelector(
isDashboardEditing,
isDashboardLoading,
(editing, loading) => ({ editing, loading })
isDashboardAvailable,
(editing, loading, isDashboardOpened) => ({ editing, loading, isDashboardOpened })
), {
setEditing,
onMount: () => setEditorAvailable(true),
Expand Down

0 comments on commit 6b2667d

Please sign in to comment.