@@ -155,22 +155,67 @@ it("names exact relay claim refusals and keeps other failures generic", async ()
155155 }
156156} ) ;
157157
158- it ( "keeps a community upload out of first-join local defaults without changing the published profile" , async ( ) => {
158+ it . each ( [
159+ "https://relay.example/media/avatar.png" ,
160+ "https://RELAY.example:443/media/avatar.png" ,
161+ ] ) (
162+ "keeps %s out of first-join local defaults without changing the published profile" ,
163+ async ( picture ) => {
164+ api . inspectProfile . mockResolvedValueOnce ( {
165+ exists : true ,
166+ existing : { name : "Fixture" } ,
167+ profile : {
168+ name : "Fixture" ,
169+ picture,
170+ about : "" ,
171+ } ,
172+ } ) ;
173+ vi . stubGlobal (
174+ "fetch" ,
175+ vi . fn ( async ( url : string ) => {
176+ const route = String ( url ) . split ( "/" ) . at ( - 1 ) ;
177+ if ( route === "register" ) return Response . json ( { id : "x" } ) ;
178+ if ( route === "info" ) return Response . json ( { name : "Fixture" } ) ;
179+ throw new Error ( `Unexpected request: ${ url } ` ) ;
180+ } ) ,
181+ ) ;
182+ const communities = {
183+ snapshot : ( ) => ( { status : "ready" , profile : { name : "" , picture : "" } } ) ,
184+ joined : vi . fn ( ) ,
185+ } as unknown as Communities ;
186+ render (
187+ < CommunityDialog
188+ communities = { communities }
189+ mode = "join"
190+ close = { ( ) => { } }
191+ /> ,
192+ ) ;
193+ const user = userEvent . setup ( ) ;
194+ await user . type ( screen . getByLabelText ( "Relay URL" ) , "wss://relay.example" ) ;
195+ await user . click ( screen . getByRole ( "button" , { name : "Continue" } ) ) ;
196+ await user . click (
197+ await screen . findByRole ( "button" , { name : "Open community" } ) ,
198+ ) ;
199+ expect ( api . publishProfile ) . not . toHaveBeenCalled ( ) ;
200+ expect ( communities . joined ) . toHaveBeenCalledWith (
201+ expect . objectContaining ( { id : "https://relay.example" } ) ,
202+ { name : "Fixture" , picture : "" , about : "" } ,
203+ ) ;
204+ } ,
205+ ) ;
206+
207+ it ( "explains an inherited invalid avatar when editing at join and recovers on replacement" , async ( ) => {
208+ const picture = "http://images.example/avatar.png" ;
159209 api . inspectProfile . mockResolvedValueOnce ( {
160210 exists : true ,
161- existing : { name : "Fixture" } ,
162- profile : {
163- name : "Fixture" ,
164- picture : "https://relay.example/media/avatar.png" ,
165- about : "" ,
166- } ,
211+ existing : { name : "Fixture" , picture } ,
212+ profile : { name : "Fixture" , picture, about : "" } ,
167213 } ) ;
168214 vi . stubGlobal (
169215 "fetch" ,
170216 vi . fn ( async ( url : string ) => {
171- const route = String ( url ) . split ( "/" ) . at ( - 1 ) ;
172- if ( route === "register" ) return Response . json ( { id : "x" } ) ;
173- if ( route === "info" ) return Response . json ( { name : "Fixture" } ) ;
217+ if ( url . endsWith ( "/register" ) ) return Response . json ( { id : "x" } ) ;
218+ if ( url . endsWith ( "/info" ) ) return Response . json ( { name : "Fixture" } ) ;
174219 throw new Error ( `Unexpected request: ${ url } ` ) ;
175220 } ) ,
176221 ) ;
@@ -184,12 +229,28 @@ it("keeps a community upload out of first-join local defaults without changing t
184229 const user = userEvent . setup ( ) ;
185230 await user . type ( screen . getByLabelText ( "Relay URL" ) , "wss://relay.example" ) ;
186231 await user . click ( screen . getByRole ( "button" , { name : "Continue" } ) ) ;
232+ await user . type ( await screen . findByLabelText ( "Display name" ) , " changed" ) ;
233+ expect (
234+ screen . getByRole ( "button" , { name : "Publish profile & open" } ) ,
235+ ) . toBeDisabled ( ) ;
236+ expect ( screen . getByRole ( "alert" ) ) . toHaveTextContent ( "Use an HTTPS image URL" ) ;
237+ await user . click ( screen . getByRole ( "button" , { name : "Edit avatar" } ) ) ;
238+ const input = await screen . findByLabelText ( "Picture URL (optional)" ) ;
239+ expect ( input ) . toHaveAccessibleDescription ( / U s e a n H T T P S i m a g e U R L / ) ;
240+ await user . clear ( input ) ;
241+ await user . type ( input , "https://images.example/new.png" ) ;
242+ await user . click ( screen . getByRole ( "button" , { name : "Done" } ) ) ;
243+ expect ( screen . queryByRole ( "alert" ) ) . not . toBeInTheDocument ( ) ;
187244 await user . click (
188- await screen . findByRole ( "button" , { name : "Open community " } ) ,
245+ screen . getByRole ( "button" , { name : "Publish profile & open " } ) ,
189246 ) ;
190- expect ( api . publishProfile ) . not . toHaveBeenCalled ( ) ;
191- expect ( communities . joined ) . toHaveBeenCalledWith (
192- expect . objectContaining ( { id : "https://relay.example" } ) ,
193- { name : "Fixture" , picture : "" , about : "" } ,
247+ expect ( api . publishProfile ) . toHaveBeenCalledWith (
248+ "https://relay.example" ,
249+ {
250+ name : "Fixture changed" ,
251+ picture : "https://images.example/new.png" ,
252+ about : "" ,
253+ } ,
254+ { name : "Fixture" , picture } ,
194255 ) ;
195256} ) ;
0 commit comments