|
| 1 | +import { ComponentFixture, TestBed } from '@angular/core/testing'; |
| 2 | +import { Router } from '@angular/router'; |
| 3 | + |
| 4 | +import { MyRegistrationsRedirectComponent } from './my-registrations-redirect.component'; |
| 5 | + |
| 6 | +import { RouterMock } from '@testing/providers/router-provider.mock'; |
| 7 | + |
| 8 | +describe('MyRegistrationsRedirectComponent', () => { |
| 9 | + let component: MyRegistrationsRedirectComponent; |
| 10 | + let fixture: ComponentFixture<MyRegistrationsRedirectComponent>; |
| 11 | + let router: jest.Mocked<Router>; |
| 12 | + |
| 13 | + beforeEach(async () => { |
| 14 | + const routerMock = RouterMock.create().build(); |
| 15 | + |
| 16 | + await TestBed.configureTestingModule({ |
| 17 | + imports: [MyRegistrationsRedirectComponent], |
| 18 | + providers: [{ provide: Router, useValue: routerMock }], |
| 19 | + }).compileComponents(); |
| 20 | + |
| 21 | + fixture = TestBed.createComponent(MyRegistrationsRedirectComponent); |
| 22 | + component = fixture.componentInstance; |
| 23 | + router = TestBed.inject(Router) as jest.Mocked<Router>; |
| 24 | + fixture.detectChanges(); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should create', () => { |
| 28 | + expect(component).toBeTruthy(); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should be an instance of MyRegistrationsRedirectComponent', () => { |
| 32 | + expect(component).toBeInstanceOf(MyRegistrationsRedirectComponent); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should navigate to /my-registrations on component creation', () => { |
| 36 | + expect(router.navigate).toHaveBeenCalledWith(['/my-registrations'], { |
| 37 | + queryParamsHandling: 'preserve', |
| 38 | + replaceUrl: true, |
| 39 | + }); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should preserve query parameters during navigation', () => { |
| 43 | + const navigationOptions = router.navigate.mock.calls[0][1]; |
| 44 | + expect(navigationOptions?.queryParamsHandling).toBe('preserve'); |
| 45 | + }); |
| 46 | + |
| 47 | + it('should replace the current URL in browser history', () => { |
| 48 | + const navigationOptions = router.navigate.mock.calls[0][1]; |
| 49 | + expect(navigationOptions?.replaceUrl).toBe(true); |
| 50 | + }); |
| 51 | +}); |
0 commit comments