Skip to content

PB-1263: add handleLegacyParam function tests#1161

Merged
sommerfe merged 1 commit intodevelopfrom
feat-pb-1263-add-handlelegacyparam-function-tests
Jan 6, 2025
Merged

PB-1263: add handleLegacyParam function tests#1161
sommerfe merged 1 commit intodevelopfrom
feat-pb-1263-add-handlelegacyparam-function-tests

Conversation

@sommerfe
Copy link
Contributor

@sommerfe sommerfe commented Dec 5, 2024

@sommerfe sommerfe self-assigned this Dec 5, 2024
@cypress
Copy link

cypress bot commented Dec 5, 2024

web-mapviewer    Run #4190

Run Properties:  status check passed Passed #4190  •  git commit 9ee9052313: Merge pull request #1161 from geoadmin/feat-pb-1263-add-handlelegacyparam-functi...
Project web-mapviewer
Branch Review develop
Run status status check passed Passed #4190
Run duration 01m 43s
Commit git commit 9ee9052313: Merge pull request #1161 from geoadmin/feat-pb-1263-add-handlelegacyparam-functi...
Committer Felix Sommer
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 1
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 48
View all changes introduced in this branch ↗︎

@sommerfe sommerfe force-pushed the feat-pb-1263-add-handlelegacyparam-function-tests branch 3 times, most recently from 02a0ea4 to 305f1f6 Compare December 9, 2024 09:57
@sommerfe sommerfe requested review from ltkum and pakb December 9, 2024 10:08
@sommerfe sommerfe marked this pull request as ready for review December 9, 2024 10:08
Copy link
Contributor

@pakb pakb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for if tests are covering sufficient ground, I'll let @ltkum gives his opinion on the matter as he was the one writing most of it

@sommerfe sommerfe force-pushed the feat-pb-1263-add-handlelegacyparam-function-tests branch 7 times, most recently from 591755d to 154de0a Compare December 18, 2024 14:46
Copy link
Contributor

@ltkum ltkum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good foundation, but I think we can simplify this a bit, and also extend the coverage at the same time

newValue = LV95.transformCustomZoomLevelToStandard(legacyValue)
if (projection instanceof CustomCoordinateSystem) {
newValue = projection.transformStandardZoomLevelToCustom(newValue)
newValue = projection.transformStandardZoomLevelToCustom(newValue) // FIXME: the function transformStandardZoomLevelToCustom is not implemented in CustomCoordinateSystem
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently in the mapviewer, we have the following coordinates systems :
LV95 & LV03 : swissCoordinatesSystems which inherits CustomCoordinateSystem, and in which the function is implemented
WGS84 & webmercator which inherits StandardCoordinateSystem
We should not call for the function outside of a specific projection. I would remove this FIXME.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do i understand this right, that this function will never be called ? so then we should remove either the whole if statement or replace this function call directly with a throw Error call

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function will never be called in the current implementation of the mapviewer. There might be a day where we have a Coordinate System which would be both custom, and not swiss. I would at least add a comment for this , and maybe @pakb has another idea for further mitigation.

Regarding the throw Error call, that is the basic function implementation, so this is currently the case: if we reach this place, something went very wrong and it will throw an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so I removed the FIXME comment, so it is like it was before. But I can add a comment saying that this case should never be called in theory

Comment on lines +131 to +104
it('N', () => {
const param = 'N'
const legacyCoordinates = [0, 0]
handleLegacyParams({ param, legacyCoordinates })

expect(legacyCoordinates).to.deep.equal([0, legacyValue])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can also work if the array is still empty, and we should make sure it works in both case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so if legacyCoordinates = []
then the result is [ undefined, 10 ]
is this valid ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it is ['undefined', 10], as when I tried it quickly it gave me in the console something of the form : [, 10], but if you do legacyCoordinates[0], it should give you undefined, yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it and it fills the index 0 with undefined, how did you get [, 10] ? is this an empty string then or what is at index 0
so should i add a test to see if the result is [undefined, 10] ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it in a quick js codepen, and it gave me [ <1 empty item>, 10 ] as a result. Maybe it's an implementation of the codepen to show undefined items in such a way (for example if I had put the coordinates at arrray[250]).

I would test that the result is indeed [undefined, 10]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok i'll test this thanks

Comment on lines +220 to +188
const layerVisibility = 'layers_visibility'
const layerOpacity = 'layers_opacity'
const layerTimestamp = 'layers_timestamp'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we want to check it's transformed correctly, we should also make tests which checks that the values are transformed correctly. This means :
we need to set the visibility to 'true'
we need to check that if we set the opacity to a valid value (a value between 0 and 1 as a string)
we need to add a timeConfig to the layerConfig and a timestamp to check that it can be added to the layer

but it is also good to check that if we set invalid values, it work as expected and ignores those values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this has to be done in a unit test of the transformLayerIntoUrlString function and does not belong to this test
do you want me to create also a unit test for the transformLayerIntoUrlString function ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, handleLegacyParameter uses transformLayerIntoUrlString anyway, but we should also test the transformLayerIntoUrlString if it's not already tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i just saw that transformLayerIntoUrlString is already tested in the layersParamParser.spec.js unit test. So i think there is nothing else to do

@sommerfe sommerfe force-pushed the feat-pb-1263-add-handlelegacyparam-function-tests branch 2 times, most recently from ad67651 to c607a7a Compare December 20, 2024 08:18
@sommerfe sommerfe requested a review from ltkum December 20, 2024 08:18
@sommerfe sommerfe force-pushed the feat-pb-1263-add-handlelegacyparam-function-tests branch 2 times, most recently from a34d7f9 to 4d2fc45 Compare January 6, 2025 08:46
Copy link
Contributor

@ltkum ltkum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please quickly change the comment to reflect the situation, but I don't want you to be blocked by it. Once it's done and the tests passes, you can merge :)

good job

if (!(projection instanceof SwissCoordinateSystem)) {
newValue = LV95.transformCustomZoomLevelToStandard(legacyValue)
if (projection instanceof CustomCoordinateSystem) {
// Currently ther is no SwissCoordinateSystem which is also a CustomCoordinateSystem so this case should never be reached
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be
// Currently, there is no CustomCoordinateSystem which is not a SwissCoordinateSystem, so this case should never be reached.

@sommerfe sommerfe force-pushed the feat-pb-1263-add-handlelegacyparam-function-tests branch from 4d2fc45 to af1b597 Compare January 6, 2025 14:59
@sommerfe sommerfe force-pushed the feat-pb-1263-add-handlelegacyparam-function-tests branch from af1b597 to 00c562a Compare January 6, 2025 15:11
@sommerfe sommerfe merged commit 9ee9052 into develop Jan 6, 2025
@sommerfe sommerfe deleted the feat-pb-1263-add-handlelegacyparam-function-tests branch January 6, 2025 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants