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', () => {