Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Angular Material Autocomplete test #2217

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 59 additions & 12 deletions packages/angular-material/test/autocomplete-control.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,18 +289,17 @@ describe('AutoComplete control Input Event Tests', () => {
zone.runOutsideAngular(() => zone.onStable.emit(null));
fixture.detectChanges();

const options = overlayContainerElement.querySelectorAll(
'mat-option'
) as NodeListOf<HTMLElement>;
options.item(0).click();
tick();
fixture.detectChanges();

expect(spy).toHaveBeenCalled();
const event = spy.calls.mostRecent()
.args[0] as MatAutocompleteSelectedEvent;

expect(event.option.value).toBe('X');
fixture.whenStable().then(() => {
const options = overlayContainerElement?.querySelectorAll(
'mat-option'
) as NodeListOf<HTMLElement>;
(options[1] as HTMLElement).click();
fixture.detectChanges();
tick();
const event = spy.calls.mostRecent()
.args[0] as MatAutocompleteSelectedEvent;
expect(event.option.value).toBe('Y');
});
}));
});
describe('AutoComplete control Error Tests', () => {
Expand Down Expand Up @@ -347,3 +346,51 @@ describe('AutoComplete control Error Tests', () => {
).toBe('Hi, this is me, test error!');
});
});

describe('AutoComplete control updateFilter function', () => {
let fixture: ComponentFixture<AutocompleteControlRenderer>;
let component: AutocompleteControlRenderer;

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [componentUT],
imports: imports,
providers: providers,
}).compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(componentUT);
component = fixture.componentInstance;
});

it('should not filter options on ENTER key press', () => {
component.shouldFilter = false;
component.options = ['X', 'Y', 'Z'];
setupMockStore(fixture, { uischema, schema, data });
getJsonFormsService(component).updateCore(
Actions.init(data, schema, uischema)
);
component.ngOnInit();
fixture.detectChanges();
component.updateFilter({ keyCode: 13 });
fixture.detectChanges();
expect(component.shouldFilter).toBe(false);
});

it('should filter options when a key other than ENTER is pressed', () => {
component.shouldFilter = false;
component.options = ['X', 'Y', 'Z'];
setupMockStore(fixture, { uischema, schema, data });
getJsonFormsService(component).updateCore(
Actions.init(data, schema, uischema)
);
component.ngOnInit();
fixture.detectChanges();

component.updateFilter({ keyCode: 65 });
fixture.detectChanges();

expect(component.shouldFilter).toBe(true);
});
});