Skip to content

Commit

Permalink
Add select testing entry point, and use pageObject in test.
Browse files Browse the repository at this point in the history
  • Loading branch information
atmgrifter00 committed Mar 8, 2024
1 parent 285fb2c commit a4c5069
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "../../../../../../node_modules/ng-packagr/ng-package.schema.json",
"lib": {
"entryFile": "public-api.ts"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './select.pageobject';
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { Component, ElementRef, Input, OnChanges, OnInit, SimpleChange, SimpleChanges, ViewChild } from '@angular/core';
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { AbstractControl, FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { SelectPageObject } from '@ni/nimble-angular/select/testing';
import { NimbleSelectModule } from '../nimble-select.module';
import { NimbleListOptionModule } from '../../list-option/nimble-list-option.module';
import { processUpdates, waitForUpdatesAsync } from '../../../testing/async-helpers';
import type { Select } from '../nimble-select.directive';

function setSelectValue(select: Select, index: number): void {
select.dispatchEvent(new Event('click'));
select.options[index].dispatchEvent(new Event('click', { bubbles: true }));
}

describe('Nimble select control value accessor', () => {
describe('when using option\'s [ngValue] binding', () => {
@Component({
Expand Down Expand Up @@ -46,6 +42,7 @@ describe('Nimble select control value accessor', () => {
let select: Select;
let fixture: ComponentFixture<TestHostComponent>;
let testHostComponent: TestHostComponent;
let pageObject: SelectPageObject;

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -58,6 +55,7 @@ describe('Nimble select control value accessor', () => {
fixture = TestBed.createComponent(TestHostComponent);
testHostComponent = fixture.componentInstance;
select = testHostComponent.select.nativeElement;
pageObject = new SelectPageObject(select);
fixture.detectChanges();
// wait for select's 'options' property to be updated from slotted content
await waitForUpdatesAsync();
Expand All @@ -81,7 +79,8 @@ describe('Nimble select control value accessor', () => {
}));

it('updates bound property when selected value is changed', () => {
setSelectValue(select, 2);
pageObject.clickSelect();
pageObject.clickOption(2);
fixture.detectChanges();

expect(testHostComponent.selectedOption).toBe(testHostComponent.selectOptions[2]);
Expand Down Expand Up @@ -110,7 +109,8 @@ describe('Nimble select control value accessor', () => {
it('fires ngModelChange one time with expected value', () => {
const ngModelChangeSpy = spyOn(testHostComponent, 'onModelValueChange');
const indexToSelect = 2;
setSelectValue(select, indexToSelect);
pageObject.clickSelect();
pageObject.clickOption(indexToSelect);
fixture.detectChanges();
expect(ngModelChangeSpy).toHaveBeenCalledOnceWith(testHostComponent.selectOptions[indexToSelect]);
});
Expand Down Expand Up @@ -142,6 +142,7 @@ describe('Nimble select control value accessor', () => {
let select: Select;
let fixture: ComponentFixture<TestHostComponent>;
let testHostComponent: TestHostComponent;
let pageObject: SelectPageObject;

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -154,6 +155,7 @@ describe('Nimble select control value accessor', () => {
fixture = TestBed.createComponent(TestHostComponent);
testHostComponent = fixture.componentInstance;
select = testHostComponent.select.nativeElement;
pageObject = new SelectPageObject(select);
fixture.detectChanges();
// wait for select's 'options' property to be updated from slotted content
await waitForUpdatesAsync();
Expand All @@ -177,7 +179,8 @@ describe('Nimble select control value accessor', () => {
}));

it('updates bound property when selected value is changed', () => {
setSelectValue(select, 2);
pageObject.clickSelect();
pageObject.clickOption(2);
fixture.detectChanges();

expect(testHostComponent.selectedOption).toBe(testHostComponent.selectOptions[2].value.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export * from './directives/radio-group/nimble-radio-group.directive';
export * from './directives/radio-group/nimble-radio-group.module';
export * from './directives/select/nimble-select-control-value-accessor.directive';
export * from './directives/select/nimble-select.directive';
export * from './directives/select/testing/select.pageobject';
export * from './directives/select/nimble-select.module';
export * from './directives/spinner/nimble-spinner.directive';
export * from './directives/spinner/nimble-spinner.module';
Expand Down

0 comments on commit a4c5069

Please sign in to comment.