diff --git a/src/app/core/guards/registration-moderation.guard.ts b/src/app/core/guards/registration-moderation.guard.ts index b9286fa5b..6c7bc47eb 100644 --- a/src/app/core/guards/registration-moderation.guard.ts +++ b/src/app/core/guards/registration-moderation.guard.ts @@ -16,10 +16,12 @@ export const registrationModerationGuard: CanActivateFn = (route) => { if (provider?.reviewsWorkflow) { return true; } + const id = route.params['providerId']; + return store.dispatch(new GetRegistryProvider(id)).pipe( - switchMap(() => { - return store.select(RegistrationProviderSelectors.getBrandedProvider).pipe( + switchMap(() => + store.select(RegistrationProviderSelectors.getBrandedProvider).pipe( take(1), map((provider) => { if (!provider?.reviewsWorkflow) { @@ -29,7 +31,7 @@ export const registrationModerationGuard: CanActivateFn = (route) => { return true; }) - ); - }) + ) + ) ); }; diff --git a/src/app/features/registries/pages/my-registrations-redirect/my-registrations-redirect.component.spec.ts b/src/app/features/registries/pages/my-registrations-redirect/my-registrations-redirect.component.spec.ts new file mode 100644 index 000000000..d4f40e53f --- /dev/null +++ b/src/app/features/registries/pages/my-registrations-redirect/my-registrations-redirect.component.spec.ts @@ -0,0 +1,51 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { Router } from '@angular/router'; + +import { MyRegistrationsRedirectComponent } from './my-registrations-redirect.component'; + +import { RouterMock } from '@testing/providers/router-provider.mock'; + +describe('MyRegistrationsRedirectComponent', () => { + let component: MyRegistrationsRedirectComponent; + let fixture: ComponentFixture; + let router: jest.Mocked; + + beforeEach(async () => { + const routerMock = RouterMock.create().build(); + + await TestBed.configureTestingModule({ + imports: [MyRegistrationsRedirectComponent], + providers: [{ provide: Router, useValue: routerMock }], + }).compileComponents(); + + fixture = TestBed.createComponent(MyRegistrationsRedirectComponent); + component = fixture.componentInstance; + router = TestBed.inject(Router) as jest.Mocked; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); + + it('should be an instance of MyRegistrationsRedirectComponent', () => { + expect(component).toBeInstanceOf(MyRegistrationsRedirectComponent); + }); + + it('should navigate to /my-registrations on component creation', () => { + expect(router.navigate).toHaveBeenCalledWith(['/my-registrations'], { + queryParamsHandling: 'preserve', + replaceUrl: true, + }); + }); + + it('should preserve query parameters during navigation', () => { + const navigationOptions = router.navigate.mock.calls[0][1]; + expect(navigationOptions?.queryParamsHandling).toBe('preserve'); + }); + + it('should replace the current URL in browser history', () => { + const navigationOptions = router.navigate.mock.calls[0][1]; + expect(navigationOptions?.replaceUrl).toBe(true); + }); +}); diff --git a/src/app/features/registries/pages/my-registrations-redirect/my-registrations-redirect.component.ts b/src/app/features/registries/pages/my-registrations-redirect/my-registrations-redirect.component.ts new file mode 100644 index 000000000..c4583b6a9 --- /dev/null +++ b/src/app/features/registries/pages/my-registrations-redirect/my-registrations-redirect.component.ts @@ -0,0 +1,13 @@ +import { Component, inject } from '@angular/core'; +import { Router } from '@angular/router'; + +@Component({ + template: '', +}) +export class MyRegistrationsRedirectComponent { + private readonly router = inject(Router); + + constructor() { + this.router.navigate(['/my-registrations'], { queryParamsHandling: 'preserve', replaceUrl: true }); + } +} diff --git a/src/app/features/registries/registries.routes.ts b/src/app/features/registries/registries.routes.ts index 79a6a2291..5686f04b2 100644 --- a/src/app/features/registries/registries.routes.ts +++ b/src/app/features/registries/registries.routes.ts @@ -40,6 +40,13 @@ export const registriesRoutes: Routes = [ (c) => c.RegistriesLandingComponent ), }, + { + path: 'my-registrations', + loadComponent: () => + import('./pages/my-registrations-redirect/my-registrations-redirect.component').then( + (c) => c.MyRegistrationsRedirectComponent + ), + }, { path: ':providerId', loadComponent: () => @@ -65,6 +72,11 @@ export const registriesRoutes: Routes = [ path: 'drafts', loadComponent: () => import('./components/drafts/drafts.component').then((mod) => mod.DraftsComponent), children: [ + { + path: ':id', + redirectTo: ':id/metadata', + pathMatch: 'full', + }, { path: ':id/metadata', loadComponent: () =>