Skip to content

Commit

Permalink
Merge pull request #547 from UKHSA-Internal/chore/update-feedback-schema
Browse files Browse the repository at this point in the history
Updating postSuggestions tests inline with schema
  • Loading branch information
rhys-burendo authored Nov 15, 2024
2 parents afbf062 + ac8b257 commit f3ff496
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 89 deletions.
14 changes: 7 additions & 7 deletions src/api/requests/suggestions/postSuggestions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ test('Handles successful submission from the api', async () => {
postSuggestion.mockResolvedValueOnce({ status: 200, data: {} })

const { success } = await postSuggestions({
improve_experience: '',
did_you_find_everything: 'yes',
reason: '',
like_to_see: '',
what_was_your_reason_for_visiting_the_dashboard_today: '',
did_you_find_everything_you_were_looking_for: 'yes',
how_could_we_improve_your_experience_with_the_dashboard: '',
what_would_you_like_to_see_on_the_dashboard_in_the_future: '',
})

expect(success).toBeTruthy()
Expand All @@ -21,9 +21,9 @@ test('Handles non 200 response from the api', async () => {
postSuggestion.mockResolvedValueOnce({ status: 500, data: {} })

const { success } = await postSuggestions({
improve_experience: '',
reason: '',
like_to_see: '',
how_could_we_improve_your_experience_with_the_dashboard: '',
what_was_your_reason_for_visiting_the_dashboard_today: '',
what_would_you_like_to_see_on_the_dashboard_in_the_future: '',
})

expect(success).toBeFalsy()
Expand Down
3 changes: 2 additions & 1 deletion src/api/requests/suggestions/postSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ export type RequestParams = z.infer<typeof requestSchema>

export const postSuggestions = async (suggestions: RequestParams) => {
try {
const { status } = await client<Response>('suggestions/v1', {
const { status } = await client<Response>('suggestions/v2', {
body: suggestions,
baseUrl: getFeedbackApiBaseUrl(),
})

if (status !== 200) {
throw new Error('Failed to submit, invalid status code')
}
Expand Down
25 changes: 4 additions & 21 deletions src/app/(pages)/feedback/confirmation/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { PageType } from '@/api/requests/cms/getPages'
import { getPageBySlug } from '@/api/requests/getPageBySlug'
import { RichText } from '@/app/components/cms'
import { View } from '@/app/components/ui/ukhsa'
import { flags } from '@/app/constants/flags.constants'
import { getFeatureFlag } from '@/app/utils/flags.utils'

export const metadata: Metadata = {
title: 'Feedback Confirmation | UKHSA data dashboard',
Expand All @@ -19,31 +17,16 @@ export default async function FeedbackConfirmation() {
confirmation_body: body,
} = await getPageBySlug<PageType.Feedback>('feedback')

const { enabled } = await getFeatureFlag(flags.feedbackForm)

return (
<View>
<div className="govuk-grid-row">
<div className="govuk-grid-column-two-thirds">
<div className="govuk-panel govuk-panel--confirmation govuk-!-margin-bottom-6">
<h1 className="govuk-panel__title">{enabled ? panelTitle : 'Form submitted'}</h1>
<div className="govuk-panel__body">{enabled ? panelText : 'Thank you for your feedback'}</div>
<h1 className="govuk-panel__title">{panelTitle}</h1>
<div className="govuk-panel__body">{panelText}</div>
</div>
{enabled ? (
<RichText>{body}</RichText>
) : (
<>
<p>
Thank you for giving feedback on the UKHSA data dashboard. We will use your comments to help us
continually improve the service. We will not be able to get in touch with you about your comments.
</p>
<p data-block-key="2ao03">
The feedback form is intended for feedback on your experience using the dashboard. If you need to get in
touch with UK Health Security Agency, you can find contact information at the bottom of the{' '}
<a href="https://www.gov.uk/government/organisations/uk-health-security-agency">UKHSA webpage</a>
</p>
</>
)}

<RichText>{body}</RichText>

<Link href="/" className="govuk-link--no-visited-state govuk-!-margin-top-2 govuk-body inline-block">
Return to home page
Expand Down
43 changes: 1 addition & 42 deletions src/app/(pages)/switchboard/(pages)/feature-flags/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ export default function SwitchBoard() {
const cookieStore = cookies()

const {
flags: {
'landing-page-hero': landingPageHero,
'interactive-charts': interactiveCharts,
'feedback-form': feedbackForm,
},
flags: { 'landing-page-hero': landingPageHero, 'interactive-charts': interactiveCharts },
} = getSwitchBoardState(cookieStore.get(UKHSA_SWITCHBOARD_COOKIE_NAME)?.value)

return (
Expand All @@ -28,7 +24,6 @@ export default function SwitchBoard() {
{
'landing-page-hero': form.get('flags.landingPageHero') as string,
'interactive-charts': form.get('flags.interactiveCharts') as string,
'feedback-form': form.get('flags.feedbackForm') as string,
}
)
}}
Expand Down Expand Up @@ -109,42 +104,6 @@ export default function SwitchBoard() {
</label>
</div>
</div>

<div
className="govuk-radios govuk-radios--inline govuk-radios--small govuk-!-margin-top-4"
data-module="govuk-radios"
>
<label className="govuk-label w-full" htmlFor="flags.feedbackForm.Enabled">
Feedback form
</label>
<div className="govuk-radios__item">
<input
defaultChecked={feedbackForm === 'enabled'}
className="govuk-radios__input"
id="flags.feedbackForm.Enabled"
name="flags.feedbackForm"
type="radio"
value="enabled"
/>
<label className="govuk-label govuk-radios__label" htmlFor="flags.feedbackForm.Enabled">
Enabled
</label>
</div>

<div className="govuk-radios__item">
<input
defaultChecked={feedbackForm === 'disabled'}
className="govuk-radios__input"
id="flags.feedbackForm.Disabled"
name="flags.feedbackForm"
type="radio"
value="disabled"
/>
<label className="govuk-label govuk-radios__label" htmlFor="flags.feedbackForm.Disabled">
Disabled
</label>
</div>
</div>
</fieldset>
<button type="submit" className="govuk-button">
Save changes
Expand Down
22 changes: 11 additions & 11 deletions src/app/components/cms/utils/handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ test('Redirect to confirmation page when valid suggestions are provided', async
})

const formData = new FormData()
formData.set('improve_experience', 'quality!')
formData.set('did_you_find_everything', 'yes')
formData.set('reason', 'testing')
formData.set('like_to_see', 'nothing')
formData.set('how_could_we_improve_your_experience_with_the_dashboard', 'quality!')
formData.set('did_you_find_everything_you_were_looking_for', 'yes')
formData.set('what_was_your_reason_for_visiting_the_dashboard_today', 'testing')
formData.set('what_would_you_like_to_see_on_the_dashboard_in_the_future', 'nothing')

await handler({ message: '', errors: {} }, formData)

Expand All @@ -31,9 +31,9 @@ test('Redirect to confirmation page when valid suggestions are provided', async

test('Redirect to confirmation page when no suggestions are provided (form is non-mandatory)', async () => {
const formData = new FormData()
formData.set('improve_experience', '')
formData.set('reason', '')
formData.set('like_to_see', '')
formData.set('how_could_we_improve_your_experience_with_the_dashboard', '')
formData.set('what_was_your_reason_for_visiting_the_dashboard_today', '')
formData.set('what_would_you_like_to_see_on_the_dashboard_in_the_future', '')

await handler({ message: '', errors: {} }, formData)

Expand All @@ -50,10 +50,10 @@ test('Redirect to error page when an error with the backend API occurs', async (
})

const formData = new FormData()
formData.set('improve_experience', '')
formData.set('did_you_find_everything', 'no')
formData.set('reason', '')
formData.set('like_to_see', '')
formData.set('how_could_we_improve_your_experience_with_the_dashboard', '')
formData.set('did_you_find_everything_you_were_looking_for', 'no')
formData.set('what_was_your_reason_for_visiting_the_dashboard_today', '')
formData.set('what_would_you_like_to_see_on_the_dashboard_in_the_future', '')

const res = await handler({ message: '', errors: {} }, formData)

Expand Down
1 change: 0 additions & 1 deletion src/app/constants/flags.constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export const flags = {
landingPageHero: 'landing-page-hero',
interactiveCharts: 'interactive-charts',
feedbackForm: 'feedback-form',
}
File renamed without changes.
4 changes: 2 additions & 2 deletions src/mock-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import geographies from './handlers/geographies/v2/[topic]'
import globalBanners from './handlers/global-banners/v1'
import headlines from './handlers/headlines/v3'
import menus from './handlers/menus/v1'
import suggestions from './handlers/suggestions/v1'
import suggestions from './handlers/suggestions/v2'
import tables from './handlers/tables/v4'
import trends from './handlers/trends/v3'

Expand Down Expand Up @@ -65,7 +65,7 @@ app.post('/api/tables/v4', tables)
app.post('/api/downloads/v2', downloads)

// Misc endpoints
app.post('/api/suggestions/v1', suggestions)
app.post('/api/suggestions/v2', suggestions)
app.get('/flags/client/features', flags)

app.listen(3005, () => {
Expand Down
8 changes: 4 additions & 4 deletions src/schemas/feedback.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import * as z from 'zod'

export const feedbackSchema = z
.object({
reason: z.string().optional().nullable(),
did_you_find_everything: z.enum(['yes', 'no']).or(z.undefined()),
improve_experience: z.string().optional().nullable(),
like_to_see: z.string().optional().nullable(),
what_was_your_reason_for_visiting_the_dashboard_today: z.string().optional().nullable(),
did_you_find_everything_you_were_looking_for: z.enum(['yes', 'no']).or(z.undefined()),
how_could_we_improve_your_experience_with_the_dashboard: z.string().optional().nullable(),
what_would_you_like_to_see_on_the_dashboard_in_the_future: z.string().optional().nullable(),
})
.required()

1 comment on commit f3ff496

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit tests coverage

Lines Statements Branches Functions
Coverage: 93%
91.97% (1766/1920) 82.02% (406/495) 89.31% (259/290)
Tests Skipped Failures Errors Time
470 0 💤 0 ❌ 0 🔥 15.941s ⏱️

Please sign in to comment.