Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add authentication provider to Auth component stories #1813

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading