Skip to content

Commit

Permalink
linting and clean up mock
Browse files Browse the repository at this point in the history
  • Loading branch information
fewieden committed Jan 4, 2021
1 parent f6b18cc commit c40b876
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 234 deletions.
249 changes: 18 additions & 231 deletions __mocks__/Module.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ global.Module = {
return false;
},

getDom() {},
getDom: jest.fn(),

getHeader() {
return this.data.header;
Expand Down Expand Up @@ -86,252 +86,39 @@ 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(),

sendNotification: jest.fn(),

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 '<div class="normal">' + this.name + '</div><div class="small dimmed">' + this.identifier + '</div>';
},

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};
}
};
6 changes: 3 additions & 3 deletions __tests__/MMM-soccer.specs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe('MMM-soccer', () => {
beforeAll(() => {
require('../__mocks__/Logger');
require('../__mocks__/Module');
require('../__mocks__/Logger');
require('../__mocks__/Module');
});

const name = 'MMM-soccer';
Expand Down Expand Up @@ -33,7 +33,7 @@ describe('MMM-soccer', () => {
});

describe('start', () => {
let originalInterval = setInterval;
const originalInterval = setInterval;

beforeEach(() => {
global.setInterval = jest.fn();
Expand Down

0 comments on commit c40b876

Please sign in to comment.