Skip to content

Commit

Permalink
Merge pull request #1813 from DSD-DBS/add-identity-provider-to-story
Browse files Browse the repository at this point in the history
test: Add authentication provider to Auth component stories
  • Loading branch information
MoritzWeber0 authored Sep 18, 2024
2 parents b84d58d + 17b969a commit c2c8169
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 37 deletions.
18 changes: 18 additions & 0 deletions frontend/src/app/general/auth/auth/auth.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,29 @@
import { ActivatedRoute, convertToParamMap, Params } from '@angular/router';
import { Meta, moduleMetadata, StoryObj } from '@storybook/angular';
import { BehaviorSubject } from 'rxjs';
import { MetadataService } from 'src/app/general/metadata/metadata.service';
import { mockMetadata, MockMetadataService } from 'src/storybook/metadata';
import { AuthComponent } from './auth.component';

const meta: Meta<AuthComponent> = {
title: 'General Components/Authentication',
component: AuthComponent,
decorators: [
moduleMetadata({
providers: [
{
provide: MetadataService,
useFactory: () =>
new MockMetadataService(
mockMetadata,
undefined,
undefined,
undefined,
),
},
],
}),
],
};

export default meta;
Expand Down
41 changes: 4 additions & 37 deletions frontend/src/app/general/metadata/version/version.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { Meta, StoryObj, moduleMetadata } from '@storybook/angular';
import { Observable, of } from 'rxjs';
import {
MetadataService,
Version,
} from 'src/app/general/metadata/metadata.service';
import { VersionComponent } from 'src/app/general/metadata/version/version.component';
import { Metadata } from 'src/app/openapi';
import { mockMetadata, MockMetadataService } from 'src/storybook/metadata';

const meta: Meta<VersionComponent> = {
title: 'General Components/Version',
Expand All @@ -19,38 +18,6 @@ const meta: Meta<VersionComponent> = {
export default meta;
type Story = StoryObj<VersionComponent>;

class MockMetadataService implements Partial<MetadataService> {
public readonly backendMetadata: Observable<Metadata | undefined> =
of(undefined);
public version: Version | undefined;
public oldVersion: string | undefined;
public changedVersion = false;

constructor(
metadata: Metadata | undefined,
version: Version | undefined,
oldVersion: string | undefined,
changedVersion: boolean,
) {
this.backendMetadata = of(metadata);
this.version = version;
this.oldVersion = oldVersion;
this.changedVersion = changedVersion;
}
}

const metadata: Metadata = {
version: '1.0.0',
privacy_policy_url: 'https://example.com/privacy',
imprint_url: 'https://example.com/imprint',
provider: 'Provider',
authentication_provider: 'Authentication provider',
environment: 'Storybook Environment',
host: 'localhost',
port: '6006',
protocol: 'http',
};

const version: Version = {
git: {
version: '1.0.0',
Expand All @@ -66,7 +33,7 @@ export const VersionUnchanged: Story = {
{
provide: MetadataService,
useFactory: () =>
new MockMetadataService(metadata, version, 'v1.0.0', false),
new MockMetadataService(mockMetadata, version, 'v1.0.0', false),
},
],
}),
Expand All @@ -81,7 +48,7 @@ export const NewVersionAvailable: Story = {
{
provide: MetadataService,
useFactory: () =>
new MockMetadataService(metadata, version, 'v0.1.0', true),
new MockMetadataService(mockMetadata, version, 'v0.1.0', true),
},
],
}),
Expand All @@ -96,7 +63,7 @@ export const FirstTimeAccessed: Story = {
{
provide: MetadataService,
useFactory: () =>
new MockMetadataService(metadata, version, undefined, true),
new MockMetadataService(mockMetadata, version, undefined, true),
},
],
}),
Expand Down
42 changes: 42 additions & 0 deletions frontend/src/storybook/metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors
* SPDX-License-Identifier: Apache-2.0
*/
import { Observable, of } from 'rxjs';
import {
MetadataService,
Version,
} from 'src/app/general/metadata/metadata.service';
import { Metadata } from 'src/app/openapi';

export const mockMetadata: Metadata = {
version: '1.0.0',
privacy_policy_url: 'https://example.com/privacy',
imprint_url: 'https://example.com/imprint',
provider: 'Provider',
authentication_provider: 'Identity Provider',
environment: 'Storybook Environment',
host: 'localhost',
port: '6006',
protocol: 'http',
};

export class MockMetadataService implements Partial<MetadataService> {
public readonly backendMetadata: Observable<Metadata | undefined> =
of(undefined);
public version: Version | undefined;
public oldVersion: string | undefined;
public changedVersion = false;

constructor(
metadata: Metadata | undefined,
version?: Version | undefined,
oldVersion?: string | undefined,
changedVersion?: boolean,
) {
this.backendMetadata = of(metadata);
this.version = version;
this.oldVersion = oldVersion;
if (changedVersion) this.changedVersion = changedVersion;
}
}

0 comments on commit c2c8169

Please sign in to comment.