-
Notifications
You must be signed in to change notification settings - Fork 0
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
Edit Dialog for Images #1151
Open
asuresh-code
wants to merge
19
commits into
develop
Choose a base branch
from
feature/add-edit-image-dialog-#1075
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Edit Dialog for Images #1151
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7d9603f
Implemented Edit Dialog for Images TODO: merge develop, and implement…
asuresh-code 5415b1c
merge develop
asuresh-code 157ed0f
connect edit dialog to menuitem TODO testing #1075
asuresh-code 2b0ae3f
implement testing TODO: investigate failing Image test #1075
asuresh-code 9fccbfa
fix failing test #1075
asuresh-code 601f256
generalise edit image dialog for attachemnts #1075
asuresh-code 591651d
Address PR Comments #1075
asuresh-code 1b82001
fix failing unit test #1075
asuresh-code 35dc23a
fix conflict #1075
asuresh-code 6fb08c4
hide extension in text field edit dialog #1075
asuresh-code 6bcdfd4
Apply suggestions from code review
asuresh-code 0cda636
fix linting #1075
asuresh-code 4c39b95
Merge branch 'feature/add-edit-image-dialog-#1075' of github.com:ral-…
asuresh-code 4e6ae2f
fix linting #1075
asuresh-code 3f4e8db
Merge branch 'feature/add-edit-image-dialog-#1075' of github.com:ral-…
asuresh-code 5db78e1
fix linting + tests #1075
asuresh-code 786d1b5
Add extension as label to upload dialog #1075
asuresh-code 36bf77c
Fix comments and update attachment dialog with extension label change…
asuresh-code 6f49f96
Merge branch 'develop' into feature/add-edit-image-dialog-#1075
asuresh-code File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
import { fireEvent, screen, waitFor } from '@testing-library/react'; | ||
import userEvent, { UserEvent } from '@testing-library/user-event'; | ||
import { http } from 'msw'; | ||
import { MockInstance } from 'vitest'; | ||
import { storageApi } from '../api/api'; | ||
import { usePatchImage } from '../api/images'; | ||
import handleIMS_APIError from '../handleIMS_APIError'; | ||
import ImagesJSON from '../mocks/Images.json'; | ||
import { server } from '../mocks/server'; | ||
import { renderComponentWithRouterProvider } from '../testUtils'; | ||
import EditFileDialog, { FileDialogProps } from './editFileDialog.component'; | ||
|
||
vi.mock('../handleIMS_APIError'); | ||
|
||
describe('Edit file dialog', () => { | ||
const onClose = vi.fn(); | ||
let props: FileDialogProps; | ||
let user: UserEvent; | ||
const createView = () => { | ||
return renderComponentWithRouterProvider(<EditFileDialog {...props} />); | ||
}; | ||
|
||
beforeEach(() => { | ||
props = { | ||
open: true, | ||
onClose: onClose, | ||
fileType: 'Image', | ||
usePatchFile: usePatchImage, | ||
}; | ||
user = userEvent.setup(); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
const modifyFileValues = (values: { | ||
file_name?: string; | ||
title?: string; | ||
description?: string; | ||
}) => { | ||
if (values.file_name !== undefined) | ||
fireEvent.change(screen.getByLabelText('File Name *'), { | ||
target: { value: values.file_name }, | ||
}); | ||
|
||
if (values.title !== undefined) | ||
fireEvent.change(screen.getByLabelText('Title'), { | ||
target: { value: values.title }, | ||
}); | ||
|
||
if (values.description !== undefined) | ||
fireEvent.change(screen.getByLabelText('Description'), { | ||
target: { value: values.description }, | ||
}); | ||
}; | ||
|
||
describe('Edit an image', () => { | ||
let axiosPatchSpy: MockInstance; | ||
beforeEach(() => { | ||
props = { | ||
...props, | ||
selectedFile: ImagesJSON[0], | ||
}; | ||
|
||
axiosPatchSpy = vi.spyOn(storageApi, 'patch'); | ||
}); | ||
|
||
it('disables save button and shows circular progress indicator when request is pending', async () => { | ||
server.use( | ||
http.patch('/images/:id', () => { | ||
return new Promise(() => {}); | ||
}) | ||
); | ||
|
||
createView(); | ||
|
||
modifyFileValues({ | ||
file_name: 'Image A', | ||
}); | ||
|
||
const saveButton = screen.getByRole('button', { name: 'Save' }); | ||
await user.click(saveButton); | ||
|
||
expect(saveButton).toBeDisabled(); | ||
expect(await screen.findByRole('progressbar')).toBeInTheDocument(); | ||
}); | ||
|
||
it('Edits an image correctly', async () => { | ||
createView(); | ||
|
||
//Checks if file extension is displayed. If it's editable, actual value will not match expected. | ||
expect(screen.getByText('.png')).toBeInTheDocument(); | ||
|
||
modifyFileValues({ | ||
file_name: 'test_file_name.jpeg', | ||
title: 'Test Title', | ||
description: 'Test Description', | ||
}); | ||
|
||
const saveButton = screen.getByRole('button', { name: 'Save' }); | ||
|
||
await user.click(saveButton); | ||
|
||
expect(axiosPatchSpy).toHaveBeenCalledWith('/images/1', { | ||
file_name: 'test_file_name.jpeg.png', | ||
title: 'Test Title', | ||
description: 'Test Description', | ||
}); | ||
|
||
expect(onClose).toHaveBeenCalled(); | ||
}); | ||
|
||
it('shows correct error message when no values are changed', async () => { | ||
createView(); | ||
|
||
const saveButton = screen.getByRole('button', { name: 'Save' }); | ||
|
||
await user.click(saveButton); | ||
|
||
expect( | ||
screen.getByText( | ||
"There have been no changes made. Please change a field's value or press Cancel to exit." | ||
) | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('shows error message if required fields are whitespace or their current value was removed', async () => { | ||
createView(); | ||
modifyFileValues({ | ||
file_name: '', | ||
}); | ||
const saveButton = screen.getByRole('button', { name: 'Save' }); | ||
|
||
await user.click(saveButton); | ||
|
||
expect(screen.getByText('Please enter a file name.')).toBeInTheDocument(); | ||
expect(onClose).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('displays refresh page message and a CatchAllError request works correctly', async () => { | ||
createView(); | ||
modifyFileValues({ | ||
file_name: 'Error 500', | ||
}); | ||
const saveButton = screen.getByRole('button', { name: 'Save' }); | ||
|
||
await user.click(saveButton); | ||
|
||
expect(handleIMS_APIError).toHaveBeenCalled(); | ||
}); | ||
|
||
it('calls onClose when Close button is clicked', async () => { | ||
createView(); | ||
const cancelButton = screen.getByRole('button', { name: 'Cancel' }); | ||
await user.click(cancelButton); | ||
|
||
await waitFor(() => { | ||
expect(onClose).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.