diff --git a/frontend/src/app/general/auth/auth/auth.stories.ts b/frontend/src/app/general/auth/auth/auth.stories.ts index c4df0abc5..c160a2739 100644 --- a/frontend/src/app/general/auth/auth/auth.stories.ts +++ b/frontend/src/app/general/auth/auth/auth.stories.ts @@ -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; diff --git a/frontend/src/app/general/metadata/version/version.stories.ts b/frontend/src/app/general/metadata/version/version.stories.ts index 70bece2aa..e021bc28f 100644 --- a/frontend/src/app/general/metadata/version/version.stories.ts +++ b/frontend/src/app/general/metadata/version/version.stories.ts @@ -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', @@ -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', @@ -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), }, ], }), @@ -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), }, ], }), @@ -96,7 +63,7 @@ export const FirstTimeAccessed: Story = { { provide: MetadataService, useFactory: () => - new MockMetadataService(metadata, version, undefined, true), + new MockMetadataService(mockMetadata, version, undefined, true), }, ], }), diff --git a/frontend/src/storybook/metadata.ts b/frontend/src/storybook/metadata.ts new file mode 100644 index 000000000..37eb725b5 --- /dev/null +++ b/frontend/src/storybook/metadata.ts @@ -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; + } +}