-
Notifications
You must be signed in to change notification settings - Fork 313
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
chore(content-explorer): Migrate renameDialog #3740
Conversation
greg-in-a-box
commented
Nov 12, 2024
•
edited
Loading
edited
871a691
to
e8cecdc
Compare
c1cf36d
to
c17bc31
Compare
|
||
test('calls onCancel when cancel button is clicked', async () => { | ||
renderComponent(); | ||
await userEvent.click(await screen.findByRole('button', { name: 'Cancel' })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a lot of these seem to use find
but why not use get
? the buttons should appear on initial render and then the await
isn't needed. that way there's no confusion about whether there's a delay or something in the rendering of this component
expect(defaultProps.onRename).not.toHaveBeenCalled(); | ||
expect(defaultProps.onCancel).toHaveBeenCalled(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i dont think we should check a shared object like this. these tests are passing because they're relying on global jest setting clearMocks: true
but i don't think we should rely on that and it could set up bad habits when developers work in other repos.
creating local variables like this makes the tests more independent and intentional:
test('...', async () => {
const onCancel = jest.fn();
const onRename = jest.fn();
renderComponent({ onCancel, onRename });
await userEvent.click(screen.getByText('Rename'));
expect(onRename).not.toHaveBeenCalled();
expect(onCancel).toHaveBeenCalled();
});
expect(defaultProps.onRename).toHaveBeenCalledWith('newname', '.txt'); | ||
}); | ||
|
||
test('displays an error message when errorCode is ERROR_CODE_ITEM_NAME_IN_USE', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should not be ERROR_CODE_ITEM_NAME_IN_USE
test('displays an error message when errorCode is ERROR_CODE_ITEM_NAME_IN_USE', () => { | ||
renderComponent({ errorCode: ERROR_CODE_ITEM_NAME_IN_USE }); | ||
expect(screen.getByText('An item with the same name already exists.')).toBeInTheDocument(); | ||
}); | ||
|
||
test('displays an error message when errorCode is ERROR_CODE_ITEM_NAME_IN_USE', () => { | ||
renderComponent({ errorCode: ERROR_CODE_ITEM_NAME_IN_USE }); | ||
expect(screen.getByText('An item with the same name already exists.')).toBeInTheDocument(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate tests
<Text as="label"> | ||
{error && ( | ||
<div className="be-modal-error"> | ||
<FormattedMessage {...error} values={{ name: nameWithoutExt }} /> | ||
</div> | ||
)} | ||
</Text> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there's no error then this renders an empty label right? should error be moved out a level?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removing in favor for the below comment
<Text as="label"> | ||
<FormattedMessage {...messages.renameDialogText} values={{ name: nameWithoutExt }} /> | ||
</Text> | ||
<input ref={ref} defaultValue={nameWithoutExt} onKeyDown={onKeyDown} required type="text" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about using TextInput from blueprint to handle label, input, and error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tjiang-box had a PR to redesign the modal to align more with EUA: #3666 i think this was confirmed with design
c07954f
to
d15b910
Compare
import Button from '../../components/button/Button'; | ||
import messages from '../common/messages'; | ||
import { FormattedMessage, useIntl } from 'react-intl'; | ||
import {Modal as BlueprintModal, TextInput} from '@box/blueprint-web'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: looks like this file might need formatting?
error={ | ||
error && ( | ||
<div className="be-modal-error"> | ||
<FormattedMessage {...error} values={{ name: nameWithoutExt }} /> | ||
</div> | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think we need these divs anymore?
error={error && formatMessage(error, { name: nameWithoutExt })}
src/elements/common/modal.scss
Outdated
.be-modal-share .be-modal-dialog-content, | ||
.be-modal-delete .be-modal-dialog-content { | ||
padding: 0; | ||
border-radius: tokens.$radius-4; | ||
} | ||
|
||
.be-modal-rename .be-modal-dialog-content { | ||
input { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about using input[type='text']
so doesn't target something like buttons?
d15b910
to
3bd3aa4
Compare
const onCancel = jest.fn(); | ||
|
||
renderComponent({ onCancel }); | ||
await userEvent.click(await screen.getByRole('button', { name: 'Cancel' })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: i don't think await
on getByRole is needed. only for findByRole
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same for some other cases below
3bd3aa4
to
be0b8a3
Compare