-
Notifications
You must be signed in to change notification settings - Fork 305
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(metadata-sidebar): handle onCancel action for editing templates #3669
Conversation
bab51ea
to
a365a22
Compare
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.
Can we add one more story that shows one can add new template, cancel it, and add it again?
that was not working before
and maybe one that showcases current behavior of canceling editing
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.
can we add in some unit test coverage for your changes? i see the mock props in the defaultProps in one of the tests files but i dont see any tests added with this change to do with the onCancel action
a365a22
to
5c750ea
Compare
aaa74a3
to
09d00c3
Compare
09d00c3
to
9ae3e54
Compare
src/elements/content-sidebar/stories/tests/MetadataSidebarRedesign-visual.stories.tsx
Outdated
Show resolved
Hide resolved
if (editingTemplate) { | ||
setPendingTemplateToEdit(selectedTemplate as MetadataTemplateInstance); | ||
setIsUnsavedChangesModalOpen(true); | ||
} else { | ||
setSelectedTemplates([...selectedTemplates, selectedTemplate]); | ||
setEditingTemplate(selectedTemplate as MetadataTemplateInstance); |
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.
For future, as soon as @karolinaru merges #3663 we should use convertTemplateToTemplateInstance
here.
1573571
to
acc6392
Compare
const { getByRole } = render(<MetadataInstanceEditor {...props} />); | ||
|
||
act(() => { | ||
fireEvent.click(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.
fireEvent.click(getByRole('button', { name: 'Cancel' })); | |
await userEvent.click(getByRole('button', { name: 'Cancel' })); |
I dont think we need act
if we are using the right combination of functions, if you still get the act
error/warning still i wondering its you need to do use findByRole
instead of getByRole
which also might fix that error/warning
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 changed that to not use it, is act
deprecated or unwanted here though ? I thought it's just recommended to change where it's imported from.
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.
you dont need to use act
if you use userEvent
, should already being doing the act
within the function, if start seeing "maybe you need an act
" errors, you could probably switch to userEvent
in that case.
src/elements/content-sidebar/__tests__/MetadataInstanceEditor.test.tsx
Outdated
Show resolved
Hide resolved
src/elements/content-sidebar/__tests__/MetadataInstanceEditor.test.tsx
Outdated
Show resolved
Hide resolved
src/elements/content-sidebar/__tests__/MetadataInstanceEditor.test.tsx
Outdated
Show resolved
Hide resolved
04e074e
to
7656f6a
Compare
// Mock window.matchMedia to simulate media query behavior for tests | ||
// in which UnsavedChangesModal component relies on it. | ||
const mockMatchMedia = () => | ||
Object.defineProperty(window, 'matchMedia', { | ||
writable: true, | ||
value: jest.fn().mockImplementation(query => ({ | ||
matches: false, | ||
media: query, | ||
onchange: null, | ||
addEventListener: jest.fn(), | ||
removeEventListener: jest.fn(), | ||
dispatchEvent: jest.fn(), | ||
})), | ||
}); | ||
|
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.
this was just added to master, in the global jest setup file,
Object.defineProperty(window, 'matchMedia', { |
7e5810c
to
5cb0050
Compare
5cb0050
to
860a8bb
Compare
76e0493
76e0493
to
694815c
Compare
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.
lgtm
694815c
to
62d915e
Compare
Description
MetadataInstanceEditor
MetadataInstanceEditor
:setIsUnsavedChangesModalOpen
andonUnsavedChangesModalCancel
for handling theUnsavedChangesModal
directly from BUIEAddMetadataTemplateDropdown
still being disabled after cancelling editing a new templateUnsavedChangesModal
, addhandleCancelUnsavedChanges
inMetadataSidebarRedesign
('Cancel' action inUnsavedChangesModal
) for checking if there are pending editors to switch to immediately after cancelling the previous oneAdditional Notes:
Temporary conversion between
MetadataTemplateInstance
andMetadataTemplate
was added, which will be handled properly in the future PR