Skip to content

Commit

Permalink
#9205: Fix - Map details on context map intermittently disappears (#9337
Browse files Browse the repository at this point in the history
)
  • Loading branch information
dsuren1 authored Sep 11, 2023
1 parent 25b70d4 commit 1c385af
Show file tree
Hide file tree
Showing 6 changed files with 309 additions and 123 deletions.
105 changes: 102 additions & 3 deletions web/client/epics/__tests__/config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import expect from 'expect';
import {head} from 'lodash';
import {loadMapConfigAndConfigureMap, loadMapInfoEpic} from '../config';
import {loadMapConfigAndConfigureMap, loadMapInfoEpic, storeDetailsInfoEpic} from '../config';
import {LOAD_USER_SESSION} from '../../actions/usersession';
import {
loadMapConfig,
Expand All @@ -17,16 +17,19 @@ import {
LOAD_MAP_INFO,
MAP_INFO_LOADED,
MAP_INFO_LOAD_START,
loadMapInfo
loadMapInfo,
mapInfoLoaded
} from '../../actions/config';

import { testEpic } from './epicTestUtils';
import { TEST_TIMEOUT, addTimeoutEpic, testEpic } from './epicTestUtils';
import Persistence from '../../api/persistence';
import MockAdapter from 'axios-mock-adapter';
import axios from '../../libs/ajax';
import configBroken from "raw-loader!../../test-resources/testConfig.broken.json.txt";
import testConfigEPSG31468 from "raw-loader!../../test-resources/testConfigEPSG31468.json.txt";
import ConfigUtils from "../../utils/ConfigUtils";
import { DETAILS_LOADED } from '../../actions/details';
import { EMPTY_RESOURCE_VALUE } from '../../utils/MapInfoUtils';

const api = {
getResource: () => Promise.resolve({mapId: 1234})
Expand Down Expand Up @@ -280,5 +283,101 @@ describe('config epics', () => {
);
});
});
describe("storeDetailsInfoEpic", () => {
beforeEach(done => {
mockAxios = new MockAdapter(axios);
setTimeout(done);
});

afterEach(done => {
mockAxios.restore();
setTimeout(done);
});
const mapId = 1;
const map = {
id: mapId,
name: "name"
};
const mapAttributesEmptyDetails = {
"AttributeList": {
"Attribute": [
{
"name": "details",
"type": "STRING",
"value": EMPTY_RESOURCE_VALUE
}
]
}
};

const mapAttributesWithoutDetails = {
"AttributeList": {
"Attribute": []
}
};

const mapAttributesWithDetails = {
AttributeList: {
Attribute: [
{
name: 'details',
type: 'STRING',
value: 'rest\/geostore\/data\/1\/raw?decode=datauri'
},
{
name: "thumbnail",
type: "STRING",
value: 'rest\/geostore\/data\/1\/raw?decode=datauri'
},
{
name: 'owner',
type: 'STRING',
value: 'admin'
}
]
}
};
it('test storeDetailsInfoEpic', (done) => {
mockAxios.onGet().reply(200, mapAttributesWithDetails);
testEpic(addTimeoutEpic(storeDetailsInfoEpic), 1, mapInfoLoaded(map, mapId), actions => {
expect(actions.length).toBe(1);
actions.map((action) => {

switch (action.type) {
case DETAILS_LOADED:
expect(action.mapId).toBe(mapId);
expect(action.detailsUri).toBe("rest/geostore/data/1/raw?decode=datauri");
break;
default:
expect(true).toBe(false);
}
});
done();
}, {mapInitialConfig: {
"mapId": mapId
}});
});
it('test storeDetailsInfoEpic when api returns NODATA value', (done) => {
// const mock = new MockAdapter(axios);
mockAxios.onGet().reply(200, mapAttributesEmptyDetails);
testEpic(addTimeoutEpic(storeDetailsInfoEpic), 1, mapInfoLoaded(map, mapId), actions => {
expect(actions.length).toBe(1);
actions.map((action) => expect(action.type).toBe(TEST_TIMEOUT));
done();
}, {mapInitialConfig: {
"mapId": mapId
}});
});
it('test storeDetailsInfoEpic when api doesnt return details', (done) => {
mockAxios.onGet().reply(200, mapAttributesWithoutDetails);
testEpic(addTimeoutEpic(storeDetailsInfoEpic), 1, mapInfoLoaded(map, mapId), actions => {
expect(actions.length).toBe(1);
actions.map((action) => expect(action.type).toBe(TEST_TIMEOUT));
done();
}, {mapInitialConfig: {
"mapId": mapId
}});
});
});
});

75 changes: 2 additions & 73 deletions web/client/epics/__tests__/details-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,34 @@
*/

import expect from 'expect';
import axios from '../../libs/ajax';
import MockAdapter from 'axios-mock-adapter';
import configureMockStore from 'redux-mock-store';
import { createEpicMiddleware, combineEpics } from 'redux-observable';

import {
closeDetailsPanelEpic,
storeDetailsInfoEpic,
fetchDataForDetailsPanel
} from '../details';

import {
CLOSE_DETAILS_PANEL,
closeDetailsPanel,
openDetailsPanel,
UPDATE_DETAILS,
DETAILS_LOADED
UPDATE_DETAILS
} from '../../actions/details';
import { mapInfoLoaded } from '../../actions/config';

import { testEpic, addTimeoutEpic, TEST_TIMEOUT } from './epicTestUtils';
import { testEpic, addTimeoutEpic } from './epicTestUtils';
import ConfigUtils from '../../utils/ConfigUtils';
import { EMPTY_RESOURCE_VALUE } from '../../utils/MapInfoUtils';
import { SHOW_NOTIFICATION } from '../../actions/notifications';
import { TOGGLE_CONTROL, SET_CONTROL_PROPERTY } from '../../actions/controls';

const baseUrl = "base/web/client/test-resources/geostore/";
const mapId = 1;
const mapId2 = 2;
const detailsText = "<p>details of this map</p>";
const detailsUri = "data/2";
let map1 = {
id: mapId,
name: "name"
};
let map2 = {
id: mapId2,
name: "name2"
};
const testState = {
mapInitialConfig: {
mapId
Expand All @@ -63,24 +52,6 @@ const rootEpic = combineEpics(closeDetailsPanelEpic);
const epicMiddleware = createEpicMiddleware(rootEpic);
const mockStore = configureMockStore([epicMiddleware]);

const mapAttributesEmptyDetails = {
"AttributeList": {
"Attribute": [
{
"name": "details",
"type": "STRING",
"value": EMPTY_RESOURCE_VALUE
}
]
}
};

const mapAttributesWithoutDetails = {
"AttributeList": {
"Attribute": []
}
};

describe('details epics tests', () => {
const oldGetDefaults = ConfigUtils.getDefaults;
let store;
Expand Down Expand Up @@ -171,46 +142,4 @@ describe('details epics tests', () => {
}
});
});
it('test storeDetailsInfoEpic', (done) => {
testEpic(addTimeoutEpic(storeDetailsInfoEpic), 1, mapInfoLoaded(map2, mapId2), actions => {
expect(actions.length).toBe(1);
actions.map((action) => {
switch (action.type) {
case DETAILS_LOADED:
expect(action.mapId).toBe(mapId2);
expect(action.detailsUri).toBe("rest%2Fgeostore%2Fdata%2F3983%2Fraw%3Fdecode%3Ddatauri");
break;
default:
expect(true).toBe(false);
}
});
done();
}, {mapInitialConfig: {
"mapId": mapId2
}});
});
it('test storeDetailsInfoEpic when api returns NODATA value', (done) => {
const mock = new MockAdapter(axios);
mock.onGet().reply(200, mapAttributesEmptyDetails);
testEpic(addTimeoutEpic(storeDetailsInfoEpic), 1, mapInfoLoaded(map2, mapId2), actions => {
expect(actions.length).toBe(1);
actions.map((action) => expect(action.type).toBe(TEST_TIMEOUT));
mock.restore();
done();
}, {mapInitialConfig: {
"mapId": mapId2
}});
});
it('test storeDetailsInfoEpic when api doesnt return details', (done) => {
const mock = new MockAdapter(axios);
mock.onGet().reply(200, mapAttributesWithoutDetails);
testEpic(addTimeoutEpic(storeDetailsInfoEpic), 1, mapInfoLoaded(map2, mapId2), actions => {
expect(actions.length).toBe(1);
actions.map((action) => expect(action.type).toBe(TEST_TIMEOUT));
mock.restore();
done();
}, {mapInitialConfig: {
"mapId": mapId2
}});
});
});
Loading

0 comments on commit 1c385af

Please sign in to comment.