support front filter and front test for component
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
433afb8fe8
commit
ea2e38af4e
|
@ -18,7 +18,7 @@
|
||||||
</span>
|
</span>
|
||||||
<span translate>row(s) have been selected.</span>
|
<span translate>row(s) have been selected.</span>
|
||||||
<span class="bold link" ng-click="$ctrl.checkDummy()">
|
<span class="bold link" ng-click="$ctrl.checkDummy()">
|
||||||
{{$ctrl.AllRowsText}}
|
{{$ctrl.allRowsText}}
|
||||||
</span>
|
</span>
|
||||||
</vn-list>
|
</vn-list>
|
||||||
</vn-menu>
|
</vn-menu>
|
|
@ -143,10 +143,12 @@ export default class MultiCheck extends FormInput {
|
||||||
|
|
||||||
countRows() {
|
countRows() {
|
||||||
if (!this.model || !this.model.data) return;
|
if (!this.model || !this.model.data) return;
|
||||||
|
|
||||||
const data = this.model.data;
|
const data = this.model.data;
|
||||||
|
const modelParams = this.model.userParams;
|
||||||
const params = {
|
const params = {
|
||||||
filter: {
|
filter: {
|
||||||
where: this.model.userParams,
|
modelParams: modelParams,
|
||||||
limit: null
|
limit: null
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -155,9 +157,9 @@ export default class MultiCheck extends FormInput {
|
||||||
|
|
||||||
this.$http.get(this.model.url, {params})
|
this.$http.get(this.model.url, {params})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
this.AllRowsCount = res.data.length;
|
this.allRowsCount = res.data.length;
|
||||||
this.AllRowsText = this.$t('SelectAllRows', {
|
this.allRowsText = this.$t('SelectAllRows', {
|
||||||
rows: this.AllRowsCount
|
rows: this.allRowsCount
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -166,7 +168,7 @@ export default class MultiCheck extends FormInput {
|
||||||
if (this.checkedDummyCount)
|
if (this.checkedDummyCount)
|
||||||
return this.checkedDummyCount = null;
|
return this.checkedDummyCount = null;
|
||||||
|
|
||||||
this.checkedDummyCount = this.AllRowsCount;
|
this.checkedDummyCount = this.allRowsCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,10 +4,12 @@ import crudModel from 'core/mocks/crud-model';
|
||||||
describe('Component vnMultiCheck', () => {
|
describe('Component vnMultiCheck', () => {
|
||||||
let controller;
|
let controller;
|
||||||
let $element;
|
let $element;
|
||||||
|
let $httpBackend;
|
||||||
|
|
||||||
beforeEach(ngModule('vnCore'));
|
beforeEach(ngModule('vnCore'));
|
||||||
|
|
||||||
beforeEach(inject($componentController => {
|
beforeEach(inject(($componentController, _$httpBackend_) => {
|
||||||
|
$httpBackend = _$httpBackend_;
|
||||||
$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;
|
||||||
|
@ -26,6 +28,14 @@ describe('Component vnMultiCheck', () => {
|
||||||
expect(controller._checked).toEqual(crudModel);
|
expect(controller._checked).toEqual(crudModel);
|
||||||
expect(controller.toggle).toHaveBeenCalledWith();
|
expect(controller.toggle).toHaveBeenCalledWith();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it(`should set checkedDummyCount to null`, () => {
|
||||||
|
jest.spyOn(controller, 'toggle');
|
||||||
|
controller.checkedDummyCount = 12;
|
||||||
|
controller.checked = null;
|
||||||
|
|
||||||
|
expect(controller.checkedDummyCount).toBeNull();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('toggle()', () => {
|
describe('toggle()', () => {
|
||||||
|
@ -132,4 +142,45 @@ describe('Component vnMultiCheck', () => {
|
||||||
expect(thirdRow.checked).toBeTruthy();
|
expect(thirdRow.checked).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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'}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
controller.countRows();
|
||||||
|
|
||||||
|
$httpBackend.expectGET('modelUrl/filter').respond(response);
|
||||||
|
|
||||||
|
expect(controller.rows).toEqual(data.length);
|
||||||
|
expect(controller.AllRowsCount).toEqual(response.length);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('checkDummy()', () => {
|
||||||
|
it(`should set checkedDummyCount allRowsCount`, () => {
|
||||||
|
controller.checkedDummyCount = null;
|
||||||
|
controller.allRowsCount = 123;
|
||||||
|
controller.checkDummy();
|
||||||
|
|
||||||
|
expect(controller.checkedDummyCount).toEqual(controller.allRowsCount);
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should set checkedDummyCount to null`, () => {
|
||||||
|
controller.checkedDummyCount = 123;
|
||||||
|
controller.checkDummy();
|
||||||
|
|
||||||
|
expect(controller.checkedDummyCount).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -98,6 +98,9 @@ module.exports = Self => {
|
||||||
Self.latestBuysFilter = async(ctx, filter, options) => {
|
Self.latestBuysFilter = async(ctx, filter, options) => {
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (filter && filter.modelParams)
|
||||||
|
ctx.args = filter.modelParams;
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue