@@ -85,4 +85,48 @@ describe("Registration", () => {
8585 cy . get ( ".mx_DevicesPanel_myDevice .mx_DevicesPanel_deviceTrust .mx_E2EIcon" )
8686 . should ( "have.class" , "mx_E2EIcon_verified" ) ;
8787 } ) ;
88+
89+ it ( "should require username to fulfil requirements and be available" , ( ) => {
90+ cy . get ( ".mx_ServerPicker_change" , { timeout : 15000 } ) . click ( ) ;
91+ cy . get ( ".mx_ServerPickerDialog_continue" ) . should ( "be.visible" ) ;
92+ cy . get ( ".mx_ServerPickerDialog_otherHomeserver" ) . type ( synapse . baseUrl ) ;
93+ cy . get ( ".mx_ServerPickerDialog_continue" ) . click ( ) ;
94+ // wait for the dialog to go away
95+ cy . get ( '.mx_ServerPickerDialog' ) . should ( 'not.exist' ) ;
96+
97+ cy . get ( "#mx_RegistrationForm_username" ) . should ( "be.visible" ) ;
98+
99+ cy . intercept ( "**/_matrix/client/*/register/available?username=_alice" , {
100+ statusCode : 400 ,
101+ headers : {
102+ "Content-Type" : "application/json" ,
103+ } ,
104+ body : {
105+ errcode : "M_INVALID_USERNAME" ,
106+ error : "User ID may not begin with _" ,
107+ } ,
108+ } ) ;
109+ cy . get ( "#mx_RegistrationForm_username" ) . type ( "_alice" ) ;
110+ cy . get ( ".mx_Field_tooltip" )
111+ . should ( "have.class" , "mx_Tooltip_visible" )
112+ . should ( "contain.text" , "Some characters not allowed" ) ;
113+
114+ cy . intercept ( "**/_matrix/client/*/register/available?username=bob" , {
115+ statusCode : 400 ,
116+ headers : {
117+ "Content-Type" : "application/json" ,
118+ } ,
119+ body : {
120+ errcode : "M_USER_IN_USE" ,
121+ error : "The desired username is already taken" ,
122+ } ,
123+ } ) ;
124+ cy . get ( "#mx_RegistrationForm_username" ) . type ( "{selectAll}{backspace}bob" ) ;
125+ cy . get ( ".mx_Field_tooltip" )
126+ . should ( "have.class" , "mx_Tooltip_visible" )
127+ . should ( "contain.text" , "Someone already has that username" ) ;
128+
129+ cy . get ( "#mx_RegistrationForm_username" ) . type ( "{selectAll}{backspace}foobar" ) ;
130+ cy . get ( ".mx_Field_tooltip" ) . should ( "not.have.class" , "mx_Tooltip_visible" ) ;
131+ } ) ;
88132} ) ;
0 commit comments