Commit 01c22aba authored by Natalia Tepluhina's avatar Natalia Tepluhina Committed by Andrew Fontaine

Resolve "Pasting an image into a comment still uploades a design"

parent 1836a5c8
...@@ -106,7 +106,6 @@ export default { ...@@ -106,7 +106,6 @@ export default {
}, },
}, },
mounted() { mounted() {
this.toggleOnPasteListener(this.$route.name);
if (this.$route.path === '/designs') { if (this.$route.path === '/designs') {
this.$el.scrollIntoView(); this.$el.scrollIntoView();
} }
......
---
title: Resolve Pasting an image into a comment still uploades a design
merge_request: 38280
author:
type: fixed
...@@ -72,6 +72,7 @@ describe('Design management index page', () => { ...@@ -72,6 +72,7 @@ describe('Design management index page', () => {
const dropzoneClasses = () => findDropzone().classes(); const dropzoneClasses = () => findDropzone().classes();
const findDropzoneWrapper = () => wrapper.find('[data-testid="design-dropzone-wrapper"]'); const findDropzoneWrapper = () => wrapper.find('[data-testid="design-dropzone-wrapper"]');
const findFirstDropzoneWithDesign = () => wrapper.findAll(DesignDropzone).at(1); const findFirstDropzoneWithDesign = () => wrapper.findAll(DesignDropzone).at(1);
const findDesignsWrapper = () => wrapper.find('[data-testid="designs-root"]');
function createComponent({ function createComponent({
loading = false, loading = false,
...@@ -508,6 +509,10 @@ describe('Design management index page', () => { ...@@ -508,6 +509,10 @@ describe('Design management index page', () => {
}); });
event = new Event('paste'); event = new Event('paste');
event.clipboardData = {
files: [{ name: 'image.png', type: 'image/png' }],
getData: () => 'test.png',
};
router.replace({ router.replace({
name: DESIGNS_ROUTE_NAME, name: DESIGNS_ROUTE_NAME,
...@@ -517,43 +522,52 @@ describe('Design management index page', () => { ...@@ -517,43 +522,52 @@ describe('Design management index page', () => {
}); });
}); });
it('calls onUploadDesign with valid paste', () => { it('does not call paste event if designs wrapper is not hovered', () => {
event.clipboardData = {
files: [{ name: 'image.png', type: 'image/png' }],
getData: () => 'test.png',
};
document.dispatchEvent(event); document.dispatchEvent(event);
expect(wrapper.vm.onUploadDesign).toHaveBeenCalledTimes(1); expect(wrapper.vm.onUploadDesign).not.toHaveBeenCalled();
expect(wrapper.vm.onUploadDesign).toHaveBeenCalledWith([
new File([{ name: 'image.png' }], 'test.png'),
]);
}); });
it('renames a design if it has an image.png filename', () => { describe('when designs wrapper is hovered', () => {
event.clipboardData = { beforeEach(() => {
files: [{ name: 'image.png', type: 'image/png' }], findDesignsWrapper().trigger('mouseenter');
getData: () => 'image.png', });
};
document.dispatchEvent(event); it('calls onUploadDesign with valid paste', () => {
document.dispatchEvent(event);
expect(wrapper.vm.onUploadDesign).toHaveBeenCalledTimes(1); expect(wrapper.vm.onUploadDesign).toHaveBeenCalledTimes(1);
expect(wrapper.vm.onUploadDesign).toHaveBeenCalledWith([ expect(wrapper.vm.onUploadDesign).toHaveBeenCalledWith([
new File([{ name: 'image.png' }], `design_${Date.now()}.png`), new File([{ name: 'image.png' }], 'test.png'),
]); ]);
}); });
it('does not call onUploadDesign with invalid paste', () => { it('renames a design if it has an image.png filename', () => {
event.clipboardData = { document.dispatchEvent(event);
items: [{ type: 'text/plain' }, { type: 'text' }],
files: [],
};
document.dispatchEvent(event); expect(wrapper.vm.onUploadDesign).toHaveBeenCalledTimes(1);
expect(wrapper.vm.onUploadDesign).toHaveBeenCalledWith([
new File([{ name: 'image.png' }], `design_${Date.now()}.png`),
]);
});
expect(wrapper.vm.onUploadDesign).not.toHaveBeenCalled(); it('does not call onUploadDesign with invalid paste', () => {
event.clipboardData = {
items: [{ type: 'text/plain' }, { type: 'text' }],
files: [],
};
document.dispatchEvent(event);
expect(wrapper.vm.onUploadDesign).not.toHaveBeenCalled();
});
it('removes onPaste listener after mouseleave event', async () => {
findDesignsWrapper().trigger('mouseleave');
document.dispatchEvent(event);
expect(wrapper.vm.onUploadDesign).not.toHaveBeenCalled();
});
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment