-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show pinned collection relation (#4227)
- Loading branch information
Showing
15 changed files
with
297 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import styled from 'styled-components/native'; | ||
import Tag from './Tag'; | ||
import {CollectionIcon} from '../Icons'; | ||
|
||
const CollectionTag = styled(Tag).attrs({ | ||
LeftIcon: CollectionIcon, | ||
})({ | ||
backgroundColor: '#FDB', | ||
}); | ||
|
||
export default CollectionTag; |
119 changes: 119 additions & 0 deletions
119
client/src/lib/content/hooks/useGetCollectionByExerciseId.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import {renderHook} from '@testing-library/react-hooks'; | ||
import useGetCollectionById from './useGetCollectionById'; | ||
import usePinnedCollections from '../../user/hooks/usePinnedCollections'; | ||
import useGetCollectionByExerciseId from './useGetCollectionByExerciseId'; | ||
|
||
jest.mock('../../user/hooks/usePinnedCollections'); | ||
const mockUsePinnedCollections = usePinnedCollections as jest.Mock; | ||
mockUsePinnedCollections.mockReturnValue({ | ||
pinnedCollections: [], | ||
}); | ||
|
||
const mockGetExercisesByCollectionId = jest.fn(); | ||
jest.mock( | ||
'../../content/hooks/useGetExercisesByCollectionId', | ||
() => () => mockGetExercisesByCollectionId, | ||
); | ||
|
||
const mockUseGetCollectionById = jest.mocked(useGetCollectionById); | ||
const mockGetCollectionById = jest.fn(); | ||
mockUseGetCollectionById.mockReturnValue(mockGetCollectionById); | ||
jest.mock('./useGetCollectionById'); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('useGetCollectionByExerciseId', () => { | ||
it('returns collection if exercise is in pinned collection', () => { | ||
mockUsePinnedCollections.mockReturnValueOnce({ | ||
pinnedCollections: [{id: 'some-collection-id'}], | ||
}); | ||
mockGetExercisesByCollectionId.mockReturnValueOnce([ | ||
{id: 'some-exercise-id'}, | ||
]); | ||
mockGetCollectionById.mockReturnValueOnce({ | ||
id: 'some-collection-id', | ||
name: 'Some Collection', | ||
}); | ||
|
||
const {result} = renderHook(() => useGetCollectionByExerciseId()); | ||
|
||
const collection = result.current('some-exercise-id'); | ||
|
||
expect(mockGetExercisesByCollectionId).toHaveBeenCalledTimes(1); | ||
expect(mockGetExercisesByCollectionId).toHaveBeenCalledWith( | ||
'some-collection-id', | ||
); | ||
expect(mockGetCollectionById).toHaveBeenCalledTimes(1); | ||
expect(mockGetCollectionById).toHaveBeenCalledWith('some-collection-id'); | ||
expect(collection).toEqual({ | ||
id: 'some-collection-id', | ||
name: 'Some Collection', | ||
}); | ||
}); | ||
|
||
it('returns the first pinned collection', () => { | ||
mockUsePinnedCollections.mockReturnValueOnce({ | ||
pinnedCollections: [ | ||
{id: 'some-collection-id'}, | ||
{id: 'some-other-collection-id'}, | ||
], | ||
}); | ||
mockGetExercisesByCollectionId.mockReturnValueOnce([ | ||
{id: 'some-exercise-id'}, | ||
]); | ||
mockGetCollectionById.mockReturnValueOnce({ | ||
id: 'some-collection-id', | ||
name: 'Some Collection', | ||
}); | ||
|
||
const {result} = renderHook(() => useGetCollectionByExerciseId()); | ||
|
||
const collection = result.current('some-exercise-id'); | ||
|
||
expect(mockGetExercisesByCollectionId).toHaveBeenCalledTimes(1); | ||
expect(mockGetExercisesByCollectionId).toHaveBeenCalledWith( | ||
'some-collection-id', | ||
); | ||
expect(mockGetCollectionById).toHaveBeenCalledTimes(1); | ||
expect(mockGetCollectionById).toHaveBeenCalledWith('some-collection-id'); | ||
expect(collection).toEqual({ | ||
id: 'some-collection-id', | ||
name: 'Some Collection', | ||
}); | ||
}); | ||
|
||
it('returns undefined if no collections are pinned', () => { | ||
mockUsePinnedCollections.mockReturnValueOnce({ | ||
pinnedCollections: [], | ||
}); | ||
const {result} = renderHook(() => useGetCollectionByExerciseId()); | ||
|
||
const collection = result.current('some-exercise-id'); | ||
|
||
expect(mockGetExercisesByCollectionId).toHaveBeenCalledTimes(0); | ||
expect(mockGetCollectionById).toHaveBeenCalledTimes(0); | ||
expect(collection).toBeUndefined(); | ||
}); | ||
|
||
it("returns undefined if pinned collections don't include exercise", () => { | ||
mockUsePinnedCollections.mockReturnValueOnce({ | ||
pinnedCollections: [{id: 'some-collection-id'}], | ||
}); | ||
mockGetExercisesByCollectionId.mockReturnValueOnce([ | ||
{id: 'some-other-exercise-id'}, | ||
]); | ||
|
||
const {result} = renderHook(() => useGetCollectionByExerciseId()); | ||
|
||
const collection = result.current('some-exercise-id'); | ||
|
||
expect(mockGetExercisesByCollectionId).toHaveBeenCalledTimes(1); | ||
expect(mockGetExercisesByCollectionId).toHaveBeenCalledWith( | ||
'some-collection-id', | ||
); | ||
expect(mockGetCollectionById).toHaveBeenCalledTimes(0); | ||
expect(collection).toBeUndefined(); | ||
}); | ||
}); |
Oops, something went wrong.