Skip to content

Commit

Permalink
fix linting + tests #1075
Browse files Browse the repository at this point in the history
  • Loading branch information
asuresh-code committed Jan 14, 2025
1 parent 3f4e8db commit 5db78e1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion cypress/e2e/with_mock_data/items.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ describe('Items', () => {
.should('be.visible')
.within(() => {
cy.findByLabelText('File Name *').clear();
cy.findByText('.png').should('exist');
cy.findByLabelText('File Name *').type('test file');

cy.findByLabelText('Title').clear();
Expand All @@ -930,7 +931,7 @@ describe('Items', () => {
expect(patchRequests.length).equal(1);
const request = patchRequests[0];
expect(JSON.stringify(await request.json())).equal(
'{"file_name":"test file","description":"test description","title":"test title"}'
'{"file_name":"test file.png","description":"test description","title":"test title"}'
);
});
});
Expand Down
6 changes: 5 additions & 1 deletion src/common/editFileDialog.component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ describe('Edit file dialog', () => {

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',
Expand All @@ -98,7 +102,7 @@ describe('Edit file dialog', () => {
await user.click(saveButton);

expect(axiosPatchSpy).toHaveBeenCalledWith('/images/1', {
file_name: 'test_file_name.jpeg',
file_name: 'test_file_name.jpeg.png',
title: 'Test Title',
description: 'Test Description',
});
Expand Down
4 changes: 2 additions & 2 deletions src/common/editFileDialog.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const EditFileDialog = (props: FileDialogProps) => {

const selectedFileCopy: ObjectFilePatch = React.useMemo(
() => (selectedFile ? { ...selectedFile, file_name: initialName } : {}),
[selectedFile]
[selectedFile, initialName]
);

const initialFile: ObjectFilePatch = React.useMemo(
Expand Down Expand Up @@ -109,7 +109,7 @@ const EditFileDialog = (props: FileDialogProps) => {

const isTitleUpdated = fileData.title !== selectedFileCopy.title;

let fileToEdit: ObjectFilePatch = {};
const fileToEdit: ObjectFilePatch = {};

if (isFileNameUpdated)
fileToEdit.file_name = fileData.file_name + extension;
Expand Down
2 changes: 1 addition & 1 deletion src/mocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ export const handlers = [

const fullBody = { ...obj, ...body };

if (fullBody.file_name === 'Error 500') {
if (fullBody.file_name === 'Error 500.png') {
return HttpResponse.json(
{ detail: 'Something went wrong' },
{ status: 500 }
Expand Down

0 comments on commit 5db78e1

Please sign in to comment.