[Info Service] Update spec

...to reflect usage of popupService.
This commit is contained in:
Victor Woeltjen 2015-10-02 14:49:27 -07:00
parent 553b17fafe
commit 99048a4ee3

View File

@ -28,117 +28,85 @@ define(
describe("The info service", function () { describe("The info service", function () {
var mockCompile, var mockCompile,
mockDocument,
testWindow,
mockRootScope, mockRootScope,
mockPopupService,
mockAgentService, mockAgentService,
mockCompiledTemplate, mockScope,
testScope, mockElements,
mockBody, mockPopup,
mockElement,
service; service;
beforeEach(function () { beforeEach(function () {
mockCompile = jasmine.createSpy('$compile'); mockCompile = jasmine.createSpy('$compile');
mockDocument = jasmine.createSpyObj('$document', ['find']);
testWindow = { innerWidth: 1000, innerHeight: 100 };
mockRootScope = jasmine.createSpyObj('$rootScope', ['$new']); mockRootScope = jasmine.createSpyObj('$rootScope', ['$new']);
mockAgentService = jasmine.createSpyObj('agentService', ['isMobile', 'isPhone']); mockAgentService = jasmine.createSpyObj('agentService', ['isMobile', 'isPhone']);
mockCompiledTemplate = jasmine.createSpy('template'); mockPopupService = jasmine.createSpyObj(
testScope = {}; 'popupService',
mockBody = jasmine.createSpyObj('body', ['append']); ['display']
mockElement = jasmine.createSpyObj('element', ['css', 'remove']); );
mockPopup = jasmine.createSpyObj('popup', [
'dismiss',
'goesLeft',
'goesRight',
'goesUp',
'goesDown'
]);
mockDocument.find.andCallFake(function (tag) { mockScope = jasmine.createSpyObj("scope", ["$destroy"]);
return tag === 'body' ? mockBody : undefined; mockElements = [];
});
mockCompile.andReturn(mockCompiledTemplate); mockPopupService.display.andReturn(mockPopup);
mockCompile.andCallFake(function () {
var mockCompiledTemplate = jasmine.createSpy('template'),
mockElement = jasmine.createSpyObj('element', [
'css',
'remove',
'append'
]);
mockCompiledTemplate.andReturn(mockElement); mockCompiledTemplate.andReturn(mockElement);
mockRootScope.$new.andReturn(testScope); mockElements.push(mockElement);
return mockCompiledTemplate;
});
mockRootScope.$new.andReturn(mockScope);
service = new InfoService( service = new InfoService(
mockCompile, mockCompile,
mockDocument,
testWindow,
mockRootScope, mockRootScope,
mockPopupService,
mockAgentService mockAgentService
); );
}); });
it("creates elements and appends them to the body to display", function () { it("creates elements and displays them as popups", function () {
service.display('', '', {}, [0, 0]); service.display('', '', {}, [123, 456]);
expect(mockBody.append).toHaveBeenCalledWith(mockElement); expect(mockPopupService.display).toHaveBeenCalledWith(
mockElements[0],
[ 123, 456 ],
jasmine.any(Object)
);
}); });
it("provides a function to remove displayed info bubbles", function () { it("provides a function to remove displayed info bubbles", function () {
var fn = service.display('', '', {}, [0, 0]); var fn = service.display('', '', {}, [0, 0]);
expect(mockElement.remove).not.toHaveBeenCalled(); expect(mockPopup.dismiss).not.toHaveBeenCalled();
fn(); fn();
expect(mockElement.remove).toHaveBeenCalled(); expect(mockPopup.dismiss).toHaveBeenCalled();
}); });
describe("depending on mouse position", function () { it("when on phone device, positions at bottom", function () {
// Positioning should vary based on quadrant in window,
// which is 1000 x 100 in this test case.
it("displays from the top-left in the top-left quadrant", function () {
service.display('', '', {}, [250, 25]);
expect(mockElement.css).toHaveBeenCalledWith(
'left',
(250 + InfoConstants.BUBBLE_OFFSET[0]) + 'px'
);
expect(mockElement.css).toHaveBeenCalledWith(
'top',
(25 + InfoConstants.BUBBLE_OFFSET[1]) + 'px'
);
});
it("displays from the top-right in the top-right quadrant", function () {
service.display('', '', {}, [700, 25]);
expect(mockElement.css).toHaveBeenCalledWith(
'right',
(300 + InfoConstants.BUBBLE_OFFSET[0]) + 'px'
);
expect(mockElement.css).toHaveBeenCalledWith(
'top',
(25 + InfoConstants.BUBBLE_OFFSET[1]) + 'px'
);
});
it("displays from the bottom-left in the bottom-left quadrant", function () {
service.display('', '', {}, [250, 70]);
expect(mockElement.css).toHaveBeenCalledWith(
'left',
(250 + InfoConstants.BUBBLE_OFFSET[0]) + 'px'
);
expect(mockElement.css).toHaveBeenCalledWith(
'bottom',
(30 + InfoConstants.BUBBLE_OFFSET[1]) + 'px'
);
});
it("displays from the bottom-right in the bottom-right quadrant", function () {
service.display('', '', {}, [800, 60]);
expect(mockElement.css).toHaveBeenCalledWith(
'right',
(200 + InfoConstants.BUBBLE_OFFSET[0]) + 'px'
);
expect(mockElement.css).toHaveBeenCalledWith(
'bottom',
(40 + InfoConstants.BUBBLE_OFFSET[1]) + 'px'
);
});
it("when on phone device, positioning is always on bottom", function () {
mockAgentService.isPhone.andReturn(true); mockAgentService.isPhone.andReturn(true);
service = new InfoService( service = new InfoService(
mockCompile, mockCompile,
mockDocument,
testWindow,
mockRootScope, mockRootScope,
mockPopupService,
mockAgentService mockAgentService
); );
service.display('', '', {}, [0, 0]); service.display('', '', {}, [123, 456]);
}); expect(mockPopupService.display).toHaveBeenCalledWith(
mockElements[0],
[ 0, -25 ],
jasmine.any(Object)
);
}); });
}); });