@@ -8,7 +8,7 @@ import { FormManagerProvider } from '../store.js';
88import FormEdit from './index.js' ;
99import {
1010 createTestSession ,
11- createOnePageTwoPatternTestForm ,
11+ createOnePageThreePatternTestForm ,
1212 createTestFormManagerContext ,
1313} from '../../test-form.js' ;
1414
@@ -21,7 +21,7 @@ const meta: Meta<typeof FormEdit> = {
2121 < FormManagerProvider
2222 context = { createTestFormManagerContext ( ) }
2323 session = { createTestSession ( {
24- form : createOnePageTwoPatternTestForm ( ) ,
24+ form : createOnePageThreePatternTestForm ( ) ,
2525 route : {
2626 params : {
2727 page : '0' ,
@@ -49,6 +49,18 @@ export const FormEditTest: StoryObj<typeof FormEdit> = {
4949 } ,
5050} ;
5151
52+ export const FormEditUpdateSummary : StoryObj < typeof FormEdit > = {
53+ play : async ( { canvasElement } ) => {
54+ await editFormSummary (
55+ canvasElement ,
56+ 'New Form Title' ,
57+ 'Updated Form Title' ,
58+ 'This is an updated form description'
59+ ) ;
60+ } ,
61+ } ;
62+
63+
5264export const FormEditAddPattern : StoryObj < typeof FormEdit > = {
5365 play : async ( { canvasElement } ) => {
5466 const canvas = within ( canvasElement ) ;
@@ -76,26 +88,57 @@ export const FormEditAddPattern: StoryObj<typeof FormEdit> = {
7688const editFieldLabel = async (
7789 element : HTMLElement ,
7890 currentLabel : string ,
79- updatedLabel : string
91+ updatedLabel : string ,
92+ options ? : {
93+ inputLabelText ?: string ;
94+ description ?: string ;
95+ descriptionLabelText ?: string ;
96+ }
8097) => {
8198 const canvas = within ( element ) ;
99+ const inputLabelText = options ?. inputLabelText || 'Question text' ;
82100
83- // Give focus to the field matching `currentLabel`
84- await userEvent . click ( await canvas . findByLabelText ( currentLabel ) ) ;
101+ if ( options ?. description && options ?. descriptionLabelText ) {
102+ await userEvent . click ( await canvas . findByText ( currentLabel ) ) ;
85103
86- const input = canvas . getByLabelText ( 'Question text' ) ;
87- await userEvent . clear ( input ) ;
88- await userEvent . type ( input , updatedLabel ) ;
104+ const input = canvas . getByLabelText ( inputLabelText ) ;
105+ await userEvent . clear ( input ) ;
106+ await userEvent . type ( input , updatedLabel ) ;
107+
108+ const descriptionInput = canvas . getByLabelText ( options . descriptionLabelText ) ;
109+ await userEvent . clear ( descriptionInput ) ;
110+ await userEvent . type ( descriptionInput , options . description ) ;
111+ } else {
112+ // Give focus to the field matching `currentLabel`
113+ await userEvent . click ( await canvas . findByLabelText ( currentLabel ) ) ;
114+
115+ const input = canvas . getByLabelText ( inputLabelText ) ;
116+ await userEvent . clear ( input ) ;
117+ await userEvent . type ( input , updatedLabel ) ;
118+ }
89119
90120 await userEvent . click ( canvas . getByText ( / s a v e a n d c l o s e / i) ) ;
91121
92122 // Wait for the updated label to appear
93123 await waitFor ( ( ) => {
94- const newLabel = canvas . getByLabelText ( updatedLabel ) ;
124+ const newLabel = options ?. description ? canvas . getByText ( updatedLabel ) : canvas . getByLabelText ( updatedLabel ) ;
95125 expect ( newLabel ) . toBeInTheDocument ( ) ;
96126 } ) ;
97127} ;
98128
129+ const editFormSummary = (
130+ element : HTMLElement ,
131+ currentTitle : string ,
132+ updatedTitle : string ,
133+ updatedDescription : string
134+ ) => {
135+ return editFieldLabel ( element , currentTitle , updatedTitle , {
136+ inputLabelText : 'Title' ,
137+ description : updatedDescription ,
138+ descriptionLabelText : 'Description'
139+ } )
140+ }
141+
99142export const FormEditReorderPattern : StoryObj < typeof FormEdit > = {
100143 play : async ( { canvasElement } ) => {
101144 const canvas = within ( canvasElement ) ;
@@ -109,7 +152,7 @@ export const FormEditReorderPattern: StoryObj<typeof FormEdit> = {
109152 return buttons ;
110153 } ) ;
111154
112- const grabber = handle [ 1 ] ;
155+ const grabber = handle [ 2 ] ;
113156
114157 // Enter reordering mode with the spacebar
115158 await userEvent . type ( grabber , ' ' ) ;
@@ -123,7 +166,7 @@ export const FormEditReorderPattern: StoryObj<typeof FormEdit> = {
123166 // Wait for the DOM to update and verify the new order
124167 await waitFor ( ( ) => {
125168 const pattern1 = canvas . getByText ( 'Pattern 1' ) ;
126- const pattern2 = canvas . getByText ( 'Pattern 2 ' ) ;
169+ const pattern2 = canvas . getByText ( 'New Form Title ' ) ;
127170 expect ( pattern2 . compareDocumentPosition ( pattern1 ) ) . toBe (
128171 Node . DOCUMENT_POSITION_FOLLOWING
129172 ) ;
0 commit comments