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

Migrated DateField tests to @testing-library/react #1340

Merged
merged 14 commits into from
Jun 21, 2024

Conversation

zaxovaiko
Copy link
Member

@zaxovaiko zaxovaiko commented May 24, 2024

Migrated tests for DateField for MUI and Material themes from enzyme to @testing-library/react. Is part of #1130

@github-actions github-actions bot added Area: Theme Affects some of the theme packages Theme: Material-UI Affects the uniforms-material package Theme: MUI Affects the uniforms-mui package labels May 24, 2024
Copy link

codecov bot commented May 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.02%. Comparing base (2a116fb) to head (a547787).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1340      +/-   ##
==========================================
- Coverage   95.05%   95.02%   -0.04%     
==========================================
  Files         175      175              
  Lines        2892     2892              
  Branches      763      763              
==========================================
- Hits         2749     2748       -1     
  Misses         59       59              
- Partials       84       85       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zaxovaiko zaxovaiko added this to the v4.0 milestone May 24, 2024
@zaxovaiko zaxovaiko self-assigned this May 24, 2024
@zaxovaiko zaxovaiko marked this pull request as ready for review May 24, 2024 16:15
@github-actions github-actions bot added the Theme: AntD Affects the uniforms-antd package label May 24, 2024
Copy link
Collaborator

@piotrpospiech piotrpospiech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will postpone my code review until you find out what happened to the missing DateField tests for other themes.

import createContext from './_createContext';
import mount from './_mount';
const getClosestInput = (text: string) =>
screen.getByText(text).closest('.ant-row')?.querySelector('input');

test('<DateField> - renders an input', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like an AntD-specific test. I checkout to 37fa8c1 commit (v3.10.1 tag). Multiple similar tests for DateField exist in the semantic theme. Did we remove them on purpose or by accident? Can you check other themes as well? Maybe those tests can be moved to suites.

Copy link
Member Author

@zaxovaiko zaxovaiko Jun 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I switched to commit 37fa8c1 that you mentioned, and indeed, there were a lot more tests than we currently have. All themes have a few common tests that were only present in the AntD theme. I have moved them to suites, but I still needed to add the skipTestsForAntD flag due to some issues with how AntD handles dates.

@github-actions github-actions bot added the Area: Core Affects the uniforms package label Jun 17, 2024
@zaxovaiko zaxovaiko marked this pull request as ready for review June 17, 2024 21:39
export function testDateField(
DateField: ComponentType<any>,
{
skipTestAntD = true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the SelectField, you implemented theme?: 'antd';. It looks better.

});
const input = findClosestInputWithTestId('z');
expect(input).toBeInTheDocument();
expect(input!.value).toBe(getDateString(now, skipTestAntD));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the idea, but it looks wrong. Even if you will use options.theme === 'antd' in the future, it won't be readable enough. Create a variable above:

const useISOFormat = options.theme === 'antd'

Maybe even put it above tests to avoid duplication (there are two places to refactor).

});
const input = findClosestInputWithTestId('z');
expect(input).toBeInTheDocument();
expect(input?.value).toBe(getDateString(now, skipTestAntD));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

async () => {
const date = '2022-02-02';
const onChange = jest.fn();
const extraProps = !skipTestAntD ? { showTime: false } : { type: 'date' };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const extraProps = !skipTestAntD ? { showTime: false } : { type: 'date' };
const extraProps = skipTestAntD ? { type: 'date' } : { showTime: false };```

piotrpospiech
piotrpospiech previously approved these changes Jun 18, 2024
Comment on lines 10 to 11
const findClosestInputWithTestId = (testId: string) =>
screen.getByTestId(testId).closest('body')?.querySelector('input');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually very important to stick with the conventions of testing library.
There is a huge difference between find* and get*.
https://testing-library.com/docs/queries/about/#types-of-queries

Suggested change
const findClosestInputWithTestId = (testId: string) =>
screen.getByTestId(testId).closest('body')?.querySelector('input');
const getClosestInputWithTestId = (testId: string) =>
screen.getByTestId(testId).closest('body')?.querySelector('input');

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that makes sense! I've changed it.

@kestarumper kestarumper merged commit 6d65e02 into master Jun 21, 2024
6 of 7 checks passed
@kestarumper kestarumper deleted the rewrite-date-field-tests branch June 21, 2024 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Core Affects the uniforms package Area: Theme Affects some of the theme packages Theme: AntD Affects the uniforms-antd package Theme: Material-UI Affects the uniforms-material package Theme: MUI Affects the uniforms-mui package
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants