generated from xgeekshq/oss-template
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: team list refactor and tests (#1168)
Co-authored-by: Guido <stereopt@gmail.com>
- Loading branch information
1 parent
76551c0
commit ad585bc
Showing
19 changed files
with
169 additions
and
150 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
52 changes: 52 additions & 0 deletions
52
frontend/src/components/Teams/TeamsList/TeamsList.spec.tsx
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,52 @@ | ||
import { createMockRouter } from '@/utils/testing/mocks'; | ||
import { renderWithProviders } from '@/utils/testing/renderWithProviders'; | ||
import { TeamFactory } from '@/utils/factories/team'; | ||
import { fireEvent, waitFor } from '@testing-library/react'; | ||
import { ROUTES } from '@/utils/routes'; | ||
import TeamsList, { TeamsListProps } from '.'; | ||
|
||
const DEFAULT_PROPS = { | ||
teams: TeamFactory.createMany(3), | ||
}; | ||
|
||
const router = createMockRouter({ pathname: '/teams' }); | ||
|
||
jest.mock('next/router', () => ({ | ||
useRouter: () => router, | ||
})); | ||
|
||
const render = (props: TeamsListProps = DEFAULT_PROPS) => | ||
renderWithProviders(<TeamsList {...props} />, { routerOptions: router }); | ||
|
||
describe('Components/TeamsList', () => { | ||
let testProps: TeamsListProps; | ||
beforeEach(() => { | ||
testProps = { ...DEFAULT_PROPS }; | ||
}); | ||
|
||
it('should render correctly', () => { | ||
// Arrange | ||
const teamItemProps = { ...testProps }; | ||
|
||
// Act | ||
const { getAllByTestId } = render(teamItemProps); | ||
|
||
// Assert | ||
expect(getAllByTestId('teamItem')).toHaveLength(teamItemProps.teams.length); | ||
}); | ||
|
||
it('should render empty state correctly', async () => { | ||
// Arrange | ||
const teamItemProps = { ...testProps, teams: [] }; | ||
|
||
// Act | ||
const { getByTestId, getByText } = render(teamItemProps); | ||
fireEvent.click(getByText('Create your first team')); | ||
|
||
// Assert | ||
expect(getByTestId('emptyTeams')).toBeInTheDocument(); | ||
await waitFor(() => { | ||
expect(router.push).toHaveBeenCalledWith(ROUTES.NewTeam, ROUTES.NewTeam, expect.anything()); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,19 +1,25 @@ | ||
import React from 'react'; | ||
|
||
import { Team } from '@/types/team/team'; | ||
import Flex from '@/components/Primitives/Flex'; | ||
import EmptyTeams from './partials/EmptyTeams'; | ||
import ListOfCards from './partials/ListOfCards'; | ||
|
||
type TeamsListProps = { | ||
userId: string; | ||
import TeamItem from './TeamItem'; | ||
|
||
export type TeamsListProps = { | ||
teams: Team[]; | ||
isFetching: boolean; | ||
}; | ||
|
||
const TeamsList = ({ userId, teams, isFetching }: TeamsListProps) => { | ||
const TeamsList = ({ teams }: TeamsListProps) => { | ||
if (teams?.length === 0) return <EmptyTeams />; | ||
|
||
return <ListOfCards isLoading={isFetching} teams={teams} userId={userId} />; | ||
return ( | ||
<Flex direction="column" gap="8"> | ||
{teams.map((team: Team) => ( | ||
<TeamItem key={team.id} team={team} isTeamPage /> | ||
))} | ||
</Flex> | ||
); | ||
}; | ||
|
||
export default TeamsList; |
37 changes: 37 additions & 0 deletions
37
frontend/src/components/Teams/TeamsList/partials/EmptyTeams.tsx
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,37 @@ | ||
import { styled } from '@/styles/stitches/stitches.config'; | ||
import Link from 'next/link'; | ||
|
||
import Text from '@/components/Primitives/Text'; | ||
import Box from '@/components/Primitives/Box'; | ||
import Flex from '@/components/Primitives/Flex'; | ||
|
||
import EmptyTeamsImage from '@/components/images/EmptyTeams'; | ||
|
||
const StyledBox = styled(Flex, Box, { | ||
position: 'relative', | ||
borderRadius: '$12', | ||
backgroundColor: 'white', | ||
mt: '$14', | ||
p: '$48', | ||
}); | ||
|
||
const EmptyTeams = () => ( | ||
<StyledBox | ||
align="center" | ||
direction="column" | ||
elevation="1" | ||
justify="center" | ||
data-testid="emptyTeams" | ||
> | ||
<EmptyTeamsImage /> | ||
<Text css={{ mt: '$40', textAlign: 'center' }} size="md"> | ||
<Link href="/teams/new"> | ||
<Text link fontWeight="medium"> | ||
Create your first team | ||
</Text> | ||
</Link>{' '} | ||
now. | ||
</Text> | ||
</StyledBox> | ||
); | ||
export default EmptyTeams; |
19 changes: 0 additions & 19 deletions
19
frontend/src/components/Teams/TeamsList/partials/EmptyTeams/index.tsx
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
frontend/src/components/Teams/TeamsList/partials/EmptyTeams/styles.tsx
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
frontend/src/components/Teams/TeamsList/partials/ListOfCards/index.tsx
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
frontend/src/components/Teams/TeamsList/partials/ListOfCards/styles.tsx
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.