Fixed the Theme Service removeListener method
- It was returning an array containing the listener that was being removed
instead of returning an array of everything but the one being removed.
Fixed the Jasmine tests to honor the changes.
JIRA Tasks; ONOS-6291
Change-Id: Ib2b5cd8527157f0e67761c352cecfd5047c292a6
diff --git a/web/gui/src/main/webapp/app/fw/util/theme.js b/web/gui/src/main/webapp/app/fw/util/theme.js
index cc6b767..42b5704 100644
--- a/web/gui/src/main/webapp/app/fw/util/theme.js
+++ b/web/gui/src/main/webapp/app/fw/util/theme.js
@@ -29,7 +29,6 @@
// internal state
var listeners = [],
- currentTheme,
thidx;
// TODO: fine tune these colors
@@ -75,9 +74,9 @@
return themes[thidx];
}
- function setTheme(t, force) {
+ function setTheme(t) {
var idx = themes.indexOf(t);
- if (force || idx > -1 && idx !== thidx) {
+ if (idx > -1 && idx !== thidx) {
thidx = idx;
ps.setPrefs('theme', { idx: thidx });
applyTheme();
@@ -94,18 +93,15 @@
function applyTheme(evt) {
thidx = ps.getPrefs('theme', { idx: thidx }).idx;
- if (currentTheme != thidx) {
- $log.info('Applying theme:', thidx);
- updateBodyClass();
- themeEvent(evt || 'set');
- }
+ $log.info('Applying theme:', thidx);
+ updateBodyClass();
+ themeEvent(evt || 'set');
}
function updateBodyClass() {
var body = d3.select('body');
body.classed(themeStr, false);
body.classed(getTheme(), true);
- currentTheme = thidx;
}
function themeEvent(w) {
@@ -123,7 +119,7 @@
}
function removeListener(lsnr) {
- listeners = listeners.filter(function(obj) { return obj === lsnr; });
+ listeners = listeners.filter(function(obj) { return obj !== lsnr; });
}
// color = logical color name
diff --git a/web/gui/src/main/webapp/tests/app/fw/util/theme-spec.js b/web/gui/src/main/webapp/tests/app/fw/util/theme-spec.js
index 066aa33..228b2f0 100644
--- a/web/gui/src/main/webapp/tests/app/fw/util/theme-spec.js
+++ b/web/gui/src/main/webapp/tests/app/fw/util/theme-spec.js
@@ -118,6 +118,10 @@
var cb = jasmine.createSpy('cb');
expect(cb.calls.count()).toEqual(0);
+ // make sure previous tests don't affect our theme state...
+ ts.theme('light');
+ expect(ts.theme()).toEqual('light');
+
ts.toggleTheme(); // -> dark
expect(cb.calls.count()).toEqual(0);
@@ -128,17 +132,16 @@
expect(cb.calls.count()).toEqual(1);
ts.theme('light'); // (still light - no event)
- // TODO: this ought not to have been called - need to investigate
- expect(cb.calls.count()).toEqual(2);
+ expect(cb.calls.count()).toEqual(1);
ts.theme('dark'); // -> dark
- expect(cb.calls.count()).toEqual(3);
+ expect(cb.calls.count()).toEqual(2);
ts.removeListener(cb);
- expect(cb.calls.count()).toEqual(3);
+ expect(cb.calls.count()).toEqual(2);
- ts.toggleTheme(); // -> light
- expect(cb.calls.count()).toEqual(4);
+ ts.toggleTheme(); // -> light (but we weren't registered to hear it)
+ expect(cb.calls.count()).toEqual(2);
});
});