Fix counters not including plugins after sort

Modifying the existing plugins array doesn't fire the update event, so
the counters weren't recalculated.
This commit is contained in:
Oliver Hamlet
2016-07-02 09:26:46 +01:00
parent 3f4793b551
commit d9b53364dd
2 changed files with 20 additions and 2 deletions
+4 -2
View File
@@ -291,8 +291,8 @@
setSortedPlugins(plugins) {
this.oldLoadOrder = this.plugins;
this.plugins = [];
const newPlugins = [];
plugins.forEach((plugin) => {
let existingPlugin = this.oldLoadOrder.find(item => item.name === plugin.name);
if (existingPlugin) {
@@ -300,8 +300,10 @@
} else {
existingPlugin = new Plugin(plugin);
}
this.plugins.push(existingPlugin);
newPlugins.push(existingPlugin);
});
this.plugins = newPlugins;
}
applySort() {
+16
View File
@@ -458,11 +458,16 @@ describe('Game', () => {
describe('#setSortedPlugins', () => {
let game;
let handleEvent;
beforeEach(() => {
game = new loot.Game({}, l10n);
});
afterEach(() => {
document.removeEventListener('loot-game-plugins-change', handleEvent);
});
it('should append new plugins to the plugins array', () => {
game.setSortedPlugins([{
name: 'foo',
@@ -520,6 +525,17 @@ describe('Game', () => {
game.oldLoadOrder[0].name.should.equal('foo');
game.oldLoadOrder[1].name.should.equal('bar');
});
it('should dispatch an event', (done) => {
handleEvent = () => {
done();
};
document.addEventListener('loot-game-plugins-change', handleEvent);
game.setSortedPlugins([{
name: 'foo',
}]);
});
});
describe('#applySort', () => {