Skip to content

Commit

Permalink
added/updated magic mirror mocks, started on module tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fewieden committed Jan 3, 2021
1 parent 83d2287 commit d84b3dc
Show file tree
Hide file tree
Showing 6 changed files with 504 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ European Soccer Standings Module for MagicMirror²
* An installation of [MagicMirror²](https://github.com/MichMich/MagicMirror)
* OPTIONAL: [Voice Control](https://github.com/fewieden/MMM-voice) and [MMM-Modal](https://github.com/fewieden/MMM-Modal)
* npm
* [request](https://www.npmjs.com/package/request)
* [node-fetch](https://www.npmjs.com/package/node-fetch)

## Installation

Expand Down
7 changes: 7 additions & 0 deletions __mocks__/Logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
global.Log = {
debug: jest.fn(),
log: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
}
337 changes: 337 additions & 0 deletions __mocks__/Module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,337 @@
global.Module = {
definitions: {},
create(name) {
return this.definitions[name];
},
register(name, overrides) {
const base = {
requiresVersion: '2.0.0',

defaults: {},

showHideTimer: null,

lockStrings: [],

_nunjucksEnvironment: {addFilter: jest.fn()},

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() {
return this._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) {
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) {},

updateDom(speed) {},

sendNotification(notification, payload) {},

sendSocketNotification: jest.fn(),

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();
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};
}
};












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);
},

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();
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
);
}
};
Loading

0 comments on commit d84b3dc

Please sign in to comment.