Skip to content

Commit ea3ba0a

Browse files
Samir Hassan AyoubSamir Hassan Ayoub
authored andcommitted
fix(loading): trata o ícone de carregamento para conexões 3g
Em conexões 3g foi detectada uma lentidão no carregamento do ícone de carregamento de conteúdo. O problema foi solucionado com a construção da animação com recursos HTML e CSS. A solução também torna possível a customização de cor para o ícone. Fixes DTHFUI-796
1 parent 7b06ece commit ea3ba0a

22 files changed

+173
-41
lines changed

projects/ui/src/lib/components/po-button-group/po-button-group.component.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { ComponentFixture, fakeAsync, flush, TestBed } from '@angular/core/testi
22

33
import { configureTestSuite } from './../../util-test/util-expect.spec';
44

5-
import { PoButtonComponent } from './../po-button/po-button.component';
5+
import { PoButtonModule } from '../po-button/po-button.module';
6+
67
import { PoButtonGroupBaseComponent } from './po-button-group-base.component';
78
import { PoButtonGroupComponent } from './po-button-group.component';
89
import { PoButtonGroupItem } from './po-button-group-item.interface';
@@ -32,9 +33,8 @@ describe('PoButtonGroupComponent:', () => {
3233

3334
configureTestSuite(() => {
3435
TestBed.configureTestingModule({
35-
imports: [PoTooltipModule],
36+
imports: [ PoButtonModule, PoTooltipModule ],
3637
declarations: [
37-
PoButtonComponent,
3838
PoButtonGroupComponent
3939
]
4040
});

projects/ui/src/lib/components/po-button/po-button.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
[disabled]="disabled || loading"
1010
(click)="onClick()">
1111

12-
<span *ngIf="loading" class="po-icon po-button-loading-icon"></span>
12+
<div *ngIf="loading" class="po-button-loading-icon">
13+
<po-loading-icon p-neutral-color></po-loading-icon>
14+
</div>
1315
<span *ngIf="icon" class="po-icon {{ icon }}" aria-hidden="true"></span>
1416
<span *ngIf="label" class="po-button-label">{{ label }}</span>
1517
</button>

projects/ui/src/lib/components/po-button/po-button.component.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
22

33
import { configureTestSuite } from './../../util-test/util-expect.spec';
44

5+
import { PoLoadingModule } from '../po-loading';
6+
57
import { PoButtonComponent } from './po-button.component';
68
import { PoButtonBaseComponent } from './po-button-base.component';
79

@@ -15,6 +17,7 @@ describe('PoButtonComponent: ', () => {
1517

1618
configureTestSuite(() => {
1719
TestBed.configureTestingModule({
20+
imports: [PoLoadingModule],
1821
declarations: [ PoButtonComponent ]
1922
});
2023
});
@@ -140,7 +143,7 @@ describe('PoButtonComponent: ', () => {
140143

141144
it('should disabled button when propertie is setted.', () => {
142145
expect(button.getAttribute('disabled')).not.toBeNull();
143-
expect(button.getElementsByClassName('po-icon po-button-loading-icon').length).toBeTruthy();
146+
expect(button.getElementsByClassName('po-button-loading-icon').length).toBeTruthy();
144147
});
145148

146149
it('should keep button disabled independently of type.', () => {
@@ -150,7 +153,7 @@ describe('PoButtonComponent: ', () => {
150153
component.type = type;
151154
fixture.detectChanges();
152155
expect(button.getAttribute('disabled')).not.toBeNull();
153-
expect(button.getElementsByClassName('po-icon po-button-loading-icon').length).toBeTruthy();
156+
expect(button.getElementsByClassName('po-button-loading-icon').length).toBeTruthy();
154157
}
155158
});
156159

projects/ui/src/lib/components/po-button/po-button.module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { NgModule } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33

4+
import { PoLoadingModule } from './../po-loading/index';
5+
46
import { PoButtonComponent } from './po-button.component';
57

68
/**
@@ -10,7 +12,8 @@ import { PoButtonComponent } from './po-button.component';
1012
*/
1113
@NgModule({
1214
imports: [
13-
CommonModule
15+
CommonModule,
16+
PoLoadingModule
1417
],
1518
declarations: [
1619
PoButtonComponent

projects/ui/src/lib/components/po-field/po-combo/po-combo.component.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import { changeBrowserInnerWidth, configureTestSuite } from './../../../util-tes
88

99
import * as UtilsFunctions from '../../../utils/util';
1010
import { removeDuplicatedOptions } from '../../../utils/util';
11+
12+
import { PoLoadingModule } from '../../po-loading/po-loading.module';
13+
1114
import { PoFieldContainerBottomComponent } from './../po-field-container/po-field-container-bottom/po-field-container-bottom.component';
1215
import { PoFieldContainerComponent } from '../po-field-container/po-field-container.component';
13-
import { PoLoadingComponent } from '../../po-loading/po-loading.component';
1416

1517
import { PoComboComponent } from './po-combo.component';
1618
import { PoComboFilterMode } from './po-combo-filter-mode.enum';
@@ -31,10 +33,10 @@ describe('PoComboComponent:', () => {
3133

3234
configureTestSuite(() => {
3335
TestBed.configureTestingModule({
36+
imports: [ PoLoadingModule ],
3437
declarations: [
3538
PoComboComponent,
3639
PoFieldContainerComponent,
37-
PoLoadingComponent,
3840
PoFieldContainerBottomComponent
3941
],
4042
providers: [ HttpClient, HttpHandler]
@@ -1425,11 +1427,11 @@ describe('PoComboComponent - with service:', () => {
14251427
configureTestSuite(() => {
14261428
TestBed.configureTestingModule({
14271429
imports: [
1428-
HttpClientTestingModule
1430+
HttpClientTestingModule,
1431+
PoLoadingModule
14291432
],
14301433
declarations: [ PoComboComponent,
14311434
PoFieldContainerComponent,
1432-
PoLoadingComponent,
14331435
PoFieldContainerBottomComponent
14341436
],
14351437
providers: [ HttpClient, HttpHandler, PoComboFilterService]

projects/ui/src/lib/components/po-field/po-upload/po-upload.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { HttpClient, HttpHandler } from '@angular/common/http';
55

66
import { configureTestSuite } from './../../../util-test/util-expect.spec';
77

8-
import { PoButtonComponent } from '../../po-button/po-button.component';
8+
import { PoButtonModule } from '../../po-button';
99

1010
import { PoFieldContainerBottomComponent } from './../po-field-container/po-field-container-bottom/po-field-container-bottom.component';
1111
import { PoFieldContainerComponent } from '../po-field-container/po-field-container.component';
@@ -30,10 +30,10 @@ describe('PoUploadComponent:', () => {
3030

3131
configureTestSuite(() => {
3232
TestBed.configureTestingModule({
33+
imports: [ PoButtonModule ],
3334
declarations: [
3435
PoUploadComponent,
3536
PoFieldContainerComponent,
36-
PoButtonComponent,
3737
PoFieldContainerBottomComponent
3838
],
3939
providers: [ HttpClient, HttpHandler]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<div class="po-loading-icon" [class.po-loading-icon-neutral-color]="neutralColor">
2+
<span class="po-loading-icon-bar po-loading-icon-bar-1"></span>
3+
<span class="po-loading-icon-bar po-loading-icon-bar-2"></span>
4+
<span class="po-loading-icon-bar po-loading-icon-bar-3"></span>
5+
<span class="po-loading-icon-bar po-loading-icon-bar-4"></span>
6+
<span class="po-loading-icon-bar po-loading-icon-bar-5"></span>
7+
<span class="po-loading-icon-bar po-loading-icon-bar-6"></span>
8+
<span class="po-loading-icon-bar po-loading-icon-bar-7"></span>
9+
<span class="po-loading-icon-bar po-loading-icon-bar-8"></span>
10+
</div>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
import { By } from '@angular/platform-browser';
3+
4+
import { configureTestSuite, expectPropertiesValues } from '../../../util-test/util-expect.spec';
5+
6+
import { PoLoadingIconComponent } from './po-loading-icon.component';
7+
import { PoLoadingModule } from '../po-loading.module';
8+
9+
describe('PoLoadingOverlayComponent', () => {
10+
let component: PoLoadingIconComponent;
11+
let fixture: ComponentFixture<PoLoadingIconComponent>;
12+
let nativeElement: any;
13+
14+
configureTestSuite(() => {
15+
TestBed.configureTestingModule({
16+
imports: [ PoLoadingModule ]
17+
});
18+
});
19+
20+
beforeEach(() => {
21+
fixture = TestBed.createComponent(PoLoadingIconComponent);
22+
component = fixture.componentInstance;
23+
24+
nativeElement = fixture.debugElement.nativeElement;
25+
});
26+
27+
it('should be created', () => {
28+
expect(component instanceof PoLoadingIconComponent).toBeTruthy();
29+
});
30+
31+
describe('Properties', () => {
32+
33+
it('p-neutral-color: should update property with valid values', () => {
34+
const validValuesTrue = [true, 'true', 1, ''];
35+
const validValuesFalse = [false, 'false', 0];
36+
37+
expectPropertiesValues(component, 'neutralColor', validValuesTrue, true);
38+
expectPropertiesValues(component, 'neutralColor', validValuesFalse, false);
39+
});
40+
41+
it('p-neutral-color: should update property with false if it receives an invalid values', () => {
42+
const invalidValues = [null, undefined, NaN, 'teste'];
43+
44+
expectPropertiesValues(component, 'neutralColor', invalidValues, false);
45+
});
46+
});
47+
48+
describe('Templates', () => {
49+
50+
it('should count the amount of `po-loading-icon-bar` elements', () => {
51+
const iconBars = fixture.debugElement.queryAll(By.css('.po-loading-icon-bar'));
52+
53+
expect(iconBars.length).toBe(8);
54+
});
55+
});
56+
57+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Component, Input } from '@angular/core';
2+
3+
import { convertToBoolean } from '../../../utils/util';
4+
5+
/**
6+
* @docsPrivate
7+
*
8+
* @description
9+
*
10+
* Componente que exibe um ícone de carregamento de conteúdo. A cor padrão para ele é a primária conforme o tema utilizado.
11+
* É possível alterá-la para um tom cinza conforme a necessidade.
12+
*/
13+
@Component({
14+
selector: 'po-loading-icon',
15+
templateUrl: 'po-loading-icon.component.html'
16+
})
17+
export class PoLoadingIconComponent {
18+
19+
private _neutralColor: boolean;
20+
21+
/**
22+
* @optional
23+
*
24+
* @description
25+
*
26+
* Definição para cor neutra (cinza) para o ícone de carregamento.
27+
*
28+
* @default `false`
29+
*/
30+
@Input('p-neutral-color') set neutralColor(value: boolean) {
31+
this._neutralColor = convertToBoolean(value);
32+
}
33+
34+
get neutralColor(): boolean {
35+
return this._neutralColor;
36+
}
37+
38+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<div class="po-loading">
2-
<span class="po-loading-icon"></span>
2+
<po-loading-icon></po-loading-icon>
33
<span class="po-loading-label po-text-ellipsis" *ngIf="text">{{text}}</span>
44
</div>

0 commit comments

Comments
 (0)