diff --git a/platform/features/plot/src/elements/PlotAxis.js b/platform/features/plot/src/elements/PlotAxis.js index ff48af6e99..29e67d1976 100644 --- a/platform/features/plot/src/elements/PlotAxis.js +++ b/platform/features/plot/src/elements/PlotAxis.js @@ -92,7 +92,7 @@ define( if (!optionKeys[key] && !newOptions[key]) { toAdd.push(option); } - newOptions[option.key] = true; + newOptions[key] = true; }); }); diff --git a/platform/features/plot/test/elements/PlotAxisSpec.js b/platform/features/plot/test/elements/PlotAxisSpec.js index f4419096e4..f06f0c69cc 100644 --- a/platform/features/plot/test/elements/PlotAxisSpec.js +++ b/platform/features/plot/test/elements/PlotAxisSpec.js @@ -30,7 +30,12 @@ define( "use strict"; describe("A plot axis", function () { - var testMetadatas = [ + var testMetadatas, + testDefault, + axis; + + beforeEach(function () { + testMetadatas = [ { tests: [ { key: "t0", name: "T0" }, @@ -52,13 +57,14 @@ define( { key: "t6", name: "T6" } ] } - ], - testDefault = { key: "test", name: "Test" }, - controller = new PlotAxis("tests", testMetadatas, testDefault); + ]; + testDefault = { key: "test", name: "Test" }; + axis = new PlotAxis("tests", testMetadatas, testDefault); + }); it("pulls out a list of domain or range options", function () { // Should have filtered out duplicates, etc - expect(controller.options).toEqual([ + expect(axis.options).toEqual([ { key: "t0", name: "T0" }, { key: "t1", name: "T1" }, { key: "t2", name: "T2" }, @@ -70,7 +76,7 @@ define( }); it("chooses the first option as a default", function () { - expect(controller.active).toEqual({ key: "t0", name: "T0" }); + expect(axis.active).toEqual({ key: "t0", name: "T0" }); }); it("falls back to a provided default if no options are present", function () { @@ -78,6 +84,26 @@ define( .toEqual(testDefault); }); + it("allows options to be chosen by key", function () { + axis.chooseOption("t3"); + expect(axis.active).toEqual({ key: "t3", name: "T3" }); + }); + + it("reflects changes to applicable metadata", function () { + axis.updateMetadata([ testMetadatas[1] ]); + expect(axis.options).toEqual([ + { key: "t0", name: "T0" }, + { key: "t2", name: "T2" } + ]); + }); + + it("returns the same array instance for unchanged metadata", function () { + // ...to avoid triggering extra digest cycles. + var oldInstance = axis.options; + axis.updateMetadata(testMetadatas); + expect(axis.options).toBe(oldInstance); + }); + }); } );