Skip to content

Commit

Permalink
Move all new its into describe blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
canac committed Jan 3, 2024
1 parent 93878dd commit d3ca1b4
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 97 deletions.
64 changes: 36 additions & 28 deletions test/spec/controllers/eventForm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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);
});
});
});
110 changes: 59 additions & 51 deletions test/spec/controllers/eventRegistrations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down
44 changes: 26 additions & 18 deletions test/spec/controllers/reviewRegistration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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);
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit d3ca1b4

Please sign in to comment.