diff --git a/src/components/Accordion/Accordion.spec.tsx b/src/components/Accordion/Accordion.spec.tsx index 3ec94039c..ef429580c 100644 --- a/src/components/Accordion/Accordion.spec.tsx +++ b/src/components/Accordion/Accordion.spec.tsx @@ -20,12 +20,12 @@ const makeSut = ({ describe('Accordion', () => { describe('when isOpen is false', () => { - it('body cannot render', () => { + it('body is collapsed', () => { makeSut({ isOpen: false }); - const content = screen.queryByText('content'); + const contentWrapper = screen.getByTestId('accordion-content'); - expect(content).not.toBeInTheDocument(); + expect(contentWrapper).toHaveStyle('height: 0'); }); }); @@ -33,9 +33,9 @@ describe('Accordion', () => { it('body can render', () => { makeSut({ isOpen: true }); - const content = screen.getByText('content'); + const contentWrapper = screen.getByTestId('accordion-content'); - expect(content).toBeVisible(); + expect(contentWrapper).toHaveStyle('height: auto'); }); }); }); diff --git a/src/components/Accordion/Accordion.tsx b/src/components/Accordion/Accordion.tsx index 74e0f803e..c475ba2ce 100644 --- a/src/components/Accordion/Accordion.tsx +++ b/src/components/Accordion/Accordion.tsx @@ -7,29 +7,30 @@ import scss from './Accordion.module.scss'; import { TAccordionProps } from './Accordion.types'; -function computeVariants(duration: number): Record { - return { - collapsed: { height: 0, transition: { duration } }, - expanded: { height: 'auto', transition: { duration } }, - }; -} +const accordionVariants: Record = { + collapsed: { height: 0, opacity: 0 }, + expanded: { + height: 'auto', + opacity: 1, + }, +}; function Accordion({ duration = 0.3, ...props }: TAccordionProps): ReactNode { return (
{props.header}
- {props.isOpen ? ( - - {props.content} - - ) : null} + + {props.content} +
); diff --git a/src/components/MainComposer/MainComposer.module.scss b/src/components/MainComposer/MainComposer.module.scss index 1f62b9bfc..518433ae7 100644 --- a/src/components/MainComposer/MainComposer.module.scss +++ b/src/components/MainComposer/MainComposer.module.scss @@ -1,6 +1,2 @@ @use '~styles/global.scss'; @use '~styles/breakpoints.scss'; - -.container { - min-height: 40rem; -} diff --git a/src/pages/home/components/Sidebar/Sidebar.spec.tsx b/src/pages/home/components/Sidebar/Sidebar.spec.tsx index 70db3b7ec..428f64d2f 100644 --- a/src/pages/home/components/Sidebar/Sidebar.spec.tsx +++ b/src/pages/home/components/Sidebar/Sidebar.spec.tsx @@ -50,13 +50,13 @@ describe('Sidebar component', () => { for (var account in accounts) { const socialMedia = mockedSocialMedias().get(account); - const accordionEvidence = screen.getByText( + const accordionEvidence = screen.getAllByText( new RegExp(socialMedia?.name as string, 'i') ); - await userEvent.click(accordionEvidence); + await userEvent.click(accordionEvidence[0]); - expect(accordionEvidence).toBeInTheDocument(); + expect(accordionEvidence[0]).toBeInTheDocument(); } Object.values(accounts).forEach((values) => { @@ -176,16 +176,16 @@ describe('Sidebar component', () => { await userEvent.type(inputSearchComponent, 'Twitter'); - const discordAccordion = screen.getByText(/discord/i); - await waitForElementToBeRemoved(discordAccordion); + const discordAccordion = screen.getAllByText(/discord/i); + await waitForElementToBeRemoved(discordAccordion[0]); - const accordion = screen.getByText(/twitter/i); - await userEvent.click(accordion); + const accordions = screen.getAllByText(/twitter/i); + await userEvent.click(accordions[0]); const evidence = screen.getByText('Twitter User 14'); expect(evidence).toBeInTheDocument(); - expect(discordAccordion).not.toBeInTheDocument(); + expect(discordAccordion[0]).not.toBeInTheDocument(); }); it('and theres no results', async () => { diff --git a/src/pages/home/components/Sidebar/components/SocialAccordion/SocialAccordion.spec.tsx b/src/pages/home/components/Sidebar/components/SocialAccordion/SocialAccordion.spec.tsx index ced1408f7..6684702f9 100644 --- a/src/pages/home/components/Sidebar/components/SocialAccordion/SocialAccordion.spec.tsx +++ b/src/pages/home/components/Sidebar/components/SocialAccordion/SocialAccordion.spec.tsx @@ -36,9 +36,9 @@ describe('SocialAccordion', () => { title={mockedSocialMedias().get(socialMediaId)?.name as string} /> ); - const accordion = screen.getByText(/discord/i); + const accordion = screen.getAllByText(/discord/i); - expect(accordion).toBeInTheDocument(); + expect(accordion[0]).toBeInTheDocument(); }); it('renders the intern content of accordion when is open', async () => { @@ -52,11 +52,9 @@ describe('SocialAccordion', () => { /> ); - const accordion = screen.getByText(/discord/i); + const accordion = screen.getAllByText(/discord/i); - await act(async () => { - await userEvent.click(accordion); - }); + await userEvent.click(accordion[0]); const innerContent = screen.getByText(mockDiscordData[0].userName); @@ -91,14 +89,8 @@ describe('SocialAccordion', () => { /> ); - const [account] = mockDiscordData; - const socialMedias = mockedSocialMedias().get(account.socialMediaId); - - const accordion = screen.getByText(/discord/i); - - await act(async () => { - await userEvent.click(accordion); - }); + const accordion = screen.getAllByText(/discord/i); + await userEvent.click(accordion[0]); const [firstAccountSwitch] = screen.getAllByRole('checkbox'); @@ -125,10 +117,8 @@ describe('SocialAccordion', () => { /> ); - const accordion = screen.getByText(/discord/i); - await act(async () => { - await userEvent.click(accordion); - }); + const accordion = screen.getAllByText(/discord/i); + await userEvent.click(accordion[0]); const [firstAccountSwitch] = screen.getAllByRole('checkbox'); @@ -141,7 +131,7 @@ describe('SocialAccordion', () => { }); }); - describe('when click 2 times', () => { + describe('when clicked 2 times', () => { it('closes the accordion', async () => { const socialMediaId = 'DISCORD_EXAMPLE_ID'; @@ -153,22 +143,19 @@ describe('SocialAccordion', () => { /> ); - const accordion = screen.getByText(/discord/i); + const contentWrapper = screen.getByTestId('accordion-content'); + const toggleAccordion = screen.getByTestId('accordion-toggle-button'); - await act(async () => { - await userEvent.click(accordion); - }); - - const innerContent = screen.getByText(mockDiscordData[0].userName); - - expect(innerContent).toBeInTheDocument(); + await userEvent.click(toggleAccordion); - await act(async () => { - await userEvent.click(accordion); + await waitFor(() => { + expect(contentWrapper).toHaveStyle('opacity: 1'); }); + await userEvent.click(toggleAccordion); + await waitFor(() => { - expect(innerContent).not.toBeInTheDocument(); + expect(contentWrapper).toHaveStyle('opacity: 0'); }); }); }); @@ -201,9 +188,9 @@ describe('SocialAccordion', () => { /> ); - const accountQuantity = screen.getByText(/1/); + const accountQuantity = screen.getAllByText(/1/); - expect(accountQuantity).toBeInTheDocument(); + expect(accountQuantity[0]).toBeInTheDocument(); }); }); }); diff --git a/src/pages/home/components/Sidebar/components/SocialAccordion/SocialAccordion.tsx b/src/pages/home/components/Sidebar/components/SocialAccordion/SocialAccordion.tsx index 9898737ff..1ed5f14b1 100644 --- a/src/pages/home/components/Sidebar/components/SocialAccordion/SocialAccordion.tsx +++ b/src/pages/home/components/Sidebar/components/SocialAccordion/SocialAccordion.tsx @@ -65,6 +65,7 @@ function SocialAccordion(props: SocialAccordionProps): ReactNode { aria-controls="content-accordion" aria-expanded={isOpen} className={scss.container} + data-testid="accordion-toggle-button" id="btn-accordion" onClick={handleOpenAccordion} >