#783 test fixes and naming corrections

This commit is contained in:
Carlos Jimenez 2018-11-06 14:27:16 +01:00
parent 1ad44f22b4
commit 8e648864df
8 changed files with 125 additions and 126 deletions

View File

@ -1,13 +1,13 @@
describe('Component vnAutocomplete', () => {
let $element;
let $ctrl;
let controller;
let data = {id: 1, name: 'Bruce Wayne'};
beforeEach(ngModule('vnCore'));
beforeEach(inject(($compile, $rootScope) => {
$element = $compile(`<vn-autocomplete></vn-autocomplete>`)($rootScope);
$ctrl = $element.controller('vnAutocomplete');
controller = $element.controller('vnAutocomplete');
}));
afterEach(() => {
@ -16,47 +16,47 @@ describe('Component vnAutocomplete', () => {
describe('url() setter', () => {
it(`should set the url property`, () => {
$ctrl.url = '/TestModels';
controller.url = '/TestModels';
expect($ctrl.url).toEqual('/TestModels');
expect(controller.url).toEqual('/TestModels');
});
});
describe('field() setter/getter', () => {
it(`should set the field property`, () => {
$ctrl.field = 'id';
controller.field = 'id';
expect($ctrl.field).toEqual('id');
expect(controller.field).toEqual('id');
});
});
describe('selection property', () => {
beforeEach(() => {
$ctrl.field = data.id;
controller.field = data.id;
});
it(`should set selection finding an existing item in the initialData property`, () => {
$ctrl.initialData = data;
controller.initialData = data;
expect($ctrl.selection).toEqual(data);
expect(controller.selection).toEqual(data);
});
it(`should set selection finding an existing item in the data property`, () => {
$ctrl.data = [data];
controller.data = [data];
expect($ctrl.selection).toEqual(data);
expect(controller.selection).toEqual(data);
});
it(`should perform a query if the item id isn't present in the data property`, inject($httpBackend => {
$httpBackend.whenGET(/testUrl.*/).respond([data]);
$ctrl.url = 'testUrl';
controller.url = 'testUrl';
$httpBackend.flush();
expect($ctrl.selection).toEqual(data);
expect(controller.selection).toEqual(data);
}));
it(`should set selection to null when can't find an existing item in the data property`, () => {
expect($ctrl.selection).toEqual(null);
expect(controller.selection).toEqual(null);
});
});
});

View File

@ -1,13 +1,13 @@
describe('Component vnDropDown', () => {
let $element;
let $ctrl;
let controller;
beforeEach(ngModule('vnCore'));
beforeEach(inject(($compile, $rootScope, $document) => {
$element = $compile(`<vn-drop-down></vn-drop-down>`)($rootScope);
$document.find('body').append($element);
$ctrl = $element.controller('vnDropDown');
controller = $element.controller('vnDropDown');
}));
afterEach(() => {
@ -16,17 +16,17 @@ describe('Component vnDropDown', () => {
describe('show() method', () => {
it(`should enable the show property`, () => {
$ctrl.show();
controller.show();
expect($ctrl.shown).toEqual(true);
expect(controller.shown).toEqual(true);
});
});
describe('hide() method', () => {
it(`should disable the show property`, () => {
$ctrl.hide();
controller.hide();
expect($ctrl.shown).toEqual(false);
expect(controller.shown).toEqual(false);
});
});
});

View File

@ -1,12 +1,12 @@
describe('Component vnIconMenu', () => {
let $ctrl;
let controller;
let $element;
beforeEach(ngModule('vnCore'));
beforeEach(inject(($compile, $rootScope) => {
$element = $compile(`<vn-icon-menu></vn-icon-menu>`)($rootScope);
$ctrl = $element.controller('vnIconMenu');
controller = $element.controller('vnIconMenu');
}));
afterEach(() => {
@ -15,26 +15,26 @@ describe('Component vnIconMenu', () => {
describe('onClick(event)', () => {
it(`should emit the open event`, () => {
spyOn($ctrl, 'emit');
spyOn(controller, 'emit');
let event = new MouseEvent('click', {
view: $ctrl.element.window,
view: controller.element.window,
bubbles: true,
cancelable: true
});
$ctrl.onClick(event);
controller.onClick(event);
expect($ctrl.emit).toHaveBeenCalledWith('open');
expect(controller.emit).toHaveBeenCalledWith('open');
});
});
describe('onDropDownSelect(value)', () => {
it(`should set field to the given value and emit the change event`, () => {
spyOn($ctrl, 'emit');
$ctrl.onDropDownSelect('mariano');
spyOn(controller, 'emit');
controller.onDropDownSelect('mariano');
expect($ctrl.field).toBe('mariano');
expect($ctrl.emit).toHaveBeenCalledWith('change', {value: 'mariano'});
expect(controller.field).toBe('mariano');
expect(controller.emit).toHaveBeenCalledWith('change', {value: 'mariano'});
});
});
});

View File

@ -2,14 +2,14 @@
describe('Component vnPopover', () => {
let $element;
let $parent;
let $ctrl;
let controller;
beforeEach(ngModule('vnCore'));
beforeEach(inject(($compile, $rootScope, $document) => {
$element = $compile(`<vn-popover>test</vn-popover>`)($rootScope);
$document.find('body').append($element);
$ctrl = $element.controller('vnPopover');
controller = $element.controller('vnPopover');
$parent = angular.element('<div/>');
$document.find('body').append($parent);
@ -22,19 +22,19 @@ describe('Component vnPopover', () => {
describe('show()', () => {
it(`should enable the shown property and emit the open event`, () => {
spyOn($ctrl, 'emit');
$ctrl.show();
spyOn(controller, 'emit');
controller.show();
expect($ctrl.shown).toBeTruthy();
expect($ctrl.emit).toHaveBeenCalledWith('open');
expect(controller.shown).toBeTruthy();
expect(controller.emit).toHaveBeenCalledWith('open');
});
it(`should do nothing if it's already shown`, () => {
$ctrl.shown = true;
spyOn($ctrl, 'emit');
$ctrl.show();
controller.shown = true;
spyOn(controller, 'emit');
controller.show();
expect($ctrl.emit).not.toHaveBeenCalledWith('open');
expect(controller.emit).not.toHaveBeenCalledWith('open');
});
it(`should check that popover is visible into the screen`, () => {
@ -46,38 +46,38 @@ describe('Component vnPopover', () => {
top: '0',
left: '100px'
});
$ctrl.show($parent[0]);
controller.show($parent[0]);
let rect = $ctrl.popover.getBoundingClientRect();
let style = $ctrl.window.getComputedStyle($ctrl.element);
let rect = controller.popover.getBoundingClientRect();
let style = controller.window.getComputedStyle(controller.element);
expect(style.visibility).toEqual('visible');
expect(style.display).not.toEqual('none');
expect(0).toBeLessThanOrEqual(rect.top);
expect(0).toBeLessThanOrEqual(rect.left);
expect($ctrl.window.innerHeight).toBeGreaterThan(rect.bottom);
expect($ctrl.window.innerWidth).toBeGreaterThan(rect.right);
expect(controller.window.innerHeight).toBeGreaterThan(rect.bottom);
expect(controller.window.innerWidth).toBeGreaterThan(rect.right);
});
});
describe('hide()', () => {
it(`should disable the shown property and emit the close event`, inject($timeout => {
$ctrl.show();
spyOn($ctrl, 'emit');
$ctrl.hide();
controller.show();
spyOn(controller, 'emit');
controller.hide();
$timeout.flush();
expect($ctrl.shown).toBeFalsy();
expect($ctrl.emit).toHaveBeenCalledWith('close');
expect(controller.shown).toBeFalsy();
expect(controller.emit).toHaveBeenCalledWith('close');
}));
it(`should do nothing if it's already hidden`, () => {
$ctrl.shown = false;
spyOn($ctrl, 'emit');
$ctrl.hide();
controller.shown = false;
spyOn(controller, 'emit');
controller.hide();
expect($ctrl.emit).not.toHaveBeenCalledWith('close');
expect(controller.emit).not.toHaveBeenCalledWith('close');
});
});
});

View File

@ -2,7 +2,7 @@ import './tooltip';
describe('Component vnTooltip', () => {
let $element;
let $ctrl;
let controller;
let $parent;
let element;
let window;
@ -12,9 +12,9 @@ describe('Component vnTooltip', () => {
beforeEach(inject(($compile, $rootScope, $document) => {
$element = $compile(`<vn-tooltip class="text">test</span></vn-tooltip>`)($rootScope);
$document.find('body').append($element);
$ctrl = $element.controller('vnTooltip');
controller = $element.controller('vnTooltip');
element = $element[0];
window = $ctrl.window;
window = controller.window;
$parent = angular.element('<div/>');
$parent.css({
@ -35,7 +35,7 @@ describe('Component vnTooltip', () => {
describe('show()', () => {
it(`should check that tooltip is visible into the screen`, () => {
$ctrl.show($parent[0]);
controller.show($parent[0]);
let rect = element.getBoundingClientRect();
let style = window.getComputedStyle(element);
@ -52,8 +52,8 @@ describe('Component vnTooltip', () => {
describe('hide()', () => {
it(`should check that tooltip is not visible`, () => {
$ctrl.show($parent[0]);
$ctrl.hide();
controller.show($parent[0]);
controller.hide();
let style = window.getComputedStyle(element);
expect(style.display).toEqual('none');
@ -62,22 +62,22 @@ describe('Component vnTooltip', () => {
describe('relocate()', () => {
it(`should reallocate tooltip on top-left`, () => {
$ctrl.show($parent[0]);
controller.show($parent[0]);
let rect = element.getBoundingClientRect();
expect($ctrl.margin).toBeLessThan(rect.top);
expect($ctrl.margin).toEqual(rect.left);
expect(controller.margin).toBeLessThan(rect.top);
expect(controller.margin).toEqual(rect.left);
});
it(`should reallocate tooltip on bottom-left`, () => {
$parent.css({
top: `${window.innerHeight}px`
});
$ctrl.show($parent[0]);
controller.show($parent[0]);
let rect = element.getBoundingClientRect();
expect(window.innerHeight).toBeGreaterThan(rect.top);
expect($ctrl.margin).toEqual(rect.left);
expect(controller.margin).toEqual(rect.left);
});
it(`should reallocate tooltip on bottom-right`, () => {
@ -85,22 +85,22 @@ describe('Component vnTooltip', () => {
top: `${window.innerHeight}px`,
left: `${window.innerWidth}px`
});
$ctrl.show($parent[0]);
controller.show($parent[0]);
let rect = element.getBoundingClientRect();
expect(window.innerWidth).toBeGreaterThan(rect.left);
expect(window.innerWidth - $ctrl.margin).toEqual(rect.right);
expect(window.innerWidth - controller.margin).toEqual(rect.right);
});
it(`should reallocate tooltip on top-right`, () => {
$parent.css({
left: `${window.innerWidth}px`
});
$ctrl.show($parent[0]);
controller.show($parent[0]);
let rect = element.getBoundingClientRect();
expect($ctrl.margin).toBeLessThan(rect.top);
expect(window.innerWidth - $ctrl.margin).toEqual(rect.right);
expect(controller.margin).toBeLessThan(rect.top);
expect(window.innerWidth - controller.margin).toEqual(rect.right);
});
it(`should reallocate tooltip on center`, () => {
@ -108,7 +108,7 @@ describe('Component vnTooltip', () => {
top: `${window.window.innerHeight / 2}px`,
left: `${window.window.innerWidth / 2}px`
});
$ctrl.show($parent[0]);
controller.show($parent[0]);
let rect = element.getBoundingClientRect();
expect(window.innerHeight / 2).toBeLessThan(rect.top);

View File

@ -2,7 +2,7 @@ import './index.js';
describe('Component vnTicketIndex', () => {
let $element;
let $ctrl;
let controller;
let $window;
let tickets = [{
id: 1,
@ -22,7 +22,7 @@ describe('Component vnTicketIndex', () => {
beforeEach(inject(($compile, $rootScope, $httpBackend, _$window_) => {
$window = _$window_;
$element = $compile('<vn-ticket-index></vn-ticket-index>')($rootScope);
$ctrl = $element.controller('vnTicketIndex');
controller = $element.controller('vnTicketIndex');
$httpBackend.whenGET(/\/ticket\/api\/Tickets\/filter.*/).respond(tickets);
$httpBackend.flush();
@ -35,7 +35,7 @@ describe('Component vnTicketIndex', () => {
describe('compareDate()', () => {
it('should return warning when the date is the present', () => {
let curDate = new Date();
let result = $ctrl.compareDate(curDate);
let result = controller.compareDate(curDate);
expect(result).toEqual('warning');
});
@ -43,7 +43,7 @@ describe('Component vnTicketIndex', () => {
it('should return sucess when the date is in the future', () => {
let futureDate = new Date();
futureDate = futureDate.setDate(futureDate.getDate() + 10);
let result = $ctrl.compareDate(futureDate);
let result = controller.compareDate(futureDate);
expect(result).toEqual('success');
});
@ -51,7 +51,7 @@ describe('Component vnTicketIndex', () => {
it('should return undefined when the date is in the past', () => {
let pastDate = new Date();
pastDate = pastDate.setDate(pastDate.getDate() - 10);
let result = $ctrl.compareDate(pastDate);
let result = controller.compareDate(pastDate);
expect(result).toEqual(undefined);
});
@ -59,31 +59,31 @@ describe('Component vnTicketIndex', () => {
describe('showDescriptor()', () => {
it('should show the descriptor popover', () => {
spyOn($ctrl.$.descriptor, 'show');
spyOn(controller.$.descriptor, 'show');
let event = new MouseEvent('click', {
view: $window,
bubbles: true,
cancelable: true
});
$ctrl.showDescriptor(event, tickets[0].clientFk);
controller.showDescriptor(event, tickets[0].clientFk);
expect($ctrl.$.descriptor.show).toHaveBeenCalledWith();
expect(controller.$.descriptor.show).toHaveBeenCalledWith();
});
});
describe('preview()', () => {
it('should show the dialog summary', () => {
spyOn($ctrl.$.summary, 'show');
spyOn(controller.$.summary, 'show');
let event = new MouseEvent('click', {
view: $window,
bubbles: true,
cancelable: true
});
$ctrl.preview(event, tickets[0]);
controller.preview(event, tickets[0]);
expect($ctrl.$.summary.show).toHaveBeenCalledWith();
expect(controller.$.summary.show).toHaveBeenCalledWith();
});
});
});

View File

@ -2,7 +2,7 @@ import './index.js';
describe('Ticket', () => {
describe('Component vnTicketSale', () => {
let $ctrl;
let controller;
let $element;
let $scope;
let $httpBackend;
@ -43,8 +43,8 @@ describe('Ticket', () => {
$httpBackend.whenGET(`/ticket/api/Tickets/1/getVAT`).respond(200, 10.5);
$element = $compile('<vn-ticket-sale ticket="ticket"></vn-ticket-sale>')($scope);
$ctrl = $element.controller('vnTicketSale');
$ctrl.card = {reload: () => {}};
controller = $element.controller('vnTicketSale');
controller.card = {reload: () => {}};
$httpBackend.flush();
}));
@ -56,124 +56,123 @@ describe('Ticket', () => {
describe('createClaim()', () => {
it('should perform a query and call windows open', () => {
spyOn(window, 'open');
spyOn(controller.$state, 'go');
let res = {id: 1};
$httpBackend.expectPOST(`claim/api/Claims/createFromSales`).respond(res);
$ctrl.createClaim();
controller.createClaim();
$httpBackend.flush();
let urlMock = null;
expect(window.open).toHaveBeenCalledWith(urlMock, '_blank');
expect(controller.$state.go).toHaveBeenCalledWith('claim.card.basicData', {id: 1});
});
});
describe('total/VAT/subTotal properties', () => {
it('should fill total, VAT and subTotal', () => {
expect($ctrl.subTotal).toEqual(227.5);
expect($ctrl.VAT).toEqual(10.5);
expect($ctrl.total).toEqual(238);
expect(controller.subTotal).toEqual(227.5);
expect(controller.VAT).toEqual(10.5);
expect(controller.total).toEqual(238);
});
});
describe('isChecked() getter', () => {
it('should set isChecked value to true when one of the instances has the value checked to true', () => {
$ctrl.sales[0].checked = true;
controller.sales[0].checked = true;
expect($ctrl.isChecked).toBeTruthy();
expect(controller.isChecked).toBeTruthy();
});
});
describe('getCheckedLines()', () => {
it('should make an array of the instances with the property checked true()', () => {
let sale = $ctrl.sales[1];
let sale = controller.sales[1];
sale.checked = true;
let expectedResult = [{id: sale.id, instance: 1}];
expect($ctrl.getCheckedLines()).toEqual(expectedResult);
expect(controller.getCheckedLines()).toEqual(expectedResult);
});
});
describe('onStateOkClick()', () => {
it('should perform a get and then call a function', () => {
let filter = {where: {code: "OK"}, fields: ["id"]};
let filter = {where: {code: 'OK'}, fields: ['id']};
filter = encodeURIComponent(JSON.stringify(filter));
let res = [{id: 3}];
spyOn($ctrl, 'onStateChange');
spyOn(controller, 'onStateChange');
$httpBackend.whenGET(`/ticket/api/States?filter=${filter}`).respond(res);
$ctrl.onStateOkClick();
controller.onStateOkClick();
$httpBackend.flush();
expect($ctrl.onStateChange).toHaveBeenCalledWith(3);
expect(controller.onStateChange).toHaveBeenCalledWith(3);
});
});
describe('showAddTurnDialog()', () => {
it('should call contrtoller.$scope.addTurn.show()', () => {
$ctrl.$scope.addTurn = {show: () => {}};
spyOn($ctrl.$scope.addTurn, 'show');
$ctrl.showAddTurnDialog();
controller.$scope.addTurn = {show: () => {}};
spyOn(controller.$scope.addTurn, 'show');
controller.showAddTurnDialog();
expect($ctrl.$scope.addTurn.show).toHaveBeenCalledWith();
expect(controller.$scope.addTurn.show).toHaveBeenCalledWith();
});
});
describe('addTurn(day)', () => {
it('should make a query and call $.addTurn.hide() and vnApp.showSuccess()', () => {
spyOn($ctrl.$scope.addTurn, 'hide');
spyOn(controller.$scope.addTurn, 'hide');
$httpBackend.expectPATCH(`/ticket/api/TicketWeeklies`).respond();
$ctrl.addTurn(1);
controller.addTurn(1);
$httpBackend.flush();
expect($ctrl.$scope.addTurn.hide).toHaveBeenCalledWith();
expect(controller.$scope.addTurn.hide).toHaveBeenCalledWith();
});
});
describe('onStateChange()', () => {
it('should perform a post and then call a function', () => {
$httpBackend.expectPOST(`/ticket/api/TicketTrackings/changeState`).respond();
$ctrl.onStateChange(3);
controller.onStateChange(3);
$httpBackend.flush();
});
});
describe('onRemoveLinesClick()', () => {
it('should call getCheckedLines, call removeInstances, and make a query', () => {
$ctrl.sales[1].checked = true;
controller.sales[1].checked = true;
$httpBackend.whenPOST(`/ticket/api/Sales/removes`).respond();
$ctrl.onRemoveLinesClick('ACCEPT');
controller.onRemoveLinesClick('ACCEPT');
$httpBackend.flush();
expect($ctrl.sales.length).toEqual(1);
expect(controller.sales.length).toEqual(1);
});
});
describe('unmarkAsReserved()', () => {
it('should call setReserved with false', () => {
spyOn($ctrl, 'setReserved');
spyOn(controller, 'setReserved');
$ctrl.unmarkAsReserved(false);
controller.unmarkAsReserved(false);
expect($ctrl.setReserved).toHaveBeenCalledWith(false);
expect(controller.setReserved).toHaveBeenCalledWith(false);
});
});
describe('markAsReserved()', () => {
it('should call setReserved with true', () => {
spyOn($ctrl, 'setReserved');
spyOn(controller, 'setReserved');
$ctrl.markAsReserved(true);
controller.markAsReserved(true);
expect($ctrl.setReserved).toHaveBeenCalledWith(true);
expect(controller.setReserved).toHaveBeenCalledWith(true);
});
});
describe('setReserved()', () => {
it('should call getCheckedLines, $.index.accept and make a query ', () => {
$ctrl.sales[1].checked = true;
controller.sales[1].checked = true;
let expectedRequest = {
sales: [{
id: sales[1].id,
@ -184,7 +183,7 @@ describe('Ticket', () => {
};
$httpBackend.expectPOST(`/ticket/api/Sales/reserve`, expectedRequest).respond();
$ctrl.unmarkAsReserved(false);
controller.unmarkAsReserved(false);
$httpBackend.flush();
});
});

View File

@ -55,7 +55,7 @@ describe('Client lock verified data path', () => {
it('should confirm verified data button is disabled for salesPerson', async () => {
const result = await nightmare
.wait(selectors.clientFiscalData.verifiedDataCheckboxInput)
.evaluate((selector) => {
.evaluate(selector => {
return document.querySelector(selector).disabled;
}, selectors.clientFiscalData.verifiedDataCheckbox);
@ -137,7 +137,7 @@ describe('Client lock verified data path', () => {
it('should confirm verified data button is enabled for administrative', async () => {
const result = await nightmare
.wait(selectors.clientFiscalData.verifiedDataCheckboxInput)
.evaluate((selector) => {
.evaluate(selector => {
return document.querySelector(selector).disabled;
}, selectors.clientFiscalData.verifiedDataCheckbox);
@ -159,7 +159,7 @@ describe('Client lock verified data path', () => {
.wait(selectors.clientBasicData.nameInput)
.waitToClick(selectors.clientFiscalData.fiscalDataButton)
.wait(selectors.clientFiscalData.verifiedDataCheckboxInput)
.evaluate((selector) => {
.evaluate(selector => {
return document.querySelector(selector).checked;
}, selectors.clientFiscalData.verifiedDataCheckboxInput);
@ -241,7 +241,7 @@ describe('Client lock verified data path', () => {
it('should confirm verified data button is disabled once again for salesPerson', async () => {
const result = await nightmare
.wait(selectors.clientFiscalData.verifiedDataCheckboxInput)
.evaluate((selector) => {
.evaluate(selector => {
return document.querySelector(selector).disabled;
}, selectors.clientFiscalData.verifiedDataCheckbox);
@ -312,7 +312,7 @@ describe('Client lock verified data path', () => {
it('should confirm verified data button is disabled for salesAssistant', async () => {
const result = await nightmare
.wait(selectors.clientFiscalData.verifiedDataCheckboxInput)
.evaluate((selector) => {
.evaluate(selector => {
return document.querySelector(selector).disabled;
}, selectors.clientFiscalData.verifiedDataCheckbox);
@ -394,7 +394,7 @@ describe('Client lock verified data path', () => {
it('should confirm verified data button is enabled once again', async () => {
const result = await nightmare
.wait(selectors.clientFiscalData.verifiedDataCheckboxInput)
.evaluate((selector) => {
.evaluate(selector => {
return document.querySelector(selector).disabled;
}, selectors.clientFiscalData.verifiedDataCheckbox);
@ -404,7 +404,7 @@ describe('Client lock verified data path', () => {
it('should confirm the form is enabled for salesPerson', async () => {
const result = await nightmare
.wait(selectors.clientFiscalData.socialNameInput)
.evaluate((selector) => {
.evaluate(selector => {
return document.querySelector(selector).disabled;
}, 'vn-textfield[field="$ctrl.client.socialName"] > div');