Skip to content

Commit

Permalink
Add unit tests and reduced error cases
Browse files Browse the repository at this point in the history
  • Loading branch information
offtherailz committed Nov 27, 2024
1 parent 1b98005 commit 6fe416f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('wpsChart enhancer', () => {
document.body.innerHTML = '';
setTimeout(done);
});
it('wpsChart data retrival', (done) => {
it('wpsCounter data retrieval', (done) => {
const Sink = wpsCounter(createSink( ({data, loading} = {}) => {
if (!loading) {
expect(data).toExist();
Expand All @@ -44,7 +44,7 @@ describe('wpsChart enhancer', () => {
};
ReactDOM.render(<Sink {...props} />, document.getElementById("container"));
});
it('wpsChart error management', (done) => {
it('wpsCounter error management', (done) => {
const Sink = wpsCounter(createSink( ({error, loading} = {}) => {
if (!loading && error) {
expect(error).toExist();
Expand All @@ -64,4 +64,28 @@ describe('wpsChart enhancer', () => {
};
ReactDOM.render(<Sink {...props} />, document.getElementById("container"));
});
it('wpsCounter with mapSync and dependencies', (done) => {
const Sink = wpsCounter(createSink( ({data, loading} = {}) => {
if (!loading) {
expect(data).toExist();
done();
}
}));
const props = {
mapSync: true,
dependencies: {
viewport: "..."
},
layer: {
name: "test",
url: 'base/web/client/test-resources/widgetbuilder/aggregate',
wpsUrl: 'base/web/client/test-resources/widgetbuilder/aggregate',
search: {url: 'base/web/client/test-resources/widgetbuilder/aggregate'}},
options: {
aggregateFunction: "Count",
aggregationAttribute: "test"
}
};
ReactDOM.render(<Sink {...props} />, document.getElementById("container"));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,28 @@ describe('triggerFetch stream', () => {
}
);
});
it('triggerFetch with mapSync and dependencies.viewport', (done) => {
const base = {
layer: { name: "TEST" },
mapSync: true
};
const propsChanges = [
base, // does not trigger fetch
{...base, dependencies: { viewport: true }}, // triggers fetch (p1)
{...base, dependencies: { viewport: false }}, // does not trigger fetch
{...base, mapSync: false, filter: "changed"} // triggers fetch (p2) (the filter changes due to the viewport)
];
triggerFetch(Rx.Observable.from(propsChanges))
.bufferCount(4)
.subscribe(
([p1, p2, p3, p4]) => {
expect(p1?.dependencies?.viewport).toBe(true);
expect(p2).toExist();
expect(p3).toNotExist();
expect(p4).toNotExist();
done();
}
);
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default ($props) =>
// Check if mapSync is enabled (true) and dependencies.viewport is null or falsy
// If this condition is true, return false to filter out the event.
// This prevents an extra API call from being triggered when the viewport is not available.
if (mapSync && !dependencies.viewport) {
if (mapSync && !dependencies?.viewport) {
return false;
}
return layer.name;
Expand Down
2 changes: 1 addition & 1 deletion web/client/components/widgets/enhancers/wpsCounter.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const dataStreamFactory = ($props) =>
// Check if mapSync is enabled (true) and dependencies.viewport is null or falsy
// If this condition is true, return false to filter out the event.
// This prevents an extra API call from being triggered when the viewport is not available.
if (mapSync && !dependencies.viewport) {
if (mapSync && !dependencies?.viewport) {
return false;
}
return layer.name && getWpsUrl(layer) && options && options.aggregateFunction && options.aggregationAttribute;
Expand Down

0 comments on commit 6fe416f

Please sign in to comment.