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,12 +522,18 @@ describe('Design management index page', () => { ...@@ -517,12 +522,18 @@ 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 = { document.dispatchEvent(event);
files: [{ name: 'image.png', type: 'image/png' }],
getData: () => 'test.png',
};
expect(wrapper.vm.onUploadDesign).not.toHaveBeenCalled();
});
describe('when designs wrapper is hovered', () => {
beforeEach(() => {
findDesignsWrapper().trigger('mouseenter');
});
it('calls onUploadDesign with valid paste', () => {
document.dispatchEvent(event); document.dispatchEvent(event);
expect(wrapper.vm.onUploadDesign).toHaveBeenCalledTimes(1); expect(wrapper.vm.onUploadDesign).toHaveBeenCalledTimes(1);
...@@ -532,11 +543,6 @@ describe('Design management index page', () => { ...@@ -532,11 +543,6 @@ describe('Design management index page', () => {
}); });
it('renames a design if it has an image.png filename', () => { it('renames a design if it has an image.png filename', () => {
event.clipboardData = {
files: [{ name: 'image.png', type: 'image/png' }],
getData: () => 'image.png',
};
document.dispatchEvent(event); document.dispatchEvent(event);
expect(wrapper.vm.onUploadDesign).toHaveBeenCalledTimes(1); expect(wrapper.vm.onUploadDesign).toHaveBeenCalledTimes(1);
...@@ -555,6 +561,14 @@ describe('Design management index page', () => { ...@@ -555,6 +561,14 @@ describe('Design management index page', () => {
expect(wrapper.vm.onUploadDesign).not.toHaveBeenCalled(); 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();
});
});
}); });
describe('when navigating', () => { describe('when navigating', () => {
......
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