Skip to content

Commit

Permalink
fix jest test
Browse files Browse the repository at this point in the history
  • Loading branch information
jparez committed Jun 13, 2024
1 parent d481be8 commit 8e47448
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"jsxSingleQuote": true,
"trailingComma": "all",
"bracketSpacing": false,
"spaceBeforeFunctionParen": false,
"jsxBracketSameLine": false,
"arrowParens": "always",
"proseWrap": "preserve",
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/FileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ module.exports = class FileUpload extends OverlayPlugin {
case 'success':
this.displayStep('successScreen');
// On flashing success, force display success screen
if (this.flashing && this.widget.classList.contains('gm-hidden')) {
if (this.flashing && !this.instance.store.getters.isWidgetOpened(this.overlayID)) {
this.toggleWidget();
}
this.flashing = false;
Expand All @@ -313,7 +313,7 @@ module.exports = class FileUpload extends OverlayPlugin {
case 'install_error':
this.displayStep('errorScreen');
// On flashing error, force display errorscreen
if (this.flashing && this.widget.classList.contains('gm-hidden')) {
if (this.flashing && !this.instance.store.getters.isWidgetOpened(this.overlayID)) {
this.toggleWidget();
}
this.flashing = false;
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/MouseEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ module.exports = class MouseEvents {
}
this.instance.sendEvent(json);

this.removeMouseUpListener();
if (this.removeMouseUpListener) {
this.removeMouseUpListener();
}
}

/**
Expand Down
5 changes: 4 additions & 1 deletion tests/mocks/DeviceRenderer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const Original = require('../../src/DeviceRenderer');

module.exports = class DeviceRenderer extends Original {
constructor(options) {
document.body.innerHTML = `
Expand Down Expand Up @@ -38,6 +37,10 @@ module.exports = class DeviceRenderer extends Original {
return {};
},
subscribe: jest.fn(),
dispatch: jest.fn(),
getters: {
isWidgetOpened: () => false,
},
};
this.apiManager = {
registerFunction: jest.fn(),
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/clipboard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ jest.mock('loglevel');

const Clipboard = require('../../src/plugins/Clipboard');
const Instance = require('../mocks/DeviceRenderer');
const store = require('../../src/store/index');

let clipboard;
let instance;
Expand All @@ -12,6 +13,7 @@ let plugin;
describe('Clipboard Plugin', () => {
beforeEach(() => {
instance = new Instance();
store(instance);
clipboard = new Clipboard(instance, {});
plugin = document.getElementsByClassName('gm-clipboard-plugin')[0];
});
Expand All @@ -25,6 +27,7 @@ describe('Clipboard Plugin', () => {
describe('UI', () => {
beforeEach(() => {
instance = new Instance();
store(instance);
clipboard = new Clipboard(instance, {
CLIPBOARD_TITLE: 'TEST CLIPBOARD PLUGIN TITLE',
});
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/fileupload.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

jest.mock('loglevel');
const FileUpload = require('../../src/plugins/FileUpload');
const Instance = require('../mocks/DeviceRenderer');
const store = require('../../src/store/index');

let uploader;
let instance;
Expand All @@ -10,6 +11,8 @@ let plugin;
describe('FileUpload Plugin', () => {
beforeEach(() => {
instance = new Instance();
store(instance);

uploader = new FileUpload(instance, {
UPLOADER_INSTALLING: 'TEST UPLOADER PLUGIN INSTALLING...',
});
Expand All @@ -31,6 +34,7 @@ describe('FileUpload Plugin', () => {
describe('UI', () => {
beforeEach(() => {
instance = new Instance();
store(instance);
uploader = new FileUpload(instance, {
UPLOADER_TITLE: 'TEST UPLOADER PLUGIN TITLE',
UPLOADER_HOME_TITLE: 'TEST UPLOADER PLUGIN HOME TITLE',
Expand Down

0 comments on commit 8e47448

Please sign in to comment.