refactor test
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-05-10 12:02:50 +02:00
parent 5919c42df2
commit 946f1c1cb5
1 changed files with 25 additions and 18 deletions

View File

@ -5,11 +5,13 @@ describe('Component vnMultiCheck', () => {
let controller; let controller;
let $element; let $element;
let $httpBackend; let $httpBackend;
let $httpParamSerializer;
beforeEach(ngModule('vnCore')); beforeEach(ngModule('vnCore'));
beforeEach(inject(($componentController, _$httpBackend_) => { beforeEach(inject(($componentController, _$httpBackend_, _$httpParamSerializer_) => {
$httpBackend = _$httpBackend_; $httpBackend = _$httpBackend_;
$httpParamSerializer = _$httpParamSerializer_;
$element = angular.element(`<div class="shown"></div>`); $element = angular.element(`<div class="shown"></div>`);
controller = $componentController('vnMultiCheck', {$element: $element}); controller = $componentController('vnMultiCheck', {$element: $element});
controller._model = crudModel; controller._model = crudModel;
@ -145,39 +147,44 @@ describe('Component vnMultiCheck', () => {
describe('countRows()', () => { describe('countRows()', () => {
it(`should count visible rows and all rows of model`, () => { it(`should count visible rows and all rows of model`, () => {
const data = controller.model.data;
controller.model.url = 'modelUrl/filter'; controller.model.url = 'modelUrl/filter';
const response = { const data = controller.model.data;
data: [ const filter = {
{id: 1, name: 'My item 1'}, limit: null
{id: 2, name: 'My item 2'},
{id: 3, name: 'My item 3'},
{id: 4, name: 'My item 4'},
{id: 5, name: 'My item 5'},
{id: 6, name: 'My item 6'}
]
}; };
const serializedParams = $httpParamSerializer({filter});
const response = [
{id: 1, name: 'My item 1'},
{id: 2, name: 'My item 2'},
{id: 3, name: 'My item 3'},
{id: 4, name: 'My item 4'},
{id: 5, name: 'My item 5'},
{id: 6, name: 'My item 6'}
];
controller.countRows(); controller.countRows();
$httpBackend.expectGET(`modelUrl/filter?${serializedParams}`).respond(response);
$httpBackend.expectGET('modelUrl/filter').respond(response); $httpBackend.flush();
expect(controller.rows).toEqual(data.length); expect(controller.rows).toEqual(data.length);
expect(controller.AllRowsCount).toEqual(response.length); expect(controller.allRowsCount).toEqual(response.length);
expect(controller.allRowsCount).toBeGreaterThan(controller.rows);
}); });
}); });
describe('checkDummy()', () => { describe('checkDummy()', () => {
it(`should set checkedDummyCount allRowsCount`, () => { const allRows = 1234;
it(`should set the checked dummy count to all rows count if there was no count yet`, () => {
controller.checkedDummyCount = null; controller.checkedDummyCount = null;
controller.allRowsCount = 123; controller.allRowsCount = allRows;
controller.checkDummy(); controller.checkDummy();
expect(controller.checkedDummyCount).toEqual(controller.allRowsCount); expect(controller.checkedDummyCount).toEqual(controller.allRowsCount);
}); });
it(`should set checkedDummyCount to null`, () => { it(`should remove the dummy count if there was an existing one`, () => {
controller.checkedDummyCount = 123; controller.checkedDummyCount = allRows;
controller.checkDummy(); controller.checkDummy();
expect(controller.checkedDummyCount).toBeNull(); expect(controller.checkedDummyCount).toBeNull();