Skip to content

Commit ee62bde

Browse files
Rogerio-Fialhoalinelariguet
authored andcommitted
fix(lookup): Corrige ordenação das tabelas
Corrige o problema de ordenação no table quando utilizado caracteres maiúsculos e minúsculos nos labels das colunas. Fixes DTHFUI-854
1 parent 89b6e44 commit ee62bde

File tree

2 files changed

+88
-4
lines changed

2 files changed

+88
-4
lines changed

projects/ui/src/lib/utils/util.spec.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,15 @@ describe('Function sortValues:', () => {
545545
expect(sortValues(leftSide, rightSide, ascending)).toBe(expectedReturn);
546546
});
547547

548+
it('should return `-1` if `leftSide` is less than `rightSide`, `ascending` is `undefined` and use lower and upper characters', () => {
549+
const ascending: boolean = undefined;
550+
const expectedReturn: number = -1;
551+
const leftSide: string = 'Aaa';
552+
const rightSide: string = 'abc';
553+
554+
expect(sortValues(leftSide, rightSide, ascending)).toBe(expectedReturn);
555+
});
556+
548557
it('should return `-1` if `leftSide` is less than `rightSide` and `ascending` is `true`', () => {
549558
const ascending: boolean = true;
550559
const expectedReturn: number = -1;
@@ -554,6 +563,15 @@ describe('Function sortValues:', () => {
554563
expect(sortValues(leftSide, rightSide, ascending)).toBe(expectedReturn);
555564
});
556565

566+
it('should return `-1` if `leftSide` is less than `rightSide`, `ascending` is `true` and use lower and upper characters', () => {
567+
const ascending: boolean = true;
568+
const expectedReturn: number = -1;
569+
const leftSide: string = 'Aaa';
570+
const rightSide: string = 'abc';
571+
572+
expect(sortValues(leftSide, rightSide, ascending)).toBe(expectedReturn);
573+
});
574+
557575
it('should return `1` if `leftSide` is less than `rightSide` and `ascending` is `false`', () => {
558576
const ascending: boolean = false;
559577
const expectedReturn: number = 1;
@@ -563,6 +581,15 @@ describe('Function sortValues:', () => {
563581
expect(sortValues(leftSide, rightSide, ascending)).toBe(expectedReturn);
564582
});
565583

584+
it('should return `1` if `leftSide` is less than `rightSide`, `ascending` is `false` and use lower and upper characters', () => {
585+
const ascending: boolean = false;
586+
const expectedReturn: number = 1;
587+
const leftSide: string = 'Aaa';
588+
const rightSide: string = 'abc';
589+
590+
expect(sortValues(leftSide, rightSide, ascending)).toBe(expectedReturn);
591+
});
592+
566593
it('should return `1` if `leftSide` is greater than `rightSide` and `ascending` is `undefined`', () => {
567594
const ascending: boolean = undefined;
568595
const expectedReturn: number = 1;
@@ -572,6 +599,15 @@ describe('Function sortValues:', () => {
572599
expect(sortValues(leftSide, rightSide, ascending)).toBe(expectedReturn);
573600
});
574601

602+
it('should return `1` if `leftSide` is greater than `rightSide`, `ascending` is `undefined` and use lower and upper characters', () => {
603+
const ascending: boolean = undefined;
604+
const expectedReturn: number = 1;
605+
const leftSide: string = 'abc';
606+
const rightSide: string = 'Aaa';
607+
608+
expect(sortValues(leftSide, rightSide, ascending)).toBe(expectedReturn);
609+
});
610+
575611
it('should return `1` if `leftSide` is greater than `rightSide` and `ascending` is `true`', () => {
576612
const ascending: boolean = true;
577613
const expectedReturn: number = 1;
@@ -581,6 +617,15 @@ describe('Function sortValues:', () => {
581617
expect(sortValues(leftSide, rightSide, ascending)).toBe(expectedReturn);
582618
});
583619

620+
it('should return `1` if `leftSide` is greater than `rightSide`, `ascending` is `true` and use lower and upper characters', () => {
621+
const ascending: boolean = true;
622+
const expectedReturn: number = 1;
623+
const leftSide: string = 'abc';
624+
const rightSide: string = 'Aaa';
625+
626+
expect(sortValues(leftSide, rightSide, ascending)).toBe(expectedReturn);
627+
});
628+
584629
it('should return `-1` if `leftSide` is greater than `rightSide` and `ascending` is `false`', () => {
585630
const ascending: boolean = false;
586631
const expectedReturn: number = -1;
@@ -590,6 +635,15 @@ describe('Function sortValues:', () => {
590635
expect(sortValues(leftSide, rightSide, ascending)).toBe(expectedReturn);
591636
});
592637

638+
it('should return `-1` if `leftSide` is greater than `rightSide`, `ascending` is `false` and use lower and upper characters', () => {
639+
const ascending: boolean = false;
640+
const expectedReturn: number = -1;
641+
const leftSide: string = 'abc';
642+
const rightSide: string = 'AAA';
643+
644+
expect(sortValues(leftSide, rightSide, ascending)).toBe(expectedReturn);
645+
});
646+
593647
it('should return `0` if `leftSide` is equal to `rightSide` and `ascending` is `undefined`', () => {
594648
const ascending: boolean = undefined;
595649
const expectedReturn: number = 0;
@@ -599,6 +653,15 @@ describe('Function sortValues:', () => {
599653
expect(sortValues(leftSide, rightSide , ascending)).toBe(expectedReturn);
600654
});
601655

656+
it('should return `0` if `leftSide` is equal to `rightSide`, `ascending` is `undefined` and use lower and upper characters', () => {
657+
const ascending: boolean = undefined;
658+
const expectedReturn: number = 0;
659+
const leftSide: string = 'ABC';
660+
const rightSide: string = 'abc';
661+
662+
expect(sortValues(leftSide, rightSide , ascending)).toBe(expectedReturn);
663+
});
664+
602665
it('should return `0` if `leftSide` is equal to `rightSide` and `ascending` is `true`', () => {
603666
const ascending: boolean = true;
604667
const expectedReturn: number = 0;
@@ -608,6 +671,15 @@ describe('Function sortValues:', () => {
608671
expect(sortValues(leftSide, rightSide , ascending)).toBe(expectedReturn);
609672
});
610673

674+
it('should return `0` if `leftSide` is equal to `rightSide`, `ascending` is `true` and use lower and upper characters', () => {
675+
const ascending: boolean = true;
676+
const expectedReturn: number = 0;
677+
const leftSide: string = 'ABC';
678+
const rightSide: string = 'abc';
679+
680+
expect(sortValues(leftSide, rightSide , ascending)).toBe(expectedReturn);
681+
});
682+
611683
it('should return `0` if `leftSide` is equal to `rightSide` and `ascending` is `false`', () => {
612684
const ascending: boolean = false;
613685
const expectedReturn: number = 0;
@@ -617,6 +689,15 @@ describe('Function sortValues:', () => {
617689
expect(sortValues(leftSide, rightSide, ascending)).toBe(expectedReturn);
618690
});
619691

692+
it('should return `0` if `leftSide` is equal to `rightSide`, `ascending` is `false` and use lower and upper characters', () => {
693+
const ascending: boolean = false;
694+
const expectedReturn: number = 0;
695+
const leftSide: string = 'ABC';
696+
const rightSide: string = 'abc';
697+
698+
expect(sortValues(leftSide, rightSide , ascending)).toBe(expectedReturn);
699+
});
700+
620701
it('should return `-1` if `leftSide` is numeric value, `rightSide` is a character value and `ascending` is `true`', () => {
621702
const ascending: boolean = true;
622703
const expectedReturn: number = -1;

projects/ui/src/lib/utils/util.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,16 +283,19 @@ export function getFormattedLink(link: string): string {
283283
* @param ascending Determina se será em ordem ascendente ou descendente.
284284
*/
285285
export function sortValues(leftSide: string, rightSide: string, ascending: boolean = true): number {
286+
const left = isTypeof(leftSide, 'string') ? leftSide.toLowerCase() : leftSide;
287+
const right = isTypeof(rightSide, 'string') ? rightSide.toLowerCase() : rightSide;
288+
286289
if (ascending) {
287-
if (leftSide < rightSide) {
290+
if (left < right) {
288291
return -1;
289-
} else if (leftSide > rightSide) {
292+
} else if (left > right) {
290293
return 1;
291294
}
292295
} else if (ascending === false) {
293-
if (leftSide < rightSide) {
296+
if (left < right) {
294297
return 1;
295-
} else if (leftSide > rightSide) {
298+
} else if (left > right) {
296299
return -1;
297300
}
298301
}

0 commit comments

Comments
 (0)