Skip to content

Commit

Permalink
Merge pull request #1586 from DSD-DBS/fix-git-injectables
Browse files Browse the repository at this point in the history
fix: NullInjectionError in Git instance settings
  • Loading branch information
MoritzWeber0 authored May 27, 2024
2 parents 70ba158 + bb4251f commit f730af4
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
MatButton,
} from '@angular/material/button';
import { MatOption } from '@angular/material/core';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { MatDialog } from '@angular/material/dialog';
import { MatFormField, MatLabel, MatError } from '@angular/material/form-field';
import { MatIcon } from '@angular/material/icon';
import { MatInput } from '@angular/material/input';
Expand Down Expand Up @@ -61,7 +61,6 @@ import {
export class GitSettingsComponent implements OnInit {
constructor(
public dialog: MatDialog,
public dialogRef: MatDialogRef<DeleteGitSettingsDialogComponent>,
public gitInstancesService: GitInstancesService,
) {}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { AsyncValidatorFn, ValidationErrors } from '@angular/forms';
import { Meta, moduleMetadata, StoryObj } from '@storybook/angular';
import { Observable, of } from 'rxjs';
import {
GitInstance,
GitInstancesService,
} from 'src/app/settings/modelsources/git-settings/service/git-instances.service';
import { GitSettingsComponent } from './git-settings.component';

const meta: Meta<GitSettingsComponent> = {
title: 'Settings Components / Modelsources / Git Instances',
component: GitSettingsComponent,
};

export default meta;
type Story = StoryObj<GitSettingsComponent>;

class MockGitInstancesService implements Partial<GitInstancesService> {
public readonly gitInstances$: Observable<GitInstance[] | undefined> =
of(undefined);

constructor(gitInstances?: GitInstance[] | undefined) {
this.gitInstances$ = of(gitInstances);
}

asyncNameValidator(): AsyncValidatorFn {
return (): Observable<ValidationErrors | null> => {
return of(null);
};
}
}

export const General: Story = {
args: {},
decorators: [
moduleMetadata({
providers: [
{
provide: GitInstancesService,
useFactory: () =>
new MockGitInstancesService([
{
id: 1,
name: 'GitLab example',
url: 'https://gitlab.com',
apiURL: 'https://gitlab.com/api/v4',
type: 'gitlab',
},
{
id: 2,
name: 'GitHub example',
url: 'https://github.com',
apiURL: 'https://api.github.com',
type: 'github',
},
{
id: 3,
name: 'General example',
url: 'https://example.com',
type: 'general',
},
]),
},
],
}),
],
};

0 comments on commit f730af4

Please sign in to comment.