Skip to content

Commit

Permalink
Merge branch 'next-7439/fix-renaming-of-files' into 'master'
Browse files Browse the repository at this point in the history
NEXT-7439 - fix renaming of duplicated file uploads

See merge request shopware/6/product/platform!1963
  • Loading branch information
jleifeld committed Apr 2, 2020
2 parents 3a28a96 + 2933d46 commit f14dbc3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG-6.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ To get the diff between two versions, go to https://github.com/shopware/platform

* Added new `sw-settings-captcha-select` component
* This component allows users to define active captchas via `Settings -> Basic information`
* Fix renaming of duplicated media names

* Core
* The `Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\MultiFilter` no longer supports `||` and `&&`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,10 @@ Component.register('sw-duplicated-media-v2', {

async renameFile(uploadTask) {
const newTask = Object.assign({}, uploadTask);
newTask.fileName = await this.mediaService.provideName(uploadTask.fileName, uploadTask.extension).fileName;

const { fileName } = await this.mediaService.provideName(uploadTask.fileName, uploadTask.extension);
newTask.fileName = fileName;

this.mediaService.addUpload(newTask.uploadTag, newTask);
await this.mediaService.runUploads(newTask.uploadTag);
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { shallowMount } from '@vue/test-utils';
import 'src/app/component/utils/sw-duplicated-media-v2';

const uploadTaskMock = {
running: false,
src: File,
uploadTag: 'upload-tag-sw-media-index',
targetId: 'aaaef50651e04f59bbc9c309b5110e23',
fileName: 'my-demo-image',
extension: 'jpg',
error: null,
successAmount: 0,
failureAmount: 1,
totalAmount: 1
};

describe('components/utils/sw-duplicated-media-v2', () => {
let wrapper;
let uploads = {};

beforeEach(() => {
uploads = {};
wrapper = shallowMount(Shopware.Component.build('sw-duplicated-media-v2'), {
provide: {
repositoryFactory: {},
mediaService: {
addDefaultListener: jest.fn(),
removeDefaultListener: jest.fn(),
runUploads: jest.fn(),
addUpload: (tag, uploadTask) => {
if (!uploads[tag]) uploads[tag] = [];

uploads[tag].push(uploadTask);
},
provideName: async (fileName) => {
return { fileName: `${fileName}_(2)` };
}
}
}
});
});

afterEach(() => {
wrapper.destroy();
});

it('should be a Vue.js component', () => {
expect(wrapper.isVueInstance()).toBeTruthy();
});

it('should upload the renamed file', async () => {
await wrapper.vm.renameFile(uploadTaskMock);

const matchingUploadTask = uploads[uploadTaskMock.uploadTag].find(upload => {
return upload.targetId === uploadTaskMock.targetId;
});

expect(matchingUploadTask.fileName).toBe(`${uploadTaskMock.fileName}_(2)`);
expect(wrapper.vm.mediaService.runUploads).toHaveBeenCalledWith('upload-tag-sw-media-index');
});
});

0 comments on commit f14dbc3

Please sign in to comment.