Skip to content

Commit 7942a33

Browse files
anabyebruno-severino
authored andcommitted
test: ajusta erros para funcionamento da esteira
Ajusta erros nos testes para correto funcionamento da esteira. Fixes DTHFUI-9761
1 parent 75b75a7 commit 7942a33

File tree

14 files changed

+138
-66
lines changed

14 files changed

+138
-66
lines changed

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@
125125
"gulp": "^4.0.2",
126126
"gulp-tap": "^2.0.0",
127127
"husky": "^8.0.0",
128-
"jasmine-core": "~5.1.1",
129-
"jasmine-spec-reporter": "~7.0.0",
130-
"karma": "~6.4.2",
131-
"karma-chrome-launcher": "~3.2.0",
132-
"karma-coverage": "~2.2.1",
133-
"karma-jasmine": "~5.1.0",
134-
"karma-jasmine-html-reporter": "^2.1.0",
128+
"jasmine-core": "5.1.1",
129+
"jasmine-spec-reporter": "7.0.0",
130+
"karma": "6.4.2",
131+
"karma-chrome-launcher": "3.2.0",
132+
"karma-coverage": "2.2.1",
133+
"karma-jasmine": "5.1.0",
134+
"karma-jasmine-html-reporter": "2.1.0",
135135
"lint-staged": "^15.1.0",
136136
"mkdirp": "3.0.1",
137137
"ng-packagr": "~18.0.0",

projects/ui/karma.conf.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
module.exports = function (config) {
55
config.set({
66
basePath: '',
7+
files: [
8+
{ pattern: './src/lib/util-test/util-setup.spec.ts', watched: false, type: 'js' },
9+
{ pattern: './src/**/*.spec.ts', watched: false, type: 'js' }
10+
],
711
frameworks: ['jasmine', '@angular-devkit/build-angular'],
812
plugins: [
913
require('karma-jasmine'),
@@ -52,7 +56,7 @@ module.exports = function (config) {
5256
flags: ['--no-sandbox', '--headless', '--disable-gpu', '--disable-web-security', '--remote-debugging-port=9222']
5357
}
5458
},
55-
singleRun: false,
59+
singleRun: true,
5660
restartOnFileChange: true,
5761
browserNoActivityTimeout: 50000,
5862
browserDisconnectTimeout: 50000

projects/ui/src/lib/components/po-chart/directives/po-resize-observer.directive.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,26 @@ describe('PoResizeObserverDirective', () => {
8383

8484
window.ResizeObserver = resizeRef;
8585
}));
86+
87+
it('ngOnInit: should call chartWidthResize$.next when ResizeObserver callback is triggered', fakeAsync(() => {
88+
const mockObserver = {
89+
observe: jasmine.createSpy('observe'),
90+
unobserve: jasmine.createSpy('unobserve')
91+
};
92+
93+
spyOn(window as any, 'ResizeObserver').and.callFake(function (callback) {
94+
this.observe = mockObserver.observe;
95+
this.unobserve = mockObserver.unobserve;
96+
this.callback = callback;
97+
});
98+
99+
const nextSpy = spyOn(directive['chartWidthResize$'], 'next');
100+
101+
directive.ngOnInit();
102+
103+
directive['observer'].callback();
104+
tick(20);
105+
106+
expect(nextSpy).toHaveBeenCalledWith({});
107+
}));
86108
});

projects/ui/src/lib/components/po-chart/po-chart-container/po-chart-circular/po-chart-circular-path/po-chart-tooltip.directive.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ describe('PoChartTooltipDirective', () => {
5353
directive.createTooltip();
5454
fixture.detectChanges();
5555

56+
spyOnProperty(directive.tooltipElement, 'offsetWidth').and.returnValue(154);
57+
spyOnProperty(directive.tooltipElement, 'offsetHeight').and.returnValue(60);
58+
5659
event = document.createEvent('MouseEvents');
5760
event.initEvent('scroll', false, true);
5861
});
@@ -112,7 +115,7 @@ describe('PoChartTooltipDirective', () => {
112115

113116
it('calculateTooltipPosition: should return tooltipPosition', () => {
114117
const tooltipEvent = { clientX: 300, clientY: 300 };
115-
const expectedResult = { left: -77, top: 270 };
118+
const expectedResult = { left: 223, top: 228 };
116119
const result = directive.calculateTooltipPosition(tooltipEvent);
117120

118121
expect(result).toEqual(expectedResult);

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,25 @@ describe('PoDisclaimerGroupComponent:', () => {
312312
expect(component['focusOnRemoveTag']).toHaveBeenCalled();
313313
});
314314

315+
it('focusOnNextTag: should select attribute index 0 when event is not enter', () => {
316+
const tagsFake = document.createElement('div');
317+
tagsFake.innerHTML = `
318+
<div class="po-tag-remove"></div>
319+
<div class="po-tag-remove"></div>
320+
<div class="po-tag-remove"></div>
321+
`;
322+
323+
document.body.appendChild(tagsFake);
324+
325+
spyOn(component as any, 'handleKeyboardNavigationTag');
326+
327+
component['focusOnNextTag'](null, 'click');
328+
329+
expect(component['handleKeyboardNavigationTag']).toHaveBeenCalledWith(0);
330+
331+
document.body.removeChild(tagsFake);
332+
});
333+
315334
describe('Templates:', () => {
316335
it(`should set tabindex to 0 if have a disclaimer with 'hideClose'.`, () => {
317336
component.disclaimers = [{ value: 'po', hideClose: false }];

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ describe('PoDropdownComponent: ', () => {
354354
await fixture.whenStable();
355355

356356
const disabledButton = nativeElement.querySelector('.po-dropdown-button-disabled');
357-
console.log('Disabled button:', disabledButton);
358357

359358
expect(disabledButton).toBeTruthy();
360359
});

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { PoComboFilterService } from './po-combo-filter.service';
1818
import { PoComboOption } from './interfaces/po-combo-option.interface';
1919
import { PoCleanComponent } from '../po-clean/po-clean.component';
2020
import { OverlayModule } from '@angular/cdk/overlay';
21+
import { PoControlPositionService } from '../../../services/po-control-position/po-control-position.service';
2122

2223
const eventKeyBoard = document.createEvent('KeyboardEvent');
2324
eventKeyBoard.initEvent('keyup', true, true);
@@ -29,19 +30,23 @@ eventClick.initEvent('click', false, true);
2930
describe('PoComboComponent:', () => {
3031
let component: PoComboComponent;
3132
let fixture: ComponentFixture<PoComboComponent>;
33+
let controlPositionMock: jasmine.SpyObj<PoControlPositionService>;
3234
let nativeElement: any;
3335

3436
beforeEach(async () => {
3537
await TestBed.configureTestingModule({
3638
imports: [PoLoadingModule, PoIconModule, OverlayModule],
3739
declarations: [PoComboComponent, PoFieldContainerComponent, PoFieldContainerBottomComponent, PoCleanComponent],
38-
providers: [HttpClient, HttpHandler]
40+
providers: [HttpClient, HttpHandler, PoControlPositionService]
3941
}).compileComponents();
4042

4143
fixture = TestBed.createComponent(PoComboComponent);
4244
component = fixture.componentInstance;
4345
component.label = 'Label de teste';
4446
component.help = 'Help de teste';
47+
48+
controlPositionMock = jasmine.createSpyObj('PoControlPositionService', ['adjustPosition', 'setElements']);
49+
component['adjustContainerPosition'] = () => controlPositionMock.adjustPosition('bottom');
4550
});
4651

4752
it('should be created', () => {
@@ -1180,11 +1185,17 @@ describe('PoComboComponent:', () => {
11801185
it('adjustContainerPosition: should call `controlPosition.adjustPosition` with default position of container', () => {
11811186
const poComboContainerPositionDefault = 'bottom';
11821187

1183-
const spyAdjustPosition = spyOn(component['controlPosition'], 'adjustPosition');
1184-
11851188
component['adjustContainerPosition']();
11861189

1187-
expect(spyAdjustPosition).toHaveBeenCalledWith(poComboContainerPositionDefault);
1190+
expect(controlPositionMock.adjustPosition).toHaveBeenCalledWith(poComboContainerPositionDefault);
1191+
});
1192+
1193+
it('onScroll: should call `adjustContainerPosition` when triggered', () => {
1194+
const spy = spyOn(component as any, 'adjustContainerPosition');
1195+
1196+
component['onScroll']();
1197+
1198+
expect(spy).toHaveBeenCalled();
11881199
});
11891200
});
11901201

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { provideHttpClientTesting } from '@angular/common/http/testing';
22
import { NO_ERRORS_SCHEMA } from '@angular/core';
3-
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
3+
import { ComponentFixture, discardPeriodicTasks, fakeAsync, flush, TestBed, tick } from '@angular/core/testing';
44
import { RouterTestingModule } from '@angular/router/testing';
55
import { Observable, of } from 'rxjs';
66
import { PoLookupFilter } from '../../../../components/po-field/po-lookup/interfaces/po-lookup-filter.interface';
77
import { PoLookupModalComponent } from '../../../../components/po-field/po-lookup/po-lookup-modal/po-lookup-modal.component';
88
import { PoModalModule } from '../../../../components/po-modal/po-modal.module';
99
import { PoComponentInjectorService } from '../../../../services/po-component-injector/po-component-injector.service';
10-
import { changeBrowserInnerHeight } from '../../../../util-test/util-expect.spec';
1110
import { PoDynamicModule } from '../../../po-dynamic/po-dynamic.module';
1211
import { PoTableColumnSortType } from '../../../po-table/enums/po-table-column-sort-type.enum';
1312
import { PoTableColumnSort } from '../../../po-table/interfaces/po-table-column-sort.interface';
@@ -28,7 +27,7 @@ describe('PoLookupModalComponent', () => {
2827

2928
const advancedFilters = [{ property: 'name', gridColumns: 6, gridSmColumns: 12, order: 1, required: true }];
3029

31-
beforeEach(waitForAsync(() => {
30+
beforeEach(fakeAsync(() => {
3231
TestBed.configureTestingModule({
3332
declarations: [PoLookupModalComponent],
3433
schemas: [NO_ERRORS_SCHEMA],
@@ -40,9 +39,7 @@ describe('PoLookupModalComponent', () => {
4039
provideHttpClientTesting()
4140
]
4241
}).compileComponents();
43-
}));
4442

45-
beforeEach(() => {
4643
fixture = TestBed.createComponent(PoLookupModalComponent);
4744
component = fixture.componentInstance;
4845
component.infiniteScroll = false;
@@ -57,7 +54,7 @@ describe('PoLookupModalComponent', () => {
5754
}),
5855
getObjectByValue: () => of({ items: [{ value: 123, label: 'teste' }] })
5956
};
60-
});
57+
}));
6158

6259
afterEach(() => {
6360
component.poModal.close();
@@ -164,11 +161,16 @@ describe('PoLookupModalComponent', () => {
164161
});
165162

166163
describe('AdvancedSearch: ', () => {
167-
beforeEach(waitForAsync(() => {
164+
beforeEach(fakeAsync(() => {
168165
component.advancedFilters = advancedFilters;
169166
fixture.detectChanges();
170167
component.onAdvancedFilter();
168+
169+
tick(10);
171170
fixture.detectChanges();
171+
172+
flush();
173+
discardPeriodicTasks();
172174
}));
173175

174176
afterEach(() => {

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ describe('PoLookupComponent:', () => {
572572
expect(spyCallOnChange).toHaveBeenCalled();
573573
});
574574

575-
it('updateVisibleItems: should concat `visibleDisclaimers` with items of disclaimers', () => {
575+
it('updateVisibleItems: should concat `visibleDisclaimers` with items of disclaimers', fakeAsync(() => {
576576
fixture.detectChanges();
577577
const itemsDisclaimers = [
578578
{
@@ -588,58 +588,57 @@ describe('PoLookupComponent:', () => {
588588
const spyDebounceResize = spyOn(component, 'debounceResize');
589589

590590
component.disclaimers = itemsDisclaimers;
591-
592591
component.updateVisibleItems();
593592

593+
tick();
594+
594595
expect(component.visibleDisclaimers.length).toEqual(2);
595596
expect(spyDebounceResize).toHaveBeenCalled();
596-
});
597+
}));
597598

598-
it(`updateVisibleItems: shouldn't concat 'visibleDisclaimers' with items of disclaimers`, () => {
599+
it(`updateVisibleItems: shouldn't concat 'visibleDisclaimers' with items of disclaimers`, fakeAsync(() => {
599600
fixture.detectChanges();
600601
const spyDebounceResize = spyOn(component, 'debounceResize');
601602

602603
component.disclaimers = [];
603-
604-
component.visibleDisclaimers = [
605-
{
606-
value: 'test',
607-
label: 'test'
608-
}
609-
];
604+
component.visibleDisclaimers = [{ value: 'test', label: 'test' }];
610605
component.updateVisibleItems();
611606

607+
tick();
608+
612609
expect(component.disclaimers.length).toEqual(0);
613610
expect(component.visibleDisclaimers.length).toEqual(1);
614611
expect(spyDebounceResize).toHaveBeenCalled();
615-
});
612+
}));
616613

617-
it('updateVisibleItems: should set true in `isCalculateVisibleItems` if `offsetWidth` is false', () => {
614+
it('updateVisibleItems: should set true in `isCalculateVisibleItems` if `offsetWidth` is false', fakeAsync(() => {
618615
fixture.detectChanges();
619616
const spyDebounceResize = spyOn(component, 'debounceResize');
620617
component.disclaimers = [];
621618

622619
spyOnProperty(component.inputEl.nativeElement, 'offsetWidth').and.returnValue(false);
623-
624620
component.updateVisibleItems();
625621

622+
tick();
623+
626624
expect(component['isCalculateVisibleItems']).toBeTruthy();
627625
expect(spyDebounceResize).toHaveBeenCalled();
628-
});
626+
}));
629627

630-
it('updateVisibleItems: should set false in `isCalculateVisibleItems` if `offsetWidth` is true', () => {
628+
it('updateVisibleItems: should set false in `isCalculateVisibleItems` if `offsetWidth` is true', fakeAsync(() => {
631629
fixture.detectChanges();
632630
component['isCalculateVisibleItems'] = false;
633631
const spyDebounceResize = spyOn(component, 'debounceResize');
634632
component.disclaimers = [];
635633

636634
spyOnProperty(component.inputEl.nativeElement, 'offsetWidth').and.returnValue(true);
637-
638635
component.updateVisibleItems();
639636

637+
tick();
638+
640639
expect(component['isCalculateVisibleItems']).toBeFalsy();
641640
expect(spyDebounceResize).toHaveBeenCalled();
642-
});
641+
}));
643642

644643
it(`debounceResize: should call 'calculateVisibleItems'`, fakeAsync(() => {
645644
component.autoHeight = false;

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@ import { OverlayModule } from '@angular/cdk/overlay';
22
import { HttpClient, HttpHandler, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
33
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
44
import { ComponentFixture, fakeAsync, flush, TestBed, tick } from '@angular/core/testing';
5-
import { Observable, catchError, of, tap, throwError } from 'rxjs';
5+
import { Observable, of, throwError } from 'rxjs';
66

77
import * as UtilsFunction from '../../../utils/util';
88

9-
import { PoTagComponent } from '../../po-tag/po-tag.component';
109
import { Renderer2 } from '@angular/core';
1110
import { PoKeyCodeEnum } from '../../../enums/po-key-code.enum';
11+
import { PoControlPositionService } from '../../../services/po-control-position/po-control-position.service';
12+
import { PoTagComponent } from '../../po-tag/po-tag.component';
1213
import { PoFieldContainerComponent } from '../po-field-container/po-field-container.component';
1314
import { PoMultiselectBaseComponent } from '../po-multiselect/po-multiselect-base.component';
1415
import { PoFieldContainerBottomComponent } from './../po-field-container/po-field-container-bottom/po-field-container-bottom.component';
1516
import { PoMultiselectDropdownComponent } from './po-multiselect-dropdown/po-multiselect-dropdown.component';
1617
import { PoMultiselectFilter } from './po-multiselect-filter.interface';
1718
import { PoMultiselectFilterService } from './po-multiselect-filter.service';
18-
import { PoMultiselectComponent } from './po-multiselect.component';
1919
import { PoMultiselectOption } from './po-multiselect-option.interface';
20+
import { PoMultiselectComponent } from './po-multiselect.component';
2021

2122
const poMultiselectFilterServiceStub: PoMultiselectFilter = {
2223
getFilteredData: function (params: { property: string; value: string }): Observable<Array<PoMultiselectOption>> {
@@ -31,6 +32,7 @@ describe('PoMultiselectComponent:', () => {
3132
let fnAdjustContainerPosition;
3233
let component: PoMultiselectComponent;
3334
let fixture: ComponentFixture<PoMultiselectComponent>;
35+
let controlPositionMock: jasmine.SpyObj<PoControlPositionService>;
3436

3537
let multiSelectService: PoMultiselectFilterService;
3638
let httpMock: HttpTestingController;
@@ -62,6 +64,7 @@ describe('PoMultiselectComponent:', () => {
6264
HttpHandler,
6365
Renderer2,
6466
PoMultiselectFilterService,
67+
PoControlPositionService,
6568
provideHttpClient(withInterceptorsFromDi()),
6669
provideHttpClientTesting()
6770
]
@@ -71,7 +74,8 @@ describe('PoMultiselectComponent:', () => {
7174
component = fixture.componentInstance;
7275
renderer = TestBed.inject(Renderer2);
7376
fnAdjustContainerPosition = component['adjustContainerPosition'];
74-
component['adjustContainerPosition'] = () => {};
77+
controlPositionMock = jasmine.createSpyObj('PoControlPositionService', ['adjustPosition', 'setElements']);
78+
component['adjustContainerPosition'] = () => controlPositionMock.adjustPosition('bottom');
7579

7680
component.options = [{ label: 'label', value: 1 }];
7781
component.autoHeight = true;
@@ -157,11 +161,13 @@ describe('PoMultiselectComponent:', () => {
157161
expect(component.initialized).toBeTruthy();
158162
});
159163

160-
it('shouldn`t set focus on input', () => {
164+
it('shouldn`t set focus on input', done => {
161165
component.initialized = false;
162166
component.autoFocus = false;
163167
spyOn(component.inputElement.nativeElement, 'focus');
164168

169+
done();
170+
165171
component.ngAfterViewInit();
166172
expect(component.inputElement.nativeElement.focus).not.toHaveBeenCalled();
167173

0 commit comments

Comments
 (0)