From d9b53364ddba1e5d4fa9a07e3f5f21ae72b0e103 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sat, 2 Jul 2016 09:22:36 +0100 Subject: [PATCH] Fix counters not including plugins after sort Modifying the existing plugins array doesn't fire the update event, so the counters weren't recalculated. --- src/gui/html/js/game.js | 6 ++++-- src/tests/gui/html/js/test_game.js | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/gui/html/js/game.js b/src/gui/html/js/game.js index d9f48d06..79b91ba3 100644 --- a/src/gui/html/js/game.js +++ b/src/gui/html/js/game.js @@ -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() { diff --git a/src/tests/gui/html/js/test_game.js b/src/tests/gui/html/js/test_game.js index 4f7672e9..354f66b3 100644 --- a/src/tests/gui/html/js/test_game.js +++ b/src/tests/gui/html/js/test_game.js @@ -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', () => {