diff --git a/platform/features/layout/test/elements/ElementFactorySpec.js b/platform/features/layout/test/elements/ElementFactorySpec.js index 795a06f314..4dec7a4357 100644 --- a/platform/features/layout/test/elements/ElementFactorySpec.js +++ b/platform/features/layout/test/elements/ElementFactorySpec.js @@ -5,7 +5,46 @@ define( function (ElementFactory) { "use strict"; + var DIALOG_ELEMENTS = [ 'image', 'text' ], + NON_DIALOG_ELEMENTS = [ 'box', 'line' ]; + describe("The fixed position element factory", function () { + var mockDialogService, + mockPromise, + factory; + + beforeEach(function () { + mockDialogService = jasmine.createSpyObj( + 'dialogService', + [ 'getUserInput' ] + ); + mockPromise = jasmine.createSpyObj( + 'promise', + [ 'then' ] + ); + + mockDialogService.getUserInput.andReturn(mockPromise); + mockPromise.then.andReturn(mockPromise); + + factory = new ElementFactory(mockDialogService); + }); + + DIALOG_ELEMENTS.forEach(function (type) { + it("shows a dialog for " + type + " elements", function () { + expect(factory.createElement('fixed.' + type)) + .toEqual(mockPromise); + expect(mockDialogService.getUserInput).toHaveBeenCalled(); + }); + }); + + NON_DIALOG_ELEMENTS.forEach(function (type) { + it("immediately provides " + type + " elements", function () { + var result = factory.createElement('fixed.' + type); + expect(result).toBeDefined(); + expect(result).not.toEqual(mockPromise); + expect(mockDialogService.getUserInput).not.toHaveBeenCalled(); + }); + }); }); } ); \ No newline at end of file diff --git a/platform/features/layout/test/elements/LineProxySpec.js b/platform/features/layout/test/elements/LineProxySpec.js index 08cba55b6e..fe38c7c3c9 100644 --- a/platform/features/layout/test/elements/LineProxySpec.js +++ b/platform/features/layout/test/elements/LineProxySpec.js @@ -6,6 +6,67 @@ define( "use strict"; describe("A fixed position line proxy", function () { + var vertical, horizontal, diagonal, reversed; + + beforeEach(function () { + vertical = { x: 1, y: 4, x2: 1, y2: 8 }; + horizontal = { x: 3, y: 3, x2: 12, y2: 3 }; + diagonal = { x: 3, y: 8, x2: 5, y2: 11 }; + reversed = { x2: 3, y2: 8, x: 5, y: 11 }; + }); + + it("ensures visible width for vertical lines", function () { + expect(new LineProxy(vertical).width()).toEqual(1); + }); + + it("ensures visible height for horizontal lines", function () { + expect(new LineProxy(horizontal).height()).toEqual(1); + }); + + it("provides a bounding box for lines", function () { + var proxy = new LineProxy(diagonal); + expect(proxy.x()).toEqual(3); + expect(proxy.y()).toEqual(8); + expect(proxy.width()).toEqual(2); + expect(proxy.height()).toEqual(3); + }); + + it("bounds lines identically regardless of point order", function () { + // That is, x(), width(), y(), and height() should always give + // the same results for the same line segments, regardless of + // which point is x,y and which is x2,y2 + ['x', 'y', 'width', 'height'].forEach(function (method) { + expect(new LineProxy(diagonal)[method]()) + .toEqual(new LineProxy(reversed)[method]()); + }); + }); + + it("adjusts both ends when mutating x", function () { + var proxy = new LineProxy(diagonal); + proxy.x(6); + expect(diagonal).toEqual({ x: 6, y: 8, x2: 8, y2: 11 }); + }); + + it("adjusts both ends when mutating y", function () { + var proxy = new LineProxy(diagonal); + proxy.y(6); + expect(diagonal).toEqual({ x: 3, y: 6, x2: 5, y2: 9 }); + }); + + it("provides internal positions for SVG lines", function () { + var proxy; + proxy = new LineProxy(diagonal); + expect(proxy.x1()).toEqual(0); + expect(proxy.y1()).toEqual(0); + expect(proxy.x2()).toEqual(2); + expect(proxy.y2()).toEqual(3); + proxy = new LineProxy(reversed); + expect(proxy.x1()).toEqual(2); + expect(proxy.y1()).toEqual(3); + expect(proxy.x2()).toEqual(0); + expect(proxy.y2()).toEqual(0); + }); + }); } ); \ No newline at end of file