Skip to content

Commit

Permalink
(tests): edit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cmoinier committed Jul 27, 2023
1 parent 2a1ec01 commit 97b99a8
Showing 1 changed file with 33 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,35 @@ describe('FavoriteStarComponent', () => {
it('does not create tippy tooltip', () => {
expect(tippy).not.toHaveBeenCalled()
})

describe('on toggle state change', () => {
beforeEach(() => {
favoriteCountEl = fixture.debugElement.query(
By.css('.favorite-count')
).nativeElement
})
describe('if record is not part of favorite', () => {
beforeEach(() => {
;(favoritesService as any).myFavoritesUuid$.next([
component.record.uuid,
])
fixture.detectChanges()
describe('When I click on the star', () => {
// TEST THAT FUNCTIONS ARE CALLED
describe('When the record is already in favorites', () => {
beforeEach(() => {
;(favoritesService as any).myFavoritesUuid$.next([
component.record.uuid,
])
starToggle.newValue.emit(false)
fixture.detectChanges()
})
it('removes record from favorites', () => {
expect(favoritesService.removeFromFavorites).toHaveBeenCalledWith([
component.record.uuid,
])
expect(favoritesService.addToFavorites).not.toHaveBeenCalled()
})
})
describe('if change is made from this component', () => {
describe('When the record is not in favorites', () => {
beforeEach(() => {
;(favoritesService as any).myFavoritesUuid$.next([
component.record.uuid,
])
starToggle.newValue.emit(true)
fixture.detectChanges()
})
Expand All @@ -130,68 +144,38 @@ describe('FavoriteStarComponent', () => {
])
expect(favoritesService.removeFromFavorites).not.toHaveBeenCalled()
})
it('increase record favorite count by one', () => {
expect(favoriteCountEl.textContent).toEqual(
(component.record.favoriteCount + 1).toString()
)
})
it('adds the record to myFavoritesUuid$', async () => {
await expect(favoritesService.myFavoritesUuid$['_value'][0]).toBe(
component.record.uuid
)
})
})
describe('if change is made from another component', () => {
it('adds the record to myFavoritesUuid$', async () => {
await expect(favoritesService.myFavoritesUuid$['_value'][0]).toBe(
component.record.uuid
)
})
})
})
describe('if record is part of favorite', () => {
describe('When myFavoritesUuid has been updated', () => {
beforeEach(() => {
;(favoritesService as any).myFavoritesUuid$.next([
'aaa',
component.record.uuid,
])
fixture.detectChanges()
})
describe('if change is made from this component', () => {
// TEST THAT THE AMOUNT IS CORRECT
describe('When my record has been updated', () => {
beforeEach(() => {
component.record = {
...RECORDS_SUMMARY_FIXTURE[0],
favoriteCount: 42,
}
;(favoritesService as any).myFavoritesUuid$.next(['aaa'])
starToggle.newValue.emit(false)
fixture.detectChanges()
})
it('removes record from favorites', () => {
expect(favoritesService.removeFromFavorites).toHaveBeenCalledWith([
;(favoritesService as any).myFavoritesUuid$.next([
component.record.uuid,
])
expect(favoritesService.addToFavorites).not.toHaveBeenCalled()
fixture.detectChanges()
})
it('decrease record favorite count by one', () => {
it('increase record favorite count by one', () => {
expect(favoriteCountEl.textContent).toEqual(
(component.record.favoriteCount - 1).toString()
(component.record.favoriteCount + 1).toString()
)
})
})
describe('if change is made from another component', () => {
describe('When my record has not been updated', () => {
beforeEach(() => {
component.record = {
...RECORDS_SUMMARY_FIXTURE[0],
favoriteCount: 42,
}
;(favoritesService as any).myFavoritesUuid$.next(['aaa'])
fixture.detectChanges()
})
it('removes the record from myFavoritesUuid$', async () => {
await expect(
favoritesService.myFavoritesUuid$['_value'][0]
).not.toBe(component.record.uuid)
it('increase record favorite count by one', () => {
expect(favoriteCountEl.textContent).toEqual(
component.record.favoriteCount.toString()
)
})
})
})
Expand Down

0 comments on commit 97b99a8

Please sign in to comment.