From c40b8762cba3c20c65fd1fbec25819fb81f82ecf Mon Sep 17 00:00:00 2001 From: Felix Wiedenbach Date: Mon, 4 Jan 2021 20:27:47 +0100 Subject: [PATCH] linting and clean up mock --- __mocks__/Module.js | 249 +++------------------------------- __tests__/MMM-soccer.specs.js | 6 +- 2 files changed, 21 insertions(+), 234 deletions(-) diff --git a/__mocks__/Module.js b/__mocks__/Module.js index b6f25da..ccb7ef8 100644 --- a/__mocks__/Module.js +++ b/__mocks__/Module.js @@ -35,7 +35,7 @@ global.Module = { return false; }, - getDom() {}, + getDom: jest.fn(), getHeader() { return this.data.header; @@ -86,25 +86,7 @@ global.Module = { this.config = Object.assign({}, this.defaults, config); }, - socket() {}, - - file(file) { - return (this.data.path + '/' + file).replace('//', '/'); - }, - - loadStyles(callback) { - this.loadDependencies('getStyles', callback); - }, - - loadScripts(callback) { - this.loadDependencies('getScripts', callback); - }, - - loadDependencies(funcName, callback) {}, - - loadTranslations(callback) {}, - - translate(key, defaultValueOrVariables, defaultValue) {}, + translate: jest.fn(), updateDom: jest.fn(), @@ -112,226 +94,31 @@ global.Module = { sendSocketNotification: jest.fn(), - hide(speed, callback, options) { + hide: jest.fn((speed, callback) => { if (typeof callback === 'object') { - options = callback; - callback = function () { - }; + callback = jest.fn(); } - callback = callback || function () { - }; - options = options || {}; - - const self = this; - MM.hideModule( - self, - speed, - () => { - self.suspend(); - callback(); - }, - options - ); - }, + callback = callback || jest.fn(); + + global.Module.definitions[name].hidden = true; + global.Module.definitions[name].suspend(); + callback(); + }), - show(speed, callback, options) { + show: jest.fn((speed, callback) => { if (typeof callback === 'object') { - options = callback; - callback = function () { - }; + callback = jest.fn(); } - callback = callback || function () { - }; - options = options || {}; - - const self = this; - MM.showModule( - this, - speed, - () => { - self.resume(); - callback(); - }, - options - ); - } - }; - - this.definitions[name] = {...base, ...overrides}; - } -}; - - - - - - - - - - - - -module.exports = { - requiresVersion: '2.0.0', - - defaults: {}, - - showHideTimer: null, - - lockStrings: [], - - _nunjucksEnvironment: null, - - init() { - Log.log(this.defaults); - }, - - start() { - Log.info('Starting module: ' + this.name); - }, - - getScripts() { - return []; - }, - - getStyles() { - return []; - }, - - getTranslations() { - return false; - }, - - getDom() { - }, - - getHeader() { - return this.data.header; - }, - - getTemplate() { - return '
' + this.name + '
' + this.identifier + '
'; - }, - - getTemplateData() { - return {}; - }, - - notificationReceived(notification, payload, sender) { - if (sender) { - Log.log(this.name + ' received a module notification: ' + notification + ' from sender: ' + sender.name); - } else { - Log.log(this.name + ' received a system notification: ' + notification); - } - }, - - nunjucksEnvironment() { - }, - - socketNotificationReceived(notification, payload) { - Log.log(this.name + ' received a socket notification: ' + notification + ' - Payload: ' + payload); - }, - - suspend() { - Log.log(this.name + ' is suspended.'); - }, - - resume() { - Log.log(this.name + ' is resumed.'); - }, - - setData(data) { - this.data = data; - this.name = data.name; - this.identifier = data.identifier; - this.hidden = false; - - this.setConfig(data.config, data.configDeepMerge); - }, - - setConfig(config, deep) { - this.config = deep ? configMerge({}, this.defaults, config) : Object.assign({}, this.defaults, config); - }, - - socket() { - }, - - file(file) { - return (this.data.path + '/' + file).replace('//', '/'); - }, - - loadStyles(callback) { - this.loadDependencies('getStyles', callback); - }, + callback = callback || jest.fn(); - loadScripts(callback) { - this.loadDependencies('getScripts', callback); - }, - - loadDependencies(funcName, callback) { - }, - - loadTranslations(callback) { - }, - - translate(key, defaultValueOrVariables, defaultValue) { - }, - - updateDom(speed) { - }, - - sendNotification(notification, payload) { - }, - - sendSocketNotification(notification, payload) { - }, - - hide(speed, callback, options) { - if (typeof callback === 'object') { - options = callback; - callback = function () { - }; - } - - callback = callback || function () { - }; - options = options || {}; - - const self = this; - MM.hideModule( - self, - speed, - () => { - self.suspend(); + global.Module.definitions[name].hidden = false; + global.Module.definitions[name].resume(); callback(); - }, - options - ); - }, - - show(speed, callback, options) { - if (typeof callback === 'object') { - options = callback; - callback = function () { - }; - } - - callback = callback || function () { + }) }; - options = options || {}; - - const self = this; - MM.showModule( - this, - speed, - () => { - self.resume(); - callback(); - }, - options - ); + + this.definitions[name] = {...base, ...overrides}; } }; diff --git a/__tests__/MMM-soccer.specs.js b/__tests__/MMM-soccer.specs.js index 9a82665..bc2e190 100644 --- a/__tests__/MMM-soccer.specs.js +++ b/__tests__/MMM-soccer.specs.js @@ -1,7 +1,7 @@ describe('MMM-soccer', () => { beforeAll(() => { - require('../__mocks__/Logger'); - require('../__mocks__/Module'); + require('../__mocks__/Logger'); + require('../__mocks__/Module'); }); const name = 'MMM-soccer'; @@ -33,7 +33,7 @@ describe('MMM-soccer', () => { }); describe('start', () => { - let originalInterval = setInterval; + const originalInterval = setInterval; beforeEach(() => { global.setInterval = jest.fn();