Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make ControlledSelect testable #229

Closed
wants to merge 1 commit into from

Conversation

luizprsjr
Copy link
Contributor

What does this do?

Makes the ControlledSelect easier to test within forms.

Why did you do this?

I was creating a signup screen where the user should choose their account type using a select, either "user" or "trucker", but my tests couldn't interact with the BottomSheetFlatList inside the ControlledSelect because the options list was not appearing.

Who/what does this impact?

.

How did you test this?

This was the first test I conducted, and I couldn't get it to pass before the changes. I subsequently conducted more complex tests, which also worked, but sharing them here wouldn't add much value.

<ControlledSelect
  control={control}
  name="type"
  options={userTypeOptions}
  label="Tipo da conta"
  placeholder="Selecione..."
/>
it('should render the correct select options and select a type', async () => {
    const { getByTestId, getByText, queryByText } = render(<SignUpForm />);
    expect(queryByText(/Selecione.../i)).not.toBeNull();
    const select = getByText('Selecione...');
    fireEvent.press(select);

    const truckerOption = getByText('Caminhoneiro');
    const userOption = getByText('Usuário');
    expect(truckerOption).toBeTruthy();
    expect(userOption).toBeTruthy();
    fireEvent.press(truckerOption);

    const button = getByTestId('sign-up-button');
    expect(button).toBeTruthy();
    fireEvent.press(button);

    expect(queryByText(/Selecione.../i)).toBeNull();
  });

@netlify
Copy link

netlify bot commented Oct 25, 2023

Deploy Preview for obytes-starter canceled.

Name Link
🔨 Latest commit 5bf5300
🔍 Latest deploy log https://app.netlify.com/sites/obytes-starter/deploys/6538627960d813000857b8c9

@yjose
Copy link
Member

yjose commented Oct 26, 2023

Hey @luizprsjr thank you for bringing that. I am a little bit confusing but if you look at mock.js you will noticed that BottomFlatList is already mocked as FlatList 🤔

@luizprsjr
Copy link
Contributor Author

In my project created using the npx create-obytes-app@latest MyApp template, all the mocks were pointing to the BottomSheepComponent. To perform my tests successfully, I had to update the mock.

image

image

@luizprsjr
Copy link
Contributor Author

I just reviewed the code, and it appears that a commit was made to the library four months ago to address the issue with mocks. It's possible that the library version in the template is outdated, leading to the problem we encountered. Please consider updating the library version in the template to the latest one to ensure that this issue is resolved. You can refer to the following pull request for more information: link.

@luizprsjr
Copy link
Contributor Author

luizprsjr commented Oct 31, 2023

When I use the pnpm up -i command, the library doesn't appear in the list. That's why I've opened a new pull request for update #232

@yjose
Copy link
Member

yjose commented Oct 31, 2023

Thank you @luizprsjr for your work, can you confirm that updating the library fixes the issue related to mocking?

in this case we can close this PR and merge #232

@luizprsjr
Copy link
Contributor Author

Yes @yjose, I reverted to the original mock and updated the library, and all the tests passed.

@yjose yjose closed this Oct 31, 2023
@yjose
Copy link
Member

yjose commented Oct 31, 2023

closed in favor of #232

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants