Skip to content

Commit

Permalink
fix(abc:st): fix sorting trigger misalignment in mulit-column (#1767)
Browse files Browse the repository at this point in the history
  • Loading branch information
devcui committed Mar 21, 2024
1 parent 1dad60a commit a09ccb0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
2 changes: 1 addition & 1 deletion packages/abc/st/st.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
(nzResizeEnd)="colResize($event, _c)"
>
@if ($any(!last && !$any(_c).resizable.disabled)) {
<nz-resize-handle nzDirection="right" (click)="_stopPropagation($event)">
<nz-resize-handle nzDirection="right">
<i></i>
</nz-resize-handle>
}
Expand Down
1 change: 0 additions & 1 deletion packages/abc/st/st.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ export class STComponent implements AfterViewInit, OnChanges {
this._data = result.list ?? [];
this._statistical = result.statistical as STStatisticalResults;
// Should be re-render in next tike when using virtual scroll
// https://github.com/ng-alain/ng-alain/issues/1836
if (this.cdkVirtualScrollViewport != null) {
Promise.resolve().then(() => this.cdkVirtualScrollViewport?.checkViewportSize());
}
Expand Down
43 changes: 28 additions & 15 deletions packages/abc/st/test/st-data-source.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ describe('abc: table: data-souce', () => {
res: deepCopy(ST_DEFAULT_CONFIG.res),
page: deepCopy(ST_DEFAULT_CONFIG.page),
columns: [{ title: '', index: 'id' }] as _STColumn[],
headers: [[{ colSpan: 1, rowSpan: 1, hasSubColumns: false, column: { title: '', index: 'id' } as _STColumn }]],
paginator: true
};
TestBed.configureTestingModule({
Expand Down Expand Up @@ -167,29 +168,29 @@ describe('abc: table: data-souce', () => {
describe('[sort]', () => {
beforeEach(() => {
options.data = genData(DEFAULT.total, true);
options.columns[0]._sort = {
options.headers[0][0].column._sort = {
enabled: true,
compare: (a: any, b: any) => a.id - b.id
};
});
it(`should be decremented`, done => {
(options.data as STData[])[1].id = 100000;
options.columns[0]._sort.default = 'descend';
options.headers[0][0].column._sort.default = 'descend';
srv.process(options).subscribe(res => {
expect(res.list[0].id).toBe(100000);
done();
});
});
it(`should be incremented`, done => {
(options.data as STData[])[1].id = -100000;
options.columns[0]._sort.default = 'ascend';
options.headers[0][0].column._sort.default = 'ascend';
srv.process(options).subscribe(res => {
expect(res.list[0].id).toBe(-100000);
done();
});
});
it('should be null, muse be ignore sort processing', done => {
options.columns[0]._sort = {
it('should be null, muse be ingore sort processing', done => {
options.headers[0][0].column._sort = {
enabled: true,
compare: null,
default: 'descend'
Expand Down Expand Up @@ -464,7 +465,7 @@ describe('abc: table: data-souce', () => {
beforeEach(() => {
genModule();
options.data = '/mockurl';
options.columns[0]._sort = {
options.headers[0][0].column._sort = {
enabled: true,
key: 'id'
};
Expand All @@ -474,30 +475,30 @@ describe('abc: table: data-souce', () => {
});
});
it(`should be decremented`, done => {
options.columns[0]._sort.default = 'descend';
options.headers[0][0].column._sort.default = 'descend';
srv.process(options).subscribe(() => {
expect(resParams.get('id')!).toBe('descend');
done();
});
});
it(`should be incremented`, done => {
options.columns[0]._sort.default = 'ascend';
options.headers[0][0].column._sort.default = 'ascend';
srv.process(options).subscribe(() => {
expect(resParams.get('id')!).toBe('ascend');
done();
});
});
it(`should be re-name`, done => {
options.columns[0]._sort.default = 'ascend';
options.columns[0]._sort.reName = { ascend: 'A', descend: 'D' };
options.headers[0][0].column._sort.default = 'ascend';
options.headers[0][0].column._sort.reName = { ascend: 'A', descend: 'D' };
srv.process(options).subscribe(() => {
expect(resParams.get('id')!).toBe('A');
done();
});
});
it(`should be used default key when invalid re-name paraments`, done => {
options.columns[0]._sort.default = 'ascend';
options.columns[0]._sort.reName = {};
options.headers[0][0].column._sort.default = 'ascend';
options.headers[0][0].column._sort.reName = {};
srv.process(options).subscribe(() => {
expect(resParams.get('id')!).toBe('ascend');
done();
Expand All @@ -522,6 +523,12 @@ describe('abc: table: data-souce', () => {
_sort: { enabled: true, default: 'ascend', key: 'id2' }
}
];
options.headers = [
[
{ colSpan: 1, rowSpan: 1, hasSubColumns: false, column: options.columns[0] },
{ colSpan: 1, rowSpan: 1, hasSubColumns: false, column: options.columns[1] }
]
];
});
it(`should be`, done => {
srv.process(options).subscribe(() => {
Expand Down Expand Up @@ -553,6 +560,12 @@ describe('abc: table: data-souce', () => {
sort: true
}
] as _STColumn[];
options.headers = [
[
{ colSpan: 1, rowSpan: 1, hasSubColumns: false, column: options.columns[0] },
{ colSpan: 1, rowSpan: 1, hasSubColumns: false, column: options.columns[1] }
]
];
srv.process(options).subscribe(() => {
expect(resParams.has('SORT')).toBe(false);
done();
Expand Down Expand Up @@ -586,15 +599,15 @@ describe('abc: table: data-souce', () => {
});
describe('[singleSort]', () => {
it(`should working`, done => {
options.columns[0]._sort.default = 'ascend';
options.headers[0][0].column._sort.default = 'ascend';
options.singleSort = {};
srv.process(options).subscribe(() => {
expect(resParams.get('sort')).toBe('id.ascend');
done();
});
});
it(`should specify options`, done => {
options.columns[0]._sort.default = 'ascend';
options.headers[0][0].column._sort.default = 'ascend';
options.singleSort = { key: 'SORT', nameSeparator: '-' };
srv.process(options).subscribe(() => {
expect(resParams.get('SORT')).toBe('id-ascend');
Expand Down Expand Up @@ -1102,7 +1115,7 @@ describe('abc: table: data-souce', () => {
done();
});
});
it('should be ignore currency', done => {
it('should be ingore currency', done => {
options.columns = [{ title: '', index: 'a', statistical: { type: 'sum', currency: false } }] as _STColumn[];
options.data = [{ a: 1 }, { a: 2 }, { a: 0.1 }];

Expand Down
10 changes: 5 additions & 5 deletions packages/abc/st/test/st-sort.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ describe('abc: st-sort', () => {
it('muse provide the compare function', fakeAsync(() => {
spyOn(console, 'warn');
page.updateColumn([{ title: '', index: 'i', sort: { compare: 'a' } as NzSafeAny }]);
comp.sort(comp._columns[0], 0, 'descend');
comp.sort(comp._columns[0], 'descend');
page.cd();
expect(console.warn).toHaveBeenCalled();
page.asyncEnd();
}));
it('should be auto generate compose when sort is true', fakeAsync(() => {
context.data = [{ i: 1 }, { i: 2 }];
page.updateColumn([{ title: '', index: 'i', sort: true }]);
comp.sort(comp._columns[0], 0, 'descend');
comp.sort(comp._columns[0], 'descend');
page.cd();
expect(context.comp.list[0].i).toBe(2);
page.asyncEnd();
}));
it('should be sorting', fakeAsync(() => {
page.cd();
comp.sort(comp._columns[0], 0, 'descend');
comp.sort(comp._columns[0], 'descend');
const sortList = comp._columns
.filter(item => item._sort && item._sort.enabled && item._sort.default)
.map(item => item._sort!);
Expand All @@ -67,8 +67,8 @@ describe('abc: st-sort', () => {
beforeEach(() => (context.multiSort = true));
it('should be sorting', fakeAsync(() => {
page.cd();
comp.sort(comp._columns[0], 0, 'descend');
comp.sort(comp._columns[1], 0, 'ascend');
comp.sort(comp._columns[0], 'descend');
comp.sort(comp._columns[1], 'ascend');
const sortList = comp._columns
.filter(item => item._sort && item._sort.enabled && item._sort.default)
.map(item => item._sort!);
Expand Down

0 comments on commit a09ccb0

Please sign in to comment.