@@ -3,6 +3,7 @@ import { act, screen, waitFor, within } from '@testing-library/react';
33import userEvent from '@testing-library/user-event' ;
44import { describe , expect , it } from 'vitest' ;
55
6+ import { openDialog } from '../../__tests__/feature/dialog' ;
67import { type FakeFapiSeed , holdRequests , serveFapi } from '../../__tests__/feature/fake-fapi' ;
78import {
89 fapiClient ,
@@ -81,8 +82,7 @@ describe('OrganizationProfileGeneralPanel', () => {
8182 it ( 'updates only the changed name and shows the refreshed value' , async ( ) => {
8283 const { fapi } = await renderPanel ( ) ;
8384 const user = userEvent . setup ( ) ;
84- await user . click ( await screen . findByRole ( 'button' , { name : 'Edit name' } ) ) ;
85- const dialog = screen . getByRole ( 'dialog' ) ;
85+ const dialog = await openDialog ( user , await screen . findByRole ( 'button' , { name : 'Edit name' } ) ) ;
8686 await user . clear ( within ( dialog ) . getByRole ( 'textbox' , { name : 'Name' } ) ) ;
8787 await user . type ( within ( dialog ) . getByRole ( 'textbox' , { name : 'Name' } ) , 'Acme Inc' ) ;
8888 const update = holdRequests ( 'post' , '/v1/organizations/:organizationId' ) ;
@@ -100,8 +100,8 @@ describe('OrganizationProfileGeneralPanel', () => {
100100 const other = fapiOrganization ( { id : 'org_2' , name : 'Other' } ) ;
101101 const { clerk } = await renderPanel ( signedIn ( { organizations : [ acme , other ] } ) ) ;
102102 const user = userEvent . setup ( ) ;
103- await user . click ( await screen . findByRole ( 'button' , { name : 'Edit name' } ) ) ;
104- await user . type ( within ( screen . getByRole ( ' dialog' ) ) . getByRole ( 'textbox' , { name : 'Name' } ) , ' changed' ) ;
103+ const dialog = await openDialog ( user , await screen . findByRole ( 'button' , { name : 'Edit name' } ) ) ;
104+ await user . type ( within ( dialog ) . getByRole ( 'textbox' , { name : 'Name' } ) , ' changed' ) ;
105105 await act ( ( ) => clerk . setActive ( { organization : other . id } ) ) ;
106106 await waitFor ( ( ) => expect ( screen . queryByRole ( 'dialog' ) ) . toBeNull ( ) ) ;
107107 await user . click ( await screen . findByRole ( 'button' , { name : 'Edit name' } ) ) ;
@@ -111,8 +111,7 @@ describe('OrganizationProfileGeneralPanel', () => {
111111 it ( 'keeps a failed name draft and a field error, then resets after cancel' , async ( ) => {
112112 await renderPanel ( ) ;
113113 const user = userEvent . setup ( ) ;
114- await user . click ( await screen . findByRole ( 'button' , { name : 'Edit name' } ) ) ;
115- const dialog = screen . getByRole ( 'dialog' ) ;
114+ const dialog = await openDialog ( user , await screen . findByRole ( 'button' , { name : 'Edit name' } ) ) ;
116115 const field = within ( dialog ) . getByRole ( 'textbox' , { name : 'Name' } ) ;
117116 await user . clear ( field ) ;
118117 await user . type ( field , 'Rejected' ) ;
@@ -128,12 +127,12 @@ describe('OrganizationProfileGeneralPanel', () => {
128127 expect ( field ) . toHaveValue ( 'Rejected' ) ;
129128 await user . click ( within ( dialog ) . getByRole ( 'button' , { name : 'Cancel' } ) ) ;
130129 await waitFor ( ( ) => expect ( screen . queryByRole ( 'dialog' ) ) . toBeNull ( ) ) ;
131- await user . click ( screen . getByRole ( 'button' , { name : 'Edit name' } ) ) ;
132- expect ( within ( screen . getByRole ( 'dialog' ) ) . getByRole ( 'textbox' , { name : 'Name' } ) ) . toHaveValue ( 'Acme' ) ;
133- await user . clear ( within ( screen . getByRole ( 'dialog' ) ) . getByRole ( 'textbox' , { name : 'Name' } ) ) ;
134- await user . type ( within ( screen . getByRole ( 'dialog' ) ) . getByRole ( 'textbox' , { name : 'Name' } ) , 'Acme retry' ) ;
130+ const reopened = await openDialog ( user , screen . getByRole ( 'button' , { name : 'Edit name' } ) ) ;
131+ expect ( within ( reopened ) . getByRole ( 'textbox' , { name : 'Name' } ) ) . toHaveValue ( 'Acme' ) ;
132+ await user . clear ( within ( reopened ) . getByRole ( 'textbox' , { name : 'Name' } ) ) ;
133+ await user . type ( within ( reopened ) . getByRole ( 'textbox' , { name : 'Name' } ) , 'Acme retry' ) ;
135134 const retry = serveFapi ( signedIn ( ) ) ;
136- await user . click ( within ( screen . getByRole ( 'dialog' ) ) . getByRole ( 'button' , { name : 'Save changes' } ) ) ;
135+ await user . click ( within ( reopened ) . getByRole ( 'button' , { name : 'Save changes' } ) ) ;
137136 await waitFor ( ( ) => expect ( retry . memberships [ 0 ] ?. organization . name ) . toBe ( 'Acme retry' ) ) ;
138137 } ) ;
139138
@@ -155,8 +154,9 @@ describe('OrganizationProfileGeneralPanel', () => {
155154 it ( 'requires a nonblank changed name before saving' , async ( ) => {
156155 await renderPanel ( ) ;
157156 const user = userEvent . setup ( ) ;
158- await user . click ( await screen . findByRole ( 'button' , { name : 'Edit name' } ) ) ;
159- const dialog = screen . getByRole ( 'dialog' , { name : 'Edit name' } ) ;
157+ const dialog = await openDialog ( user , await screen . findByRole ( 'button' , { name : 'Edit name' } ) , {
158+ name : 'Edit name' ,
159+ } ) ;
160160 const field = within ( dialog ) . getByRole ( 'textbox' , { name : 'Name' } ) ;
161161 await user . clear ( field ) ;
162162 await user . type ( field , ' ' ) ;
@@ -166,8 +166,9 @@ describe('OrganizationProfileGeneralPanel', () => {
166166 it ( 'shows the generic fallback for an unknown name error' , async ( ) => {
167167 await renderPanel ( ) ;
168168 const user = userEvent . setup ( ) ;
169- await user . click ( await screen . findByRole ( 'button' , { name : 'Edit name' } ) ) ;
170- const dialog = screen . getByRole ( 'dialog' , { name : 'Edit name' } ) ;
169+ const dialog = await openDialog ( user , await screen . findByRole ( 'button' , { name : 'Edit name' } ) , {
170+ name : 'Edit name' ,
171+ } ) ;
171172 const field = within ( dialog ) . getByRole ( 'textbox' , { name : 'Name' } ) ;
172173 await user . type ( field , ' changed' ) ;
173174 const update = holdRequests ( 'post' , '/v1/organizations/:organizationId' ) ;
@@ -185,8 +186,7 @@ describe('OrganizationProfileGeneralPanel', () => {
185186 it ( 'clears the slug while preserving the current name' , async ( ) => {
186187 const { fapi } = await renderPanel ( ) ;
187188 const user = userEvent . setup ( ) ;
188- await user . click ( await screen . findByRole ( 'button' , { name : 'Edit slug' } ) ) ;
189- const dialog = screen . getByRole ( 'dialog' ) ;
189+ const dialog = await openDialog ( user , await screen . findByRole ( 'button' , { name : 'Edit slug' } ) ) ;
190190 await user . clear ( within ( dialog ) . getByRole ( 'textbox' , { name : 'Slug' } ) ) ;
191191 const update = holdRequests ( 'post' , '/v1/organizations/:organizationId' ) ;
192192 await user . click ( within ( dialog ) . getByRole ( 'button' , { name : 'Save changes' } ) ) ;
@@ -226,8 +226,9 @@ describe('OrganizationProfileGeneralPanel', () => {
226226 it ( 'shows a slug-specific FAPI error at the field and keeps the draft' , async ( ) => {
227227 await renderPanel ( ) ;
228228 const user = userEvent . setup ( ) ;
229- await user . click ( await screen . findByRole ( 'button' , { name : 'Edit slug' } ) ) ;
230- const dialog = screen . getByRole ( 'dialog' , { name : 'Edit slug' } ) ;
229+ const dialog = await openDialog ( user , await screen . findByRole ( 'button' , { name : 'Edit slug' } ) , {
230+ name : 'Edit slug' ,
231+ } ) ;
231232 const field = within ( dialog ) . getByRole ( 'textbox' , { name : 'Slug' } ) ;
232233 await user . type ( field , '-new' ) ;
233234 const update = holdRequests ( 'post' , '/v1/organizations/:organizationId' ) ;
@@ -249,8 +250,7 @@ describe('OrganizationProfileGeneralPanel', () => {
249250 </ MosaicProvider > ,
250251 ) ;
251252 const user = userEvent . setup ( ) ;
252- await user . click ( await screen . findByRole ( 'button' , { name : 'Edit slug' } ) ) ;
253- const dialog = screen . getByRole ( 'dialog' ) ;
253+ const dialog = await openDialog ( user , await screen . findByRole ( 'button' , { name : 'Edit slug' } ) ) ;
254254 const field = within ( dialog ) . getByRole ( 'textbox' , { name : 'Slug' } ) ;
255255 await user . clear ( field ) ;
256256 await user . type ( field , 'new-slug' ) ;
0 commit comments