Skip to content

Commit 535a1af

Browse files
Rafaellyalinelariguet
authored andcommitted
fix(table): corrige a exibição do botão de visualizar legenda
criado um tratamento no ciclo DoCheck para quando o container está invisível dentro de tabs. Fixes DTHFUI-864
1 parent fbf370f commit 535a1af

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

projects/ui/src/lib/components/po-table/po-table-subtitle-footer/po-table-subtitle-footer.component.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,43 @@ describe('PoTableSubtitleFooterComponent:', () => {
6161
expect(component['removeResizeListener']).toHaveBeenCalled();
6262
});
6363

64+
describe('ngDoCheck', () => {
65+
66+
it(`should call 'toggleShowCompleteSubtitle' and set 'isVisible' to 'true' if 'getContainerSize' returns a value greater than 0
67+
and 'isVisible' is 'false'`, () => {
68+
component['isVisible'] = false;
69+
70+
spyOn(component, <any>'getContainerSize').and.returnValue(100);
71+
spyOn(component, <any>'toggleShowCompleteSubtitle');
72+
73+
component.ngDoCheck();
74+
75+
expect(component['toggleShowCompleteSubtitle']).toHaveBeenCalled();
76+
expect(component['isVisible']).toBe(true);
77+
});
78+
79+
it('shouldn`t call `toggleShowCompleteSubtitle` if `isVisible` is `true`', () => {
80+
component['isVisible'] = true;
81+
82+
spyOn(component, <any>'toggleShowCompleteSubtitle');
83+
84+
component.ngDoCheck();
85+
86+
expect(component['toggleShowCompleteSubtitle']).not.toHaveBeenCalled();
87+
});
88+
89+
it('shouldn`t call `toggleShowCompleteSubtitle` if `getContainerSize` returns 0', () => {
90+
component['isVisible'] = false;
91+
92+
spyOn(component, <any>'getContainerSize').and.returnValue(0);
93+
spyOn(component, <any>'toggleShowCompleteSubtitle');
94+
95+
component.ngDoCheck();
96+
97+
expect(component['toggleShowCompleteSubtitle']).not.toHaveBeenCalled();
98+
});
99+
});
100+
64101
// Teste com problemas intermitentes
65102
// Uncaught Error: macroTask 'setTimeout': can not transition to 'running', expecting state 'scheduled', was 'notScheduled'.
66103
// O problema pode estar associada a forma que o componente e está estruturado e o uso do setTimeout.

projects/ui/src/lib/components/po-table/po-table-subtitle-footer/po-table-subtitle-footer.component.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AfterViewInit, Component, ElementRef, Input, OnDestroy, Renderer2 } from '@angular/core';
1+
import { AfterViewInit, Component, DoCheck, ElementRef, Input, OnDestroy, Renderer2 } from '@angular/core';
22

33
import { PoTableSubtitleColumn } from './po-table-subtitle-column.interface';
44

@@ -13,10 +13,11 @@ import { PoTableSubtitleColumn } from './po-table-subtitle-column.interface';
1313
selector: 'po-table-subtitle-footer',
1414
templateUrl: './po-table-subtitle-footer.component.html'
1515
})
16-
export class PoTableSubtitleFooterComponent implements AfterViewInit, OnDestroy {
16+
export class PoTableSubtitleFooterComponent implements AfterViewInit, DoCheck, OnDestroy {
1717

1818
showSubtitle: boolean;
1919

20+
private isVisible: boolean;
2021
private timeoutResize;
2122
protected resizeListener: () => void;
2223

@@ -33,6 +34,15 @@ export class PoTableSubtitleFooterComponent implements AfterViewInit, OnDestroy
3334
this.debounceResize();
3435
}
3536

37+
ngDoCheck() {
38+
39+
if (!this.isVisible && this.getContainerSize() > 0) {
40+
this.toggleShowCompleteSubtitle();
41+
this.isVisible = true;
42+
}
43+
44+
}
45+
3646
ngOnDestroy() {
3747
this.removeResizeListener();
3848
}

projects/ui/src/lib/components/po-table/samples/sample-po-table-airfare/sample-po-table-airfare.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { SamplePoTableAirfareService } from './sample-po-table-airfare.service';
1414
@Component({
1515
selector: 'sample-po-table-airfare',
1616
templateUrl: './sample-po-table-airfare.component.html',
17-
providers: [ SamplePoTableAirfareService ]
17+
providers: [ SamplePoTableAirfareService, PoDialogService ]
1818
})
1919
export class SamplePoTableAirfareComponent {
2020

0 commit comments

Comments
 (0)