From eea26023c5bcd2c0c42e4d5c9bac24cf3d91c23c Mon Sep 17 00:00:00 2001 From: Marcin Siodelski Date: Wed, 22 Nov 2023 10:27:29 +0100 Subject: [PATCH] [#1210] Settings story inits form values --- .../settings-page.component.stories.ts | 40 +++++++++++++++++-- .../settings-page/settings-page.component.ts | 4 +- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/webui/src/app/settings-page/settings-page.component.stories.ts b/webui/src/app/settings-page/settings-page.component.stories.ts index 0caec07ac..5c90173b1 100644 --- a/webui/src/app/settings-page/settings-page.component.stories.ts +++ b/webui/src/app/settings-page/settings-page.component.stories.ts @@ -2,7 +2,6 @@ import { moduleMetadata, Meta, Story, applicationConfig } from '@storybook/angul import { SettingsPageComponent } from './settings-page.component' import { importProvidersFrom } from '@angular/core' import { provideAnimations, provideNoopAnimations } from '@angular/platform-browser/animations' -import { HttpClientTestingModule } from '@angular/common/http/testing' import { BreadcrumbModule } from 'primeng/breadcrumb' import { FieldsetModule } from 'primeng/fieldset' import { FormsModule, ReactiveFormsModule } from '@angular/forms' @@ -14,6 +13,21 @@ import { HelpTipComponent } from '../help-tip/help-tip.component' import { MessageService } from 'primeng/api' import { ButtonModule } from 'primeng/button' import { DividerModule } from 'primeng/divider' +import { Settings } from '../backend/model/settings' +import { HttpClientModule } from '@angular/common/http' +import { toastDecorator } from '../utils-stories' +import { ToastModule } from 'primeng/toast' + +let mockGetSettingsResponse: Settings = { + bind9StatsPullerInterval: 10, + grafanaUrl: 'http://grafana.org', + keaHostsPullerInterval: 12, + keaStatsPullerInterval: 15, + keaStatusPullerInterval: 23, + appsStatePullerInterval: 44, + prometheusUrl: 'http://prometheus.org', + metricsCollectorInterval: 11, +} export default { title: 'App/SettingsPage', @@ -22,7 +36,7 @@ export default { applicationConfig({ providers: [ MessageService, - importProvidersFrom(HttpClientTestingModule), + importProvidersFrom(HttpClientModule), provideNoopAnimations(), provideAnimations(), ], @@ -38,14 +52,34 @@ export default { OverlayPanelModule, ReactiveFormsModule, RouterTestingModule, + ToastModule, ], declarations: [BreadcrumbsComponent, HelpTipComponent, SettingsPageComponent], }), + toastDecorator, ], + parameters: { + mockData: [ + { + url: 'http://localhost/api/settings', + method: 'GET', + status: 200, + delay: 0, + response: mockGetSettingsResponse, + }, + { + url: 'http://localhost/api/settings', + method: 'PUT', + status: 200, + delay: 0, + response: {}, + }, + ], + }, } as Meta const Template: Story = (args: SettingsPageComponent) => ({ props: args, }) -export const Settings = Template.bind({}) +export const SettingsForm = Template.bind({}) diff --git a/webui/src/app/settings-page/settings-page.component.ts b/webui/src/app/settings-page/settings-page.component.ts index 192e88961..4f13bc213 100644 --- a/webui/src/app/settings-page/settings-page.component.ts +++ b/webui/src/app/settings-page/settings-page.component.ts @@ -175,8 +175,8 @@ export class SettingsPageComponent implements OnInit { const msg = getErrorMessage(err) this.msgSrv.add({ severity: 'error', - summary: 'Cannot get settings', - detail: 'Error getting settings: ' + msg, + summary: 'Cannot save settings', + detail: 'Error saving settings: ' + msg, life: 10000, }) }