Skip to content
Snippets Groups Projects
Commit e6c347aa authored by OZGCloud's avatar OZGCloud
Browse files

OZG-5793 Add test case

parent 22c7123d
No related branches found
No related tags found
No related merge requests found
......@@ -51,12 +51,12 @@ import { MatFormFieldModule } from '@angular/material/form-field';
import { MatIcon } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { NavigationEnd, Router } from '@angular/router';
import { NavigationEnd, Router, RouterEvent } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { getDataTestClassOf, getDataTestIdOf } from 'libs/tech-shared/test/data-test';
import { createVorgangListResource } from 'libs/vorgang-shared/test/vorgang';
import { MockComponent } from 'ng-mocks';
import { BehaviorSubject, Observable, Subject, of } from 'rxjs';
import { BehaviorSubject, ReplaySubject, Subject, of } from 'rxjs';
import { VorgangSearchAutocompleteOptionsContentComponent } from './vorgang-search-autocomplete-options-content/vorgang-search-autocomplete-options-content.component';
import { VorgangSearchClearButtonComponent } from './vorgang-search-clear-button/vorgang-search-clear-button.component';
import { VorgangSearchComponent } from './vorgang-search.component';
......@@ -72,6 +72,13 @@ describe('VorgangSearchComponent', () => {
const searchStringSubj: Subject<string> = new BehaviorSubject(EMPTY_STRING);
const routerEvents: ReplaySubject<RouterEvent> = new ReplaySubject<RouterEvent>();
const routerMock = {
navigate: jest.fn(),
url: '/',
events: routerEvents.asObservable(),
};
const searchPreviewOption: string = getDataTestClassOf('search-preview-option');
const searchClearButton: string = getDataTestIdOf('vorgang-search-clear-button');
......@@ -119,17 +126,7 @@ describe('VorgangSearchComponent', () => {
},
{
provide: Router,
useValue: {
url: '/',
events: of(
new NavigationEnd(
0,
'/alle/search',
'/alle/search',
),
),
navigate: jest.fn(),
},
useValue: routerMock,
},
],
}).compileComponents();
......@@ -170,12 +167,21 @@ describe('VorgangSearchComponent', () => {
});
describe('ngOnInit', () => {
it('should set focus', () => {
const focusSpy = jest.spyOn(component, 'focus');
it('should set focus if path is "/alle/search"', () => {
component.focus = jest.fn();
routerEvents.next(new NavigationEnd(1, '/alle/search', ''));
component.ngOnInit();
expect(component.focus).toHaveBeenCalled();
});
it('should not set focus if path is not "/alle/search"', () => {
component.focus = jest.fn();
component.ngOnInit();
expect(focusSpy).toHaveBeenCalled();
expect(component.focus).toHaveBeenCalled();
});
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment