From 4cc412ef4ffcb6b9c53dad72cd4ac036bc743d5c Mon Sep 17 00:00:00 2001 From: Jamie V Date: Mon, 13 Jan 2025 14:09:40 -0800 Subject: [PATCH] note session selector test is better done with e2e now --- .../SessionSelectorControllerSpec.js | 451 +++++++++--------- 1 file changed, 220 insertions(+), 231 deletions(-) diff --git a/src/services/session/test/controllers/SessionSelectorControllerSpec.js b/src/services/session/test/controllers/SessionSelectorControllerSpec.js index a94d796..3fb5e19 100644 --- a/src/services/session/test/controllers/SessionSelectorControllerSpec.js +++ b/src/services/session/test/controllers/SessionSelectorControllerSpec.js @@ -1,281 +1,270 @@ -/*global define,describe,beforeEach,jasmine,Promise,it,expect,afterEach, - waitsFor,runs*/ +import SessionSelectorController from '../SessionSelectorController'; + +// this would be better tested in an e2e test +xdescribe('SessionSelectorController', function () { + let $scope; + let sessionService; + let controller; + + beforeEach(function () { + $scope = jasmine.createSpyObj('$scope', ['$digest']); + $scope.ngModel = { + dismiss: jasmine.createSpy('dismiss') + }; + + sessionService = jasmine.createSpyObj( + 'sessionService', + [ + 'setActiveTopicOrSession', + 'isActiveTopic', + 'isActiveSession', + 'getTopicsWithSessions' + ] + ); + + sessionService.isActiveTopic.and.returnValue(false); + sessionService.isActiveSession.and.returnValue(false); + + sessionService.getTopicsWithSessions.and.returnValue(Promise.resolve([ + { + topic: 'AMPCS.a', + jms_subtopic: 'a', + sessions: [ + { + number: 1, + topic: 'AMPCS.a', + jms_subtopic: 'a', + }, + { + number: 2, + topic: 'AMPCS.a', + jms_subtopic: 'a', + } + ] + }, + { + topic: 'AMPCS.b', + jms_subtopic: 'b', + sessions: [] + } + ])); + }); -define([ - // '../../src/controllers/SessionSelectorController' -], function ( - // SessionSelectorController -) { - 'use strict'; + describe('instantiation', function () { + beforeEach(function () { + controller = new SessionSelectorController($scope, sessionService); + }); - xdescribe('SessionSelectorController', function () { - var $scope, - sessionService, - controller; + it('sets scope variables', function () { + expect($scope.selection).toBeUndefined(); + expect($scope.topics.length).toBe(0); + }); - beforeEach(function () { - $scope = jasmine.createSpyObj('$scope', ['$digest']); - $scope.ngModel = { - dismiss: jasmine.createSpy('dismiss') - }; + it('immediately starts loading sessions', function () { + expect($scope.loading).toBe(true); + expect(sessionService.getTopicsWithSessions).toHaveBeenCalled(); + }); + }); - sessionService = jasmine.createSpyObj( - 'sessionService', - [ - 'setActiveTopicOrSession', - 'isActiveTopic', - 'isActiveSession', - 'getTopicsWithSessions' - ] - ); + describe('after loading', function () { + beforeEach(function (done) { + $scope.$digest.and.callFake(done); + controller = new SessionSelectorController($scope, sessionService); + }); - sessionService.isActiveTopic.and.returnValue(false); - sessionService.isActiveSession.and.returnValue(false); + it('is no longer loading', function () { + expect($scope.loading).toBe(false); + }); - sessionService.getTopicsWithSessions.and.returnValue(Promise.resolve([ - { + it('has populated topics', function () { + expect($scope.topics.length).toBe(2); + expect($scope.topics).toContain({ + selected: false, + expanded: false, + data: { topic: 'AMPCS.a', jms_subtopic: 'a', - sessions: [ - { - number: 1, + sessions: jasmine.any(Array) + }, + sessions: [ + { + selected: false, + data: { topic: 'AMPCS.a', jms_subtopic: 'a', - }, - { - number: 2, + number: 1 + } + }, + { + selected: false, + data: { topic: 'AMPCS.a', jms_subtopic: 'a', + number: 2 } - ] - }, - { + } + ] + }); + + expect($scope.topics).toContain({ + selected: false, + expanded: false, + data: { topic: 'AMPCS.b', jms_subtopic: 'b', sessions: [] - } - ])); - }); - - describe('instantiation', function () { - beforeEach(function () { - controller = new SessionSelectorController($scope, sessionService); - }); - - it('sets scope variables', function () { - expect($scope.selection).toBeUndefined(); - expect($scope.topics.length).toBe(0); - }); - - it('immediately starts loading sessions', function () { - expect($scope.loading).toBe(true); - expect(sessionService.getTopicsWithSessions).toHaveBeenCalled(); + }, + sessions: [] }); }); - describe('after loading', function () { - beforeEach(function (done) { - $scope.$digest.and.callFake(done); - controller = new SessionSelectorController($scope, sessionService); - }); - - it('is no longer loading', function () { - expect($scope.loading).toBe(false); - }); + it('does not have a selection', function () { + expect($scope.selection).toBeUndefined(); + }); + }); - it('has populated topics', function () { - expect($scope.topics.length).toBe(2); - expect($scope.topics).toContain({ - selected: false, - expanded: false, - data: { - topic: 'AMPCS.a', - jms_subtopic: 'a', - sessions: jasmine.any(Array) - }, - sessions: [ - { - selected: false, - data: { - topic: 'AMPCS.a', - jms_subtopic: 'a', - number: 1 - } - }, - { - selected: false, - data: { - topic: 'AMPCS.a', - jms_subtopic: 'a', - number: 2 - } - } - ] + describe('loading with selected topic', function () { + beforeEach(function (done) { + $scope.$digest.and.callFake(done); + sessionService + .isActiveTopic + .and.callFake(function (model) { + return model.topic === 'AMPCS.b' && !model.number; }); + controller = new SessionSelectorController($scope, sessionService); + }); - expect($scope.topics).toContain({ - selected: false, - expanded: false, - data: { - topic: 'AMPCS.b', - jms_subtopic: 'b', - sessions: [] - }, + it('has a selection', function () { + expect($scope.selection).toBeDefined(); + expect($scope.selection).toEqual({ + selected: true, + expanded: false, + data: { + topic: 'AMPCS.b', + jms_subtopic: 'b', sessions: [] - }); - }); - - it('does not have a selection', function () { - expect($scope.selection).toBeUndefined(); + }, + sessions: [] }); + expect($scope.selection).toBe($scope.topics[1]); }); + }); - describe('loading with selected topic', function () { - beforeEach(function (done) { - $scope.$digest.and.callFake(done); - sessionService - .isActiveTopic - .and.callFake(function (model) { - return model.topic === 'AMPCS.b' && !model.number; - }); - controller = new SessionSelectorController($scope, sessionService); - }); - - it('has a selection', function () { - expect($scope.selection).toBeDefined(); - expect($scope.selection).toEqual({ - selected: true, - expanded: false, - data: { - topic: 'AMPCS.b', - jms_subtopic: 'b', - sessions: [] - }, - sessions: [] + describe('loading with selected session', function () { + beforeEach(function (done) { + $scope.$digest.and.callFake(done); + sessionService + .isActiveSession + .and.callFake(function (model) { + return model.topic === 'AMPCS.a' && + model.number === 2; }); - expect($scope.selection).toBe($scope.topics[1]); - }); + controller = new SessionSelectorController($scope, sessionService); }); - describe('loading with selected session', function () { - beforeEach(function (done) { - $scope.$digest.and.callFake(done); - sessionService - .isActiveSession - .and.callFake(function (model) { - return model.topic === 'AMPCS.a' && - model.number === 2; - }); - controller = new SessionSelectorController($scope, sessionService); - }); - - it('has a selection', function () { - expect($scope.selection).toBeDefined(); - expect($scope.selection).toEqual({ - selected: true, - data: { - topic: 'AMPCS.a', - jms_subtopic: 'a', - number: 2 - } - }); - expect($scope.selection).toBe($scope.topics[0].sessions[1]); + it('has a selection', function () { + expect($scope.selection).toBeDefined(); + expect($scope.selection).toEqual({ + selected: true, + data: { + topic: 'AMPCS.a', + jms_subtopic: 'a', + number: 2 + } }); + expect($scope.selection).toBe($scope.topics[0].sessions[1]); + }); - it('expands the containing topic', function () { - expect($scope.topics[0].expanded).toBe(true); - }); + it('expands the containing topic', function () { + expect($scope.topics[0].expanded).toBe(true); }); + }); - describe('selecting a session', function () { - beforeEach(function (done) { - $scope.$digest.and.callFake(() => { - controller.select($scope.topics[0].sessions[0]); - done(); - }); - controller = new SessionSelectorController($scope, sessionService); + describe('selecting a session', function () { + beforeEach(function (done) { + $scope.$digest.and.callFake(() => { + controller.select($scope.topics[0].sessions[0]); + done(); }); + controller = new SessionSelectorController($scope, sessionService); + }); - it('marks the session as selected', function () { - expect($scope.selection).toBe($scope.topics[0].sessions[0]); - expect($scope.selection.selected).toBe(true); - }); + it('marks the session as selected', function () { + expect($scope.selection).toBe($scope.topics[0].sessions[0]); + expect($scope.selection.selected).toBe(true); + }); - it('deselects when selecting a different session', function () { - controller.select($scope.topics[0].sessions[1]); - expect($scope.selection).toBe($scope.topics[0].sessions[1]); - expect($scope.selection.selected).toBe(true); - expect($scope.topics[0].sessions[0].selected).toBe(false); - }); + it('deselects when selecting a different session', function () { + controller.select($scope.topics[0].sessions[1]); + expect($scope.selection).toBe($scope.topics[0].sessions[1]); + expect($scope.selection.selected).toBe(true); + expect($scope.topics[0].sessions[0].selected).toBe(false); + }); - it('deselects when selecting a topic', function () { - controller.select($scope.topics[0]); - expect($scope.selection).toBe($scope.topics[0]); - expect($scope.selection.selected).toBe(true); - expect($scope.topics[0].sessions[0].selected).toBe(false); - }); + it('deselects when selecting a topic', function () { + controller.select($scope.topics[0]); + expect($scope.selection).toBe($scope.topics[0]); + expect($scope.selection.selected).toBe(true); + expect($scope.topics[0].sessions[0].selected).toBe(false); + }); - it('changes active topic when confirmed', function () { - controller.confirm(); - expect(sessionService.setActiveTopicOrSession) - .toHaveBeenCalledWith($scope.selection.data); - expect($scope.ngModel.dismiss).toHaveBeenCalled(); - }); + it('changes active topic when confirmed', function () { + controller.confirm(); + expect(sessionService.setActiveTopicOrSession) + .toHaveBeenCalledWith($scope.selection.data); + expect($scope.ngModel.dismiss).toHaveBeenCalled(); + }); - it('does not change active topic when canceled', function () { - controller.cancel(); - expect(sessionService.setActiveTopicOrSession) - .not - .toHaveBeenCalled(); - expect($scope.ngModel.dismiss).toHaveBeenCalled(); - }); + it('does not change active topic when canceled', function () { + controller.cancel(); + expect(sessionService.setActiveTopicOrSession) + .not + .toHaveBeenCalled(); + expect($scope.ngModel.dismiss).toHaveBeenCalled(); }); + }); - describe('selecting a topic', function () { - beforeEach(function (done) { - $scope.$digest.and.callFake(() => { - controller.select($scope.topics[0]); - done(); - }); - controller = new SessionSelectorController($scope, sessionService); + describe('selecting a topic', function () { + beforeEach(function (done) { + $scope.$digest.and.callFake(() => { + controller.select($scope.topics[0]); + done(); }); + controller = new SessionSelectorController($scope, sessionService); + }); - it('marks the topic as selected', function () { - expect($scope.selection).toBe($scope.topics[0]); - expect($scope.selection.selected).toBe(true); - }); + it('marks the topic as selected', function () { + expect($scope.selection).toBe($scope.topics[0]); + expect($scope.selection.selected).toBe(true); + }); - it('deselects when selecting a different session', function () { - controller.select($scope.topics[0].sessions[1]); - expect($scope.selection).toBe($scope.topics[0].sessions[1]); - expect($scope.selection.selected).toBe(true); - expect($scope.topics[0].selected).toBe(false); - }); + it('deselects when selecting a different session', function () { + controller.select($scope.topics[0].sessions[1]); + expect($scope.selection).toBe($scope.topics[0].sessions[1]); + expect($scope.selection.selected).toBe(true); + expect($scope.topics[0].selected).toBe(false); + }); - it('deselects when selecting a different topic', function () { - controller.select($scope.topics[1]); - expect($scope.selection).toBe($scope.topics[1]); - expect($scope.selection.selected).toBe(true); - expect($scope.topics[0].selected).toBe(false); - }); + it('deselects when selecting a different topic', function () { + controller.select($scope.topics[1]); + expect($scope.selection).toBe($scope.topics[1]); + expect($scope.selection.selected).toBe(true); + expect($scope.topics[0].selected).toBe(false); + }); - it('changes active topic when confirmed', function () { - controller.confirm(); - expect(sessionService.setActiveTopicOrSession) - .toHaveBeenCalledWith($scope.selection.data); - expect($scope.ngModel.dismiss).toHaveBeenCalled(); - }); + it('changes active topic when confirmed', function () { + controller.confirm(); + expect(sessionService.setActiveTopicOrSession) + .toHaveBeenCalledWith($scope.selection.data); + expect($scope.ngModel.dismiss).toHaveBeenCalled(); + }); - it('does not change active topic when canceled', function () { - controller.cancel(); - expect(sessionService.setActiveTopicOrSession) - .not - .toHaveBeenCalled(); - expect($scope.ngModel.dismiss).toHaveBeenCalled(); - }); + it('does not change active topic when canceled', function () { + controller.cancel(); + expect(sessionService.setActiveTopicOrSession) + .not + .toHaveBeenCalled(); + expect($scope.ngModel.dismiss).toHaveBeenCalled(); }); }); }); - -/* Sample promise for controller functionality */ -