Skip to content

chore(Truncate): component unit test revamp#7686

Merged
wise-king-sullyman merged 3 commits intopatternfly:mainfrom
andyyvo:iss7643
Jul 26, 2022
Merged

chore(Truncate): component unit test revamp#7686
wise-king-sullyman merged 3 commits intopatternfly:mainfrom
andyyvo:iss7643

Conversation

@andyyvo
Copy link
Copy Markdown
Contributor

@andyyvo andyyvo commented Jul 12, 2022

What: Closes #7643 . Unit tests revamp -- note that there was an issue with the position prop where if position=start, then only pf-c-truncate__end would render. However, getByText could not detect the inputted text as a result of ‎ so a snapshot test was performed instead.

Additional issues: N/A.

@patternfly-build
Copy link
Copy Markdown
Collaborator

patternfly-build commented Jul 12, 2022

@nicolethoen nicolethoen self-requested a review July 15, 2022 11:22
Copy link
Copy Markdown
Contributor

@nicolethoen nicolethoen left a comment

Choose a reason for hiding this comment

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

This looks great!

Copy link
Copy Markdown
Collaborator

@wise-king-sullyman wise-king-sullyman left a comment

Choose a reason for hiding this comment

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

This is looking really good! I only have a few changes I'd like to see 🙂

Comment on lines +134 to +143
test('renders tooltip placement', () => {
const { asFragment } = render(
<Truncate
content={''}
tooltipPosition='auto'
/>
);

expect(asFragment()).toMatchSnapshot();
});
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Rather than using a snapshot here I would prefer to see independent tests that explicitly assert the behavior we're expecting, i.e. that Tooltip receives the position we expect, that it receives the content we expect, and that it receives the children we expect.

Comment on lines +66 to +92
test('renders pf-c-truncate__start when trailingNumChars prop passed', () => {
render(
<Truncate
content={'Testing truncate content'}
trailingNumChars={3}
position='middle'
/>
);

const start = screen.getByText('Testing truncate cont');

expect(start).toHaveClass('pf-c-truncate__start');
});

test('renders pf-c-truncate__end when trailingNumChars prop passed', () => {
render(
<Truncate
content={'Testing truncate content'}
trailingNumChars={3}
position='middle'
/>
);

const end = screen.getByText('ent');

expect(end).toHaveClass('pf-c-truncate__end');
});
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think these could actually be condensed into one test with multiple assertions since they're only testing one behavior.

Also regarding the test names, is it the trailingNumChars prop behavior that is causing __start and __end to both render, or is it the value of the position prop?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I believe it is the value of the position prop. If it's start then we get __end, if it's end then we get __start, and middle gives us both

@@ -28,3 +130,26 @@ test('renders middle truncation', () => {
);
expect(asFragment()).toMatchSnapshot();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you refactor this test to not be a snapshot and explicitly assert against the default behavior when position=middle and traillingNumChars isn't passed?

Comment on lines +94 to +105
test('only renders pf-c-truncate__start if truncate position is the end', () => {
render(
<Truncate
content={'Testing truncate content'}
position='end'
/>
);

const start = screen.getByText('Testing truncate content');

expect(start).toHaveClass('pf-c-truncate__start');
});
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since position=end is the default value I think this test should actually omit the position prop so that we have a test about the default behavior here.

Copy link
Copy Markdown
Collaborator

@wise-king-sullyman wise-king-sullyman left a comment

Choose a reason for hiding this comment

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

This looks great! Thanks for taking the time to make all these changes and put this together!

@wise-king-sullyman wise-king-sullyman merged commit c2f6747 into patternfly:main Jul 26, 2022
jenny-s51 pushed a commit to jenny-s51/patternfly-react that referenced this pull request Jul 26, 2022
* chore(Truncate): component unit test revamp

* chore(Truncate): updated snapshot tests to be explicitly asserting

* chore(Truncate): updating tooltip content test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Truncate test revamp

4 participants