wrote basic tests, restructured code for easier testing
This commit is contained in:
Родитель
e89a897f70
Коммит
003c6bbe95
|
@ -15,18 +15,18 @@ const welcomeBoxHeight = 67;
|
|||
|
||||
class Recommender {
|
||||
constructor() {
|
||||
this.date = new Date();
|
||||
this.installedAddonIds = new Set();
|
||||
this.recData = [];
|
||||
this.buttons = [];
|
||||
}
|
||||
init() {
|
||||
this.panel = this.createPanel();
|
||||
this.createRequestListener('install');
|
||||
this.createRequestListener('uninstall');
|
||||
this.createWindowListener();
|
||||
}
|
||||
|
||||
start() {
|
||||
this.populateInstallSet();
|
||||
this.loadLocalRecs();
|
||||
this.createWindowListener();
|
||||
if (!simplePrefs.prefs.onboarded) {
|
||||
this.onboard();
|
||||
}
|
||||
|
@ -34,7 +34,6 @@ class Recommender {
|
|||
|
||||
destroy() {
|
||||
this.panel.destroy();
|
||||
this.buttonManager.deleteButtons();
|
||||
this.removeWindowListener();
|
||||
}
|
||||
|
||||
|
@ -76,7 +75,7 @@ class Recommender {
|
|||
|
||||
// Prepares panel with info in background
|
||||
prepPanel(recs) {
|
||||
this.checkForInstalled(recs);
|
||||
this.recs = this.checkForInstalled(recs);
|
||||
this.panel.height = recs.length * panelRecHeight;
|
||||
if (!simplePrefs.prefs.onboarded) {
|
||||
this.panel.height += welcomeBoxHeight;
|
||||
|
@ -96,13 +95,15 @@ class Recommender {
|
|||
|
||||
// checks to see if any recommendations are already installed
|
||||
checkForInstalled(recs) {
|
||||
for (let rec of recs) { // eslint-disable-line prefer-const
|
||||
const markedRecs = recs;
|
||||
for (let rec of markedRecs) { // eslint-disable-line prefer-const
|
||||
if (this.installedAddonIds.has(rec.id)) {
|
||||
rec.isInstalled = true;
|
||||
} else {
|
||||
rec.isInstalled = false;
|
||||
}
|
||||
}
|
||||
return markedRecs;
|
||||
}
|
||||
|
||||
getButton(win) {
|
||||
|
@ -193,13 +194,4 @@ class Recommender {
|
|||
}
|
||||
}
|
||||
|
||||
const recommender = new Recommender();
|
||||
|
||||
exports.Recommend = {
|
||||
start() {
|
||||
recommender.init();
|
||||
},
|
||||
destroy() {
|
||||
recommender.destroy();
|
||||
},
|
||||
};
|
||||
exports.Recommender = Recommender;
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
const { Recommend } = require('lib/Recommend.js');
|
||||
const { Recommender } = require('./Recommend.js');
|
||||
const { Log } = require('lib/ConsoleLog.js');
|
||||
|
||||
Log.debug(Recommender);
|
||||
const Rec = new Recommender();
|
||||
|
||||
const variations = {
|
||||
'default'() {
|
||||
Recommend.start();
|
||||
Rec.start();
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -11,7 +15,7 @@ function isEligible() {
|
|||
}
|
||||
|
||||
function cleanup() {
|
||||
Recommend.destroy();
|
||||
Rec.destroy();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
|
@ -1,19 +1,28 @@
|
|||
var main = require("../");
|
||||
const { before, after } = require('sdk/test/utils');
|
||||
const { Recommender } = require('../lib/Recommend.js');
|
||||
|
||||
exports["test main"] = function(assert) {
|
||||
assert.pass("Unit test running!");
|
||||
let recommender;
|
||||
|
||||
exports['test main'] = (assert) => {
|
||||
assert.pass('Unit test running!');
|
||||
};
|
||||
|
||||
exports["test main async"] = function(assert, done) {
|
||||
assert.pass("async Unit test running!");
|
||||
exports['test main async'] = (assert, done) => {
|
||||
assert.pass('async Unit test running!');
|
||||
done();
|
||||
};
|
||||
|
||||
exports["test dummy"] = function(assert, done) {
|
||||
main.dummy("foo", function(text) {
|
||||
assert.ok((text === "foo"), "Is the text actually 'foo'");
|
||||
done();
|
||||
});
|
||||
exports['test recommend createPanel'] = (assert) => {
|
||||
assert.ok((recommender.panel.isShowing === false), 'Panel created!');
|
||||
};
|
||||
|
||||
require("sdk/test").run(exports);
|
||||
require('sdk/test').run(exports);
|
||||
|
||||
before(exports, () => {
|
||||
recommender = new Recommender();
|
||||
});
|
||||
|
||||
after(exports, () => {
|
||||
recommender.destroy();
|
||||
recommender = null;
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче