From a58b643a26cacebff5994153e35c9676a355c2ae Mon Sep 17 00:00:00 2001 From: grosbouddha Date: Wed, 16 Sep 2015 01:13:21 +0200 Subject: [PATCH] Add SelectedColorsService unit tests --- test/js/service/SelectedColorsServiceTest.js | 37 ++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 test/js/service/SelectedColorsServiceTest.js diff --git a/test/js/service/SelectedColorsServiceTest.js b/test/js/service/SelectedColorsServiceTest.js new file mode 100644 index 00000000..cb6f5584 --- /dev/null +++ b/test/js/service/SelectedColorsServiceTest.js @@ -0,0 +1,37 @@ + +describe("SelectedColorsService test suite", function() { + it("returns the default selected colors initially", function() { + var service = new pskl.service.SelectedColorsService(); + + var defaultSelectedColors = service.getColors(); + expect(defaultSelectedColors.length).toBe(2); + expect(defaultSelectedColors[0]).toBe(Constants.DEFAULT_PEN_COLOR); + expect(defaultSelectedColors[1]).toBe(Constants.TRANSPARENT_COLOR); + }); + + it("reacts to PRIMARY_COLOR_SELECTED event", function() { + var service = new pskl.service.SelectedColorsService(); + service.init(); + + var expectedColor = "#123456"; + $.publish(Events.PRIMARY_COLOR_SELECTED, [expectedColor]); + + var defaultSelectedColors = service.getColors(); + expect(defaultSelectedColors.length).toBe(2); + expect(defaultSelectedColors[0]).toBe(expectedColor); + expect(defaultSelectedColors[1]).toBe(Constants.TRANSPARENT_COLOR); + }); + + it("reacts to SECONDARY_COLOR_SELECTED event", function() { + var service = new pskl.service.SelectedColorsService(); + service.init(); + + var expectedColor = "#123456"; + $.publish(Events.SECONDARY_COLOR_SELECTED, [expectedColor]); + + var defaultSelectedColors = service.getColors(); + expect(defaultSelectedColors.length).toBe(2); + expect(defaultSelectedColors[0]).toBe(Constants.DEFAULT_PEN_COLOR); + expect(defaultSelectedColors[1]).toBe(expectedColor); + }); +}); \ No newline at end of file