-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: post mode identifier * refactor: types * fix: erro no typescript * fix: post mode identifier * fix: trocado set por array * fix: bug ao marcar postmode em outras contas * fix: adicionado cor no global * feat: testes * feat: stories * fix: conflitos no git * fix: post mode identifier * fix: adicionado cor no global * feat: testes * fix: responsivo * refactor: postMode component * refactor: removido throw error nos testes * refactor: ajustes com o novo tabber * fix: scroll * fix: post mode design * fix: stylelint
- Loading branch information
1 parent
a28d6c8
commit d8de648
Showing
9 changed files
with
371 additions
and
32 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions
28
src/pages/home/components/Tabber/PostModes/PostModes.components.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,28 @@ | ||
import { ReactNode } from 'react'; | ||
|
||
import { Checkbox } from '~components/Checkbox/Checkbox'; | ||
|
||
import { PostModeProps } from './PostModes.types'; | ||
|
||
export function PostMode(props: PostModeProps): ReactNode { | ||
const handlePostModeClick = (postModeElement: HTMLElement): void => { | ||
props.onClickPostMode(postModeElement); | ||
}; | ||
|
||
return ( | ||
<button | ||
className={props.postModeClasses(props.postMode.id)} | ||
onClick={(e) => { | ||
props.changePostMode(props.postMode.id); | ||
handlePostModeClick(e.currentTarget); | ||
}} | ||
> | ||
<Checkbox | ||
aria-label={`Check the post mode ${props.postMode.name}`} | ||
checked={props.isChecked(props.postMode.id)} | ||
onChange={(checked) => props.changeCheckBox(props.postMode.id, checked)} | ||
/> | ||
{props.postMode.name} | ||
</button> | ||
); | ||
} |
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
132 changes: 132 additions & 0 deletions
132
src/pages/home/components/Tabber/PostModes/PostModes.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,132 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import { | ||
mockedAccounts, | ||
mockedAddAccount, | ||
mockedSocialMedias, | ||
mockedUseSocialMediaStore, | ||
} from '~stores/__mocks__/useSocialMediaStore.mock'; | ||
|
||
import PostModes from './PostModes'; | ||
|
||
vi.mock( | ||
'~stores/useSocialMediaStore/useSocialMediaStore', | ||
() => mockedUseSocialMediaStore | ||
); | ||
|
||
const mockAccount = { | ||
id: '1', | ||
socialMediaId: 'DISCORD_EXAMPLE_ID', | ||
}; | ||
const mockChangePostMode = vi.fn(); | ||
const mockCurrentPostModeId = '1'; | ||
|
||
describe('PostModes', () => { | ||
beforeEach(() => { | ||
vi.spyOn( | ||
mockedUseSocialMediaStore, | ||
'useSocialMediaStore' | ||
).mockImplementation(() => ({ | ||
accounts: mockedAccounts(), | ||
addAccount: mockedAddAccount, | ||
socialMedias: mockedSocialMedias(), | ||
})); | ||
}); | ||
|
||
it('renders correctly', () => { | ||
render( | ||
<PostModes | ||
changePostModeId={mockChangePostMode} | ||
postId={mockAccount.id} | ||
postModeId={mockCurrentPostModeId} | ||
socialMediaId={mockAccount.socialMediaId} | ||
/> | ||
); | ||
const socialMedia = mockedSocialMedias().get(mockAccount.socialMediaId); | ||
|
||
const postModes = socialMedia?.postModes; | ||
const firstPostModeName = postModes ? postModes[0].name : ''; | ||
|
||
const postMode = screen.getByText(firstPostModeName); | ||
|
||
expect(postMode).toBeInTheDocument(); | ||
}); | ||
|
||
describe('PostModes button', () => { | ||
it('calls onChangePostMode when is clicked', async () => { | ||
render( | ||
<PostModes | ||
changePostModeId={mockChangePostMode} | ||
postId={mockAccount.id} | ||
postModeId={mockCurrentPostModeId} | ||
socialMediaId={mockAccount.socialMediaId} | ||
/> | ||
); | ||
const user = userEvent.setup(); | ||
|
||
const socialMedia = mockedSocialMedias().get(mockAccount.socialMediaId); | ||
|
||
const postModes = socialMedia?.postModes; | ||
const firstPostModeName = postModes ? postModes[0].name : ''; | ||
|
||
const postMode = screen.getByText(firstPostModeName); | ||
|
||
await user.click(postMode); | ||
expect(mockChangePostMode).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('PostModes checkbox', () => { | ||
it('add post mode when checkbox is checked', async () => { | ||
render( | ||
<PostModes | ||
changePostModeId={mockChangePostMode} | ||
postId={mockAccount.id} | ||
postModeId={mockCurrentPostModeId} | ||
socialMediaId={mockAccount.socialMediaId} | ||
/> | ||
); | ||
const user = userEvent.setup(); | ||
|
||
const socialMedia = mockedSocialMedias().get(mockAccount.socialMediaId); | ||
|
||
const postModes = socialMedia?.postModes; | ||
const firstPostModeName = postModes ? postModes[0].name : ''; | ||
|
||
const postModeCheckbox = screen.getByLabelText( | ||
`Check the post mode ${firstPostModeName}` | ||
); | ||
|
||
await user.click(postModeCheckbox); | ||
|
||
expect(postModeCheckbox).toBeChecked(); | ||
}); | ||
|
||
it('remove post mode when checkbox is not checked', async () => { | ||
render( | ||
<PostModes | ||
changePostModeId={mockChangePostMode} | ||
postId={mockAccount.id} | ||
postModeId={mockCurrentPostModeId} | ||
socialMediaId={mockAccount.socialMediaId} | ||
/> | ||
); | ||
const user = userEvent.setup(); | ||
|
||
const socialMedia = mockedSocialMedias().get(mockAccount.socialMediaId); | ||
|
||
const postModes = socialMedia?.postModes; | ||
const firstPostModeName = postModes ? postModes[0].name : ''; | ||
|
||
const postModeCheckbox = screen.getByLabelText( | ||
`Check the post mode ${firstPostModeName}` | ||
); | ||
|
||
await user.click(postModeCheckbox); | ||
await user.click(postModeCheckbox); | ||
|
||
expect(postModeCheckbox).not.toBeChecked(); | ||
}); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
src/pages/home/components/Tabber/PostModes/PostModes.stories.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,32 @@ | ||
import { useState } from 'react'; | ||
|
||
import { Story } from '@ladle/react'; | ||
|
||
import { PostMode } from '~services/api/social-media/social-media.types'; | ||
|
||
import PostModes from './PostModes'; | ||
|
||
const mock = { | ||
account: { | ||
id: '1', | ||
socialMediaId: 'DISCORD_EXAMPLE_ID', | ||
}, | ||
}; | ||
|
||
export const PostmodesStories: Story = () => { | ||
const [postModeOnView, setPostModeOnView] = useState( | ||
'DISCORD_STORY_POSTMODE_ID' | ||
); | ||
const changePostMode = (postModeId: PostMode['id']): void => { | ||
setPostModeOnView(postModeId); | ||
}; | ||
|
||
return ( | ||
<PostModes | ||
changePostModeId={changePostMode} | ||
postId={mock.account.id} | ||
postModeId={postModeOnView} | ||
socialMediaId={mock.account.socialMediaId} | ||
/> | ||
); | ||
}; |
Oops, something went wrong.