Skip to content

Commit 2fe04cf

Browse files
jhonyeduardojhosefmarks
authored andcommitted
perf(tag): adiciona ChangeDetectionStrategy.OnPush
Adiciona ChangeDetectionStrategy.OnPush no componente.
1 parent 4b8f3ce commit 2fe04cf

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Component } from '@angular/core';
12
import { ComponentFixture, TestBed } from '@angular/core/testing';
23

34
import { Observable } from 'rxjs';
@@ -10,23 +11,32 @@ import { PoTagIcon } from './enums/po-tag-icon.enum';
1011
import { PoTagOrientation } from './enums/po-tag-orientation.enum';
1112
import { PoTagType } from './enums/po-tag-type.enum';
1213

14+
@Component({
15+
template: `<po-tag p-label="Mock" (p-click)="onClick()"></po-tag>`
16+
})
17+
class PoTagClickableComponent {
18+
onClick() {}
19+
}
20+
1321
describe('PoTagComponent:', () => {
1422
let component: PoTagComponent;
1523
let fixture: ComponentFixture<PoTagComponent>;
1624

25+
let fixtureClickable: ComponentFixture<PoTagClickableComponent>;
26+
1727
let nativeElement: any;
1828

1929
configureTestSuite(() => {
2030
TestBed.configureTestingModule({
21-
declarations: [ PoTagComponent ]
31+
declarations: [ PoTagComponent, PoTagClickableComponent ]
2232
});
2333
});
2434

2535
beforeEach(() => {
2636
fixture = TestBed.createComponent(PoTagComponent);
2737
component = fixture.componentInstance;
2838

29-
fixture.detectChanges();
39+
fixtureClickable = TestBed.createComponent(PoTagClickableComponent);
3040

3141
nativeElement = fixture.debugElement.nativeElement;
3242
});
@@ -231,6 +241,8 @@ describe('PoTagComponent:', () => {
231241
});
232242

233243
it('should add `po-tag-info` as default.', () => {
244+
fixture.detectChanges();
245+
234246
expect(nativeElement.querySelector('.po-tag-info')).toBeTruthy();
235247
});
236248

@@ -303,10 +315,9 @@ describe('PoTagComponent:', () => {
303315
});
304316

305317
it('should add `po-clickable` if `p-click` @Output is wire up`.', () => {
306-
component.isClickable = true;
318+
fixtureClickable.detectChanges();
307319

308-
fixture.detectChanges();
309-
expect(nativeElement.querySelector('.po-clickable')).toBeTruthy();
320+
expect(fixtureClickable.debugElement.nativeElement.querySelector('.po-clickable')).toBeTruthy();
310321
});
311322

312323
it('shouldn`t add `po-clickable` if `p-click` @Output isn`t wire up`.', () => {

projects/ui/src/lib/components/po-tag/po-tag.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
22

33
import { PoKeyCodeEnum } from '../../enums/po-key-code.enum';
44

@@ -31,7 +31,8 @@ const poTagTypeDefault = 'po-tag-' + PoTagType.Info;
3131
*/
3232
@Component({
3333
selector: 'po-tag',
34-
templateUrl: './po-tag.component.html'
34+
templateUrl: './po-tag.component.html',
35+
changeDetection: ChangeDetectionStrategy.OnPush
3536
})
3637
export class PoTagComponent extends PoTagBaseComponent implements OnInit {
3738

0 commit comments

Comments
 (0)