Skip to content
Snippets Groups Projects

Ozg 6986 adjust routing

Merged
Martin Küsterrequested to merge
OZG-6986-AdjustRouting into main
All threads resolved!

Files

@@ -21,10 +21,11 @@
* Die sprachspezifischen Genehmigungen und Beschränkungen
* unter der Lizenz sind dem Lizenztext zu entnehmen.
*/
import { ConfigurationLinkRel, ConfigurationResource, ConfigurationService } from '@admin-client/configuration-shared';
import { ApiRootLinkRel, ApiRootResource, ApiRootService } from '@alfa-client/api-root-shared';
import { BuildInfoComponent } from '@alfa-client/common';
import { HasLinkPipe, createEmptyStateResource, createStateResource } from '@alfa-client/tech-shared';
import { Mock, dispatchEventFromFixture, existsAsHtmlElement, mock, notExistsAsHtmlElement } from '@alfa-client/test-utils';
import { Mock, existsAsHtmlElement, mock, notExistsAsHtmlElement } from '@alfa-client/test-utils';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ActivatedRoute, Router, RouterOutlet } from '@angular/router';
import { AuthenticationService } from '@authentication';
@@ -36,11 +37,12 @@ import {
OrgaUnitIconComponent,
UsersIconComponent,
} from '@ods/system';
import { createConfigurationResource } from 'libs/admin/configuration-shared/test/configuration';
import { MenuContainerComponent } from 'libs/admin/configuration/src/lib/menu-container/menu-container.component';
import { createApiRootResource } from 'libs/api-root-shared/test/api-root';
import { getDataTestIdOf } from 'libs/tech-shared/test/data-test';
import { MockComponent, MockDirective } from 'ng-mocks';
import { of } from 'rxjs';
import { Subscription, of } from 'rxjs';
import { UserProfileButtonContainerComponent } from '../common/user-profile-button-container/user-profile.button-container.component';
import { UnavailablePageComponent } from '../pages/unavailable/unavailable-page/unavailable-page.component';
import { AppComponent } from './app.component';
@@ -55,7 +57,6 @@ describe('AppComponent', () => {
const usersRolesNavigationSelector: string = getDataTestIdOf('users-roles-navigation');
const organisationsEinheitenNavigationSelector: string = getDataTestIdOf('organisations-einheiten-navigation');
const logoLink: string = getDataTestIdOf('logo-link');
const routerOutletSelector: string = getDataTestIdOf('router-outlet');
const menuContainer: string = getDataTestIdOf('menu-container');
@@ -78,8 +79,11 @@ describe('AppComponent', () => {
};
const apiRootService: Mock<ApiRootService> = mock(ApiRootService);
let configurationService: Mock<ConfigurationService>;
beforeEach(async () => {
configurationService = mock(ConfigurationService);
await TestBed.configureTestingModule({
imports: [HasLinkPipe],
declarations: [
@@ -105,6 +109,10 @@ describe('AppComponent', () => {
provide: ApiRootService,
useValue: apiRootService,
},
{
provide: ConfigurationService,
useValue: configurationService,
},
{
provide: Router,
useValue: router,
@@ -147,26 +155,195 @@ describe('AppComponent', () => {
});
describe('do after logged in', () => {
beforeEach(() => {
component.evaluateInitialNavigation = jest.fn();
});
it('should call apiRootService to getApiRoot', () => {
component.doAfterLoggedIn();
expect(apiRootService.getApiRoot).toHaveBeenCalled();
});
it('should call forwardWithoutAuthenticationParams', () => {
component.forwardWithoutAuthenticationParams = jest.fn();
it('should call evaluateInitialNavigation', () => {
component.evaluateInitialNavigation = jest.fn();
component.doAfterLoggedIn();
expect(component.forwardWithoutAuthenticationParams).toHaveBeenCalled();
expect(component.evaluateInitialNavigation).toHaveBeenCalled();
});
});
describe('evaluate initial navigation', () => {
beforeEach(() => {
component.evaluateNavigationByApiRoot = jest.fn();
});
it('should call evaluate navigation by apiRoot', () => {
const apiRootResource: ApiRootResource = createApiRootResource();
component.apiRootStateResource$ = of(createStateResource(apiRootResource));
component.evaluateInitialNavigation();
expect(component.evaluateNavigationByApiRoot).toHaveBeenCalledWith(apiRootResource);
});
it('should NOT call evaluate navigation by apiRoot if resource is loading', () => {
component.apiRootStateResource$ = of(createEmptyStateResource<ApiRootResource>(true));
component.evaluateNavigationByApiRoot = jest.fn();
component.evaluateInitialNavigation();
expect(component.evaluateNavigationByApiRoot).not.toHaveBeenCalled();
});
});
describe('evaluate navigation api root', () => {
it('should evaluate navigation by configuration if link exists', () => {
component.evaluateNavigationByConfiguration = jest.fn();
const apiRootResource: ApiRootResource = createApiRootResource([ApiRootLinkRel.CONFIGURATION]);
component.evaluateNavigationByApiRoot(apiRootResource);
expect(component.evaluateNavigationByConfiguration).toHaveBeenCalled();
});
it('should navigate by api root if link is missing', () => {
component.navigateByApiRoot = jest.fn();
const apiRootResource: ApiRootResource = createApiRootResource();
component.evaluateNavigationByApiRoot(apiRootResource);
expect(component.navigateByApiRoot).toHaveBeenCalledWith(apiRootResource);
});
});
describe('evaluate navigation by configuration', () => {
const configurationResource: ConfigurationResource = createConfigurationResource();
beforeEach(() => {
configurationService.get.mockReturnValue(of(createStateResource(configurationResource)));
component.navigateByConfiguration = jest.fn();
});
it('should call configuration service to get resource', () => {
component.evaluateNavigationByConfiguration();
expect(configurationService.get).toHaveBeenCalled();
});
it('should call navigate by configuration', () => {
component.evaluateNavigationByConfiguration();
expect(component.navigateByConfiguration).toHaveBeenCalledWith(configurationResource);
});
it('should NOT call navigate by configuration if resource is loading', () => {
configurationService.get.mockReturnValue(of(createEmptyStateResource<ConfigurationResource>(true)));
component.evaluateNavigationByConfiguration();
expect(component.navigateByConfiguration).not.toHaveBeenCalled();
});
});
describe('navigate by configuration', () => {
beforeEach(() => {
component.unsubscribe = jest.fn();
});
it('should navigate to postfach if settings link exists', () => {
component.navigateByConfiguration(createConfigurationResource([ConfigurationLinkRel.SETTING]));
expect(router.navigate).toHaveBeenCalledWith(['/postfach']);
});
it('should navigate to statistik if aggregation mapping link exists', () => {
component.navigateByConfiguration(createConfigurationResource([ConfigurationLinkRel.AGGREGATION_MAPPINGS]));
expect(router.navigate).toHaveBeenCalledWith(['/statistik']);
});
it('should navigate to unavailable page if no link exists', () => {
component.navigateByConfiguration(createConfigurationResource());
expect(router.navigate).toHaveBeenCalledWith(['/unavailable']);
});
it('should call unsubscribe', () => {
component.navigateByConfiguration(createConfigurationResource());
expect(component.unsubscribe).toHaveBeenCalled();
});
});
describe('navigate by api root', () => {
beforeEach(() => {
component.unsubscribe = jest.fn();
});
it('should navigate to benutzer und rollen if users link exists', () => {
const apiRootResource: ApiRootResource = createApiRootResource([ApiRootLinkRel.USERS]);
component.navigateByApiRoot(apiRootResource);
expect(router.navigate).toHaveBeenCalledWith(['/benutzer_und_rollen']);
});
it('should navigate to unavailable page if no link exists', () => {
component.navigateByApiRoot(createApiRootResource());
expect(router.navigate).toHaveBeenCalledWith(['/unavailable']);
});
it('should call unsubscribe', () => {
component.navigateByApiRoot(createApiRootResource());
expect(component.unsubscribe).toHaveBeenCalled();
});
});
describe('forward without authentication params', () => {
it('should navigate to same route without authentication params', () => {
component.forwardWithoutAuthenticationParams();
describe('unsubscribe', () => {
describe('apiRoot subscription', () => {
it('should unsubscribe if exists', () => {
component.apiRootSubscription = <any>mock(Subscription);
component.apiRootSubscription.unsubscribe = jest.fn();
expect(router.navigate).toHaveBeenCalledWith([], { queryParams: {} });
component.unsubscribe();
expect(component.apiRootSubscription.unsubscribe).toHaveBeenCalled();
});
it('should do nothing if not exists', () => {
component.apiRootSubscription = undefined;
const unsubscribeSpy: jest.SpyInstance = jest.spyOn(Subscription.prototype, 'unsubscribe');
component.unsubscribe();
expect(unsubscribeSpy).not.toHaveBeenCalled();
unsubscribeSpy.mockRestore();
});
});
describe('configuration subscription', () => {
it('should unsubscribe if exists', () => {
component.configurationSubscription = <any>mock(Subscription);
component.configurationSubscription.unsubscribe = jest.fn();
component.unsubscribe();
expect(component.configurationSubscription.unsubscribe).toHaveBeenCalled();
});
it('should do nothing if not exists', () => {
component.apiRootSubscription = undefined;
const unsubscribeSpy: jest.SpyInstance = jest.spyOn(Subscription.prototype, 'unsubscribe');
component.unsubscribe();
expect(unsubscribeSpy).not.toHaveBeenCalled();
unsubscribeSpy.mockRestore();
});
});
});
});
@@ -190,21 +367,6 @@ describe('AppComponent', () => {
});
});
describe('administration logo', () => {
const apiResource: ApiRootResource = createApiRootResource();
beforeEach(() => {
component.apiRootStateResource$ = of(createStateResource(apiResource));
fixture.detectChanges();
});
it('should navigate to start page on click', () => {
dispatchEventFromFixture(fixture, logoLink, 'click');
expect(router.navigate).toHaveBeenCalledWith([], { queryParams: {} });
});
});
describe('navigation', () => {
describe('user and roles', () => {
it('should show if users link is present', () => {
Loading