refactor test
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
5919c42df2
commit
946f1c1cb5
|
@ -5,11 +5,13 @@ describe('Component vnMultiCheck', () => {
|
|||
let controller;
|
||||
let $element;
|
||||
let $httpBackend;
|
||||
let $httpParamSerializer;
|
||||
|
||||
beforeEach(ngModule('vnCore'));
|
||||
|
||||
beforeEach(inject(($componentController, _$httpBackend_) => {
|
||||
beforeEach(inject(($componentController, _$httpBackend_, _$httpParamSerializer_) => {
|
||||
$httpBackend = _$httpBackend_;
|
||||
$httpParamSerializer = _$httpParamSerializer_;
|
||||
$element = angular.element(`<div class="shown"></div>`);
|
||||
controller = $componentController('vnMultiCheck', {$element: $element});
|
||||
controller._model = crudModel;
|
||||
|
@ -145,39 +147,44 @@ describe('Component vnMultiCheck', () => {
|
|||
|
||||
describe('countRows()', () => {
|
||||
it(`should count visible rows and all rows of model`, () => {
|
||||
const data = controller.model.data;
|
||||
controller.model.url = 'modelUrl/filter';
|
||||
const response = {
|
||||
data: [
|
||||
{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'}
|
||||
]
|
||||
const data = controller.model.data;
|
||||
const filter = {
|
||||
limit: null
|
||||
};
|
||||
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();
|
||||
|
||||
$httpBackend.expectGET('modelUrl/filter').respond(response);
|
||||
$httpBackend.expectGET(`modelUrl/filter?${serializedParams}`).respond(response);
|
||||
$httpBackend.flush();
|
||||
|
||||
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()', () => {
|
||||
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.allRowsCount = 123;
|
||||
controller.allRowsCount = allRows;
|
||||
controller.checkDummy();
|
||||
|
||||
expect(controller.checkedDummyCount).toEqual(controller.allRowsCount);
|
||||
});
|
||||
|
||||
it(`should set checkedDummyCount to null`, () => {
|
||||
controller.checkedDummyCount = 123;
|
||||
it(`should remove the dummy count if there was an existing one`, () => {
|
||||
controller.checkedDummyCount = allRows;
|
||||
controller.checkDummy();
|
||||
|
||||
expect(controller.checkedDummyCount).toBeNull();
|
||||
|
|
Loading…
Reference in New Issue