From d3ca1b4b0df81860c01d2dc81f308e8fbebf6031 Mon Sep 17 00:00:00 2001 From: Caleb Cox Date: Wed, 3 Jan 2024 14:34:39 -0600 Subject: [PATCH] Move all new its into describe blocks --- test/spec/controllers/eventForm.spec.js | 64 +++++----- .../controllers/eventRegistrations.spec.js | 110 ++++++++++-------- .../controllers/reviewRegistration.spec.js | 44 ++++--- 3 files changed, 121 insertions(+), 97 deletions(-) diff --git a/test/spec/controllers/eventForm.spec.js b/test/spec/controllers/eventForm.spec.js index 5cc08ee35..c1d879083 100644 --- a/test/spec/controllers/eventForm.spec.js +++ b/test/spec/controllers/eventForm.spec.js @@ -122,13 +122,15 @@ describe('Controller: eventForm', function () { }); }); - it('previewForm navigates to the preview page', () => { - spyOn($location, 'path'); - scope.previewForm(); + describe('previewForm', () => { + it('navigates to the preview page', () => { + spyOn($location, 'path'); + scope.previewForm(); - expect($location.path).toHaveBeenCalledWith( - '/preview/c63b8abf-52ff-4cc4-afbc-5923b01f1ab0/page/', - ); + expect($location.path).toHaveBeenCalledWith( + '/preview/c63b8abf-52ff-4cc4-afbc-5923b01f1ab0/page/', + ); + }); }); describe('deletePage', () => { @@ -201,16 +203,18 @@ describe('Controller: eventForm', function () { }); }); - it('copyBlock copies an existing block', () => { - const existingBlock = scope.conference.registrationPages[1].blocks[3]; - scope.copyBlock(existingBlock.id); - const newBlock = scope.conference.registrationPages[1].blocks[4]; - - expect(newBlock.id).not.toBe(existingBlock.id); - expect(newBlock.position).toBe(4); - expect(newBlock.title).toBe('Dropdown Question (copy)'); - expect(newBlock.rules[0].id).not.toBe(existingBlock.rules[0].id); - expect(newBlock.rules[0].blockId).toBe(newBlock.id); + describe('copyBlock', () => { + it('copies an existing block', () => { + const existingBlock = scope.conference.registrationPages[1].blocks[3]; + scope.copyBlock(existingBlock.id); + const newBlock = scope.conference.registrationPages[1].blocks[4]; + + expect(newBlock.id).not.toBe(existingBlock.id); + expect(newBlock.position).toBe(4); + expect(newBlock.title).toBe('Dropdown Question (copy)'); + expect(newBlock.rules[0].id).not.toBe(existingBlock.rules[0].id); + expect(newBlock.rules[0].blockId).toBe(newBlock.id); + }); }); describe('insertBlock', () => { @@ -286,24 +290,28 @@ describe('Controller: eventForm', function () { }); }); - it('addNewPage adds a new page', () => { - scope.addNewPage(); - const newPage = scope.conference.registrationPages[2]; + describe('addNewPage', () => { + it('adds a new page', () => { + scope.addNewPage(); + const newPage = scope.conference.registrationPages[2]; - expect(scope.conference.registrationPages.length).toBe(3); - expect(newPage.title).toBe('Page 3'); - expect($location.hash()).toBe('page3'); + expect(scope.conference.registrationPages.length).toBe(3); + expect(newPage.title).toBe('Page 3'); + expect($location.hash()).toBe('page3'); + }); }); - it('togglePage toggles page visibility', () => { - const pageId = scope.conference.registrationPages[0].id; + describe('togglePage', () => { + it('toggles page visibility', () => { + const pageId = scope.conference.registrationPages[0].id; - scope.togglePage(pageId); + scope.togglePage(pageId); - expect(scope.isPageHidden(pageId)).toBe(true); + expect(scope.isPageHidden(pageId)).toBe(true); - scope.togglePage(pageId); + scope.togglePage(pageId); - expect(scope.isPageHidden(pageId)).toBe(false); + expect(scope.isPageHidden(pageId)).toBe(false); + }); }); }); diff --git a/test/spec/controllers/eventRegistrations.spec.js b/test/spec/controllers/eventRegistrations.spec.js index 0a372eb64..85e11caf6 100644 --- a/test/spec/controllers/eventRegistrations.spec.js +++ b/test/spec/controllers/eventRegistrations.spec.js @@ -131,55 +131,61 @@ describe('Controller: eventRegistrations', function () { }); }); - it('toggleColumn toggles the column visibility', () => { - const setItem = spyOn($window.localStorage, 'setItem'); - scope.toggleColumn(0); - - expect(scope.blocks[0].visible).toBe(true); - expect(setItem).toHaveBeenCalledWith( - `visibleBlocks:${testData.conference.id}`, - '["e088fefc-eb9c-4904-b849-017facc9e063"]', - ); + describe('toggleColumn', () => { + it('toggles the column visibility', () => { + const setItem = spyOn($window.localStorage, 'setItem'); + scope.toggleColumn(0); + + expect(scope.blocks[0].visible).toBe(true); + expect(setItem).toHaveBeenCalledWith( + `visibleBlocks:${testData.conference.id}`, + '["e088fefc-eb9c-4904-b849-017facc9e063"]', + ); - expect(scope.queryParameters.block).toEqual([ - 'e088fefc-eb9c-4904-b849-017facc9e063', - ]); + expect(scope.queryParameters.block).toEqual([ + 'e088fefc-eb9c-4904-b849-017facc9e063', + ]); - scope.toggleColumn(0); + scope.toggleColumn(0); - expect(scope.blocks[0].visible).toBe(false); - expect(setItem).toHaveBeenCalledWith( - `visibleBlocks:${testData.conference.id}`, - '[]', - ); + expect(scope.blocks[0].visible).toBe(false); + expect(setItem).toHaveBeenCalledWith( + `visibleBlocks:${testData.conference.id}`, + '[]', + ); - expect(scope.queryParameters.block).toEqual([]); + expect(scope.queryParameters.block).toEqual([]); + }); }); - it('toggleBuiltInColumn toggles the column visibility', () => { - const setItem = spyOn($window.localStorage, 'setItem'); - scope.toggleBuiltInColumn('Email'); + describe('toggleBuiltInColumn', () => { + it('toggles the column visibility', () => { + const setItem = spyOn($window.localStorage, 'setItem'); + scope.toggleBuiltInColumn('Email'); - expect(scope.builtInColumnsVisible.Email).toBe(false); - expect(setItem).toHaveBeenCalledWith( - `builtInColumnsVisibleStorage`, - '{"Email":false,"Group":true,"GroupId":false,"Started":true,"Completed":true}', - ); + expect(scope.builtInColumnsVisible.Email).toBe(false); + expect(setItem).toHaveBeenCalledWith( + `builtInColumnsVisibleStorage`, + '{"Email":false,"Group":true,"GroupId":false,"Started":true,"Completed":true}', + ); - scope.toggleBuiltInColumn('Email'); + scope.toggleBuiltInColumn('Email'); - expect(scope.builtInColumnsVisible.Email).toBe(true); - expect(setItem).toHaveBeenCalledWith( - `builtInColumnsVisibleStorage`, - '{"Email":true,"Group":true,"GroupId":false,"Started":true,"Completed":true}', - ); + expect(scope.builtInColumnsVisible.Email).toBe(true); + expect(setItem).toHaveBeenCalledWith( + `builtInColumnsVisibleStorage`, + '{"Email":true,"Group":true,"GroupId":false,"Started":true,"Completed":true}', + ); + }); }); - it('resetStrFilter clears the filter', () => { - scope.strFilter = 'Filter'; - scope.resetStrFilter(); + describe('resetStrFilter', () => { + it('clears the filter', () => { + scope.strFilter = 'Filter'; + scope.resetStrFilter(); - expect(scope.strFilter).toBe(''); + expect(scope.strFilter).toBe(''); + }); }); describe('isRegistrantReported', () => { @@ -384,24 +390,26 @@ describe('Controller: eventRegistrations', function () { }); }); - it('editRegistrant edits registrants', () => { - $httpBackend.expectGET(/^registrations\/.+$/).respond(200, {}); + describe('editRegistrant', () => { + it('edits registrants', () => { + $httpBackend.expectGET(/^registrations\/.+$/).respond(200, {}); - scope.editRegistrant(testData.registration.registrants[0]); + scope.editRegistrant(testData.registration.registrants[0]); - const newRegistration = { - ...testData.registration, - registrants: [ - { ...testData.registration.registrants[0], firstName: 'Updated' }, - testData.registration.registrants[1], - ], - }; + const newRegistration = { + ...testData.registration, + registrants: [ + { ...testData.registration.registrants[0], firstName: 'Updated' }, + testData.registration.registrants[1], + ], + }; - $httpBackend.flush(); - fakeModal.close(newRegistration); + $httpBackend.flush(); + fakeModal.close(newRegistration); - expect(scope.registrants[0].firstName).toBe('Updated'); - expect(scope.registrations[0]).toBe(newRegistration); + expect(scope.registrants[0].firstName).toBe('Updated'); + expect(scope.registrations[0]).toBe(newRegistration); + }); }); describe('withdrawRegistrant', () => { diff --git a/test/spec/controllers/reviewRegistration.spec.js b/test/spec/controllers/reviewRegistration.spec.js index 87e4eb7d7..11cca8c01 100644 --- a/test/spec/controllers/reviewRegistration.spec.js +++ b/test/spec/controllers/reviewRegistration.spec.js @@ -53,20 +53,26 @@ describe('Controller: ReviewRegistrationCtrl', function () { }); }); - it('currentPayment balance is set to the remaining balance', () => { - expect(scope.currentPayment.amount).toBe(49); + describe('currentPayment', () => { + it('should have balance set to the remaining balance', () => { + expect(scope.currentPayment.amount).toBe(49); + }); }); - it('findAnswer should return answer', function () { - expect(scope.findAnswer('9b83eebd-b064-4edf-92d0-7982a330272a').value).toBe( - 'M', - ); + describe('findAnswer', () => { + it('should return an answer', function () { + expect( + scope.findAnswer('9b83eebd-b064-4edf-92d0-7982a330272a').value, + ).toBe('M'); + }); }); - it('getBlock finds blocks by id', () => { - expect(scope.getBlock('e088fefc-eb9c-4904-b849-017facc9e063').title).toBe( - 'Email', - ); + describe('getBlock', () => { + it('finds a block by its id', () => { + expect(scope.getBlock('e088fefc-eb9c-4904-b849-017facc9e063').title).toBe( + 'Email', + ); + }); }); describe('registerDisabled', () => { @@ -76,7 +82,7 @@ describe('Controller: ReviewRegistrationCtrl', function () { expect(scope.registerDisabled()).toBe(true); }); - it('is true with invalid with invalid registrants', () => { + it('is true with invalid registrants', () => { spyOn(scope, 'allRegistrantsValid').and.returnValue(false); expect(scope.registerDisabled()).toBe(true); @@ -177,13 +183,15 @@ describe('Controller: ReviewRegistrationCtrl', function () { }); }); - it('blockVisibleForRegistrant should be true', function () { - expect( - scope.blockVisibleForRegistrant( - scope.conference.registrationPages[1].blocks[0], - scope.currentRegistration.registrants[0], - ), - ).toBe(true); + describe('blockVisibleForRegistrant', () => { + it('should return true for visible blocks', function () { + expect( + scope.blockVisibleForRegistrant( + scope.conference.registrationPages[1].blocks[0], + scope.currentRegistration.registrants[0], + ), + ).toBe(true); + }); }); describe('acceptedPaymentMethods', () => {