Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datahub: Favorite star bug on page change #533

Merged
merged 9 commits into from
Jul 28, 2023
Merged

Conversation

cmoinier
Copy link
Collaborator

@cmoinier cmoinier commented Jul 13, 2023

Thanks Tobias and Florent for the help!

JIRA ISSUE

https://jira.camptocamp.com/browse/GSHDF-679

DESCRIPTION

  • Permettre d'ajouter/supprimer un record des favoris
  • Permettre de garder ce favori en changeant d'onglet
  • Permettre de garder ce favori en allant sur la page du record

@github-actions
Copy link
Contributor

github-actions bot commented Jul 13, 2023

Affected libs: feature-search, feature-record, feature-router, feature-map, feature-dataviz,
Affected apps: metadata-editor, datahub, demo, webcomponents, search, map-viewer,

  • 🚀 Build and deploy storybook and demo on GitHub Pages
  • 📦 Build and push affected docker images

Copy link
Member

@fgravin fgravin left a comment

Choose a reason for hiding this comment

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

Great work thanks.
I have made some comments to make the logic clearer about what we are doing.

Also, I don't think that you properly test the new behavior.
You should add a couple of tests where the modifiedFavorites$ ticks

  • contains the component record
  • does not contain the component record

}
})
editedDs = []
})
}

ngOnDestroy(): void {
this.subscription.unsubscribe()
Copy link
Member

Choose a reason for hiding this comment

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

Usually, one subscription is enough, you could use subscription.add() to all subscribes that you want to unsubscribe from.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I did try that. For some reason the subscription isn't working (as in, nothing happens, no update on directly clicked record nor on the other page) unless it's in its own subscription. I agree this is not the best way.

Copy link
Member

Choose a reason for hiding this comment

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

It should work, what did you try ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Tried the normal way : this.subscription.add() on this.favoritesService.myFavoritesUuid$.pipe() ......

@fgravin fgravin changed the title GSHDF-679 : Favorite star bug on page change datahub: Favorite star bug on page change Jul 13, 2023
@cmoinier cmoinier requested a review from fgravin July 17, 2023 09:39
@cmoinier cmoinier assigned fgravin and unassigned cmoinier Jul 17, 2023
Copy link
Member

@fgravin fgravin left a comment

Choose a reason for hiding this comment

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

It works well like that thanks.
The test should be modified though, to play the new scenario, and test all the possibilities.

Thanks !

@fgravin fgravin assigned cmoinier and unassigned fgravin Jul 17, 2023
cmoinier and others added 2 commits July 17, 2023 18:50
…tar.component.ts


refactor pairwise logic

Co-authored-by: Florent Gravin <[email protected]>
)
})
it('adds the record to myFavoritesUuid$', async () => {
await expect(favoritesService.myFavoritesUuid$['_value'][0]).toBe(
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand what does this test actually test.
BTW, Observables are a flow and should not be tested as an instantaneous value (which is hacky cause it's not the public API).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It tests if the record is present in the myFavoriteUuid after the user clicks on the star. It's important especially when it ticks from another component.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, so how do I test if myFavoriteUuid properly recorded that the record is in the user's favorite? I didn't have any other idea

Copy link
Member

Choose a reason for hiding this comment

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

component.record.uuid = 'a'

  • myFavoriteUuid$.next(['b']) => nothing happens
  • myFavoriteUuid$.next(['a']) => the component is updated

Copy link
Member

Choose a reason for hiding this comment

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

It tests if the record is present in the myFavoriteUuid after the user clicks on the star. It's important especially when it ticks from another component.

yes but you did the myFavoritesUuid$.next([component.record.uuid]) in the beforeEach, which is exactly what you test in there.

])
expect(favoritesService.removeFromFavorites).not.toHaveBeenCalled()
})
it('increase record favorite count by one', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Damn I forgot to commit one comment

While this test is a consequence of myFavoritesUuid$ tick.
Both things are decorrelated and should be tested separatly.

When I click on the star => here you test that the functions have been called

  • When the record is already in favorite
  • When the record is not in favorites
    When favorites has been updated => here you test that the amount is correct
  • My record have been updated
  • My record haven't been updated

@fgravin fgravin linked an issue Jul 26, 2023 that may be closed by this pull request
@fgravin fgravin added this to the 1.1.0 milestone Jul 27, 2023
@fgravin fgravin added the bug Something isn't working label Jul 27, 2023
@fgravin fgravin assigned fgravin and unassigned cmoinier Jul 27, 2023
@fgravin
Copy link
Member

fgravin commented Jul 28, 2023

@cmoinier all the tests were there, thanks !
I have reworked the whole scenario to make it clearer, what we test and how.
There was a lot of useless statements in the beforeEach() as well

@fgravin fgravin self-requested a review July 28, 2023 10:08
@cmoinier cmoinier merged commit ba4b049 into main Jul 28, 2023
5 checks passed
@cmoinier
Copy link
Collaborator Author

Thanks for the rework @fgravin :)

Looks good to me, merging now.

@jahow jahow deleted the favorite-star-toggle branch August 14, 2023 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Datahub]: Favorites de-synchronization
2 participants