Skip to content

Commit

Permalink
[#1210] Settings story inits form values
Browse files Browse the repository at this point in the history
  • Loading branch information
msiodelski committed Nov 24, 2023
1 parent 3b12fb4 commit eea2602
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
40 changes: 37 additions & 3 deletions webui/src/app/settings-page/settings-page.component.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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',
Expand All @@ -22,7 +36,7 @@ export default {
applicationConfig({
providers: [
MessageService,
importProvidersFrom(HttpClientTestingModule),
importProvidersFrom(HttpClientModule),
provideNoopAnimations(),
provideAnimations(),
],
Expand All @@ -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<SettingsPageComponent> = (args: SettingsPageComponent) => ({
props: args,
})

export const Settings = Template.bind({})
export const SettingsForm = Template.bind({})
4 changes: 2 additions & 2 deletions webui/src/app/settings-page/settings-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
Expand Down

0 comments on commit eea2602

Please sign in to comment.