2022-07-04 10:00:27 +01:00
//
2022-08-11 08:54:24 +01:00
// C o p y r i g h t 2 0 2 2 N e w V e c t o r L t d
2022-07-04 10:00:27 +01:00
//
// L i c e n s e d u n d e r t h e A p a c h e L i c e n s e , V e r s i o n 2 . 0 ( t h e " L i c e n s e " ) ;
// y o u m a y n o t u s e t h i s f i l e e x c e p t i n c o m p l i a n c e w i t h t h e L i c e n s e .
// Y o u m a y o b t a i n a c o p y o f t h e L i c e n s e a t
//
// h t t p : / / w w w . a p a c h e . o r g / l i c e n s e s / L I C E N S E - 2 . 0
//
// U n l e s s r e q u i r e d b y a p p l i c a b l e l a w o r a g r e e d t o i n w r i t i n g , s o f t w a r e
// d i s t r i b u t e d u n d e r t h e L i c e n s e i s d i s t r i b u t e d o n a n " A S I S " B A S I S ,
// W I T H O U T W A R R A N T I E S O R C O N D I T I O N S O F A N Y K I N D , e i t h e r e x p r e s s o r i m p l i e d .
// S e e t h e L i c e n s e f o r t h e s p e c i f i c l a n g u a g e g o v e r n i n g p e r m i s s i o n s a n d
// l i m i t a t i o n s u n d e r t h e L i c e n s e .
//
import ElementX
2022-07-06 14:49:05 +01:00
import XCTest
2022-07-04 10:00:27 +01:00
@ MainActor
class ServerSelectionUITests : XCTestCase {
let textFieldIdentifier = " addressTextField "
func testNormalState ( ) async {
// G i v e n t h e i n i t i a l s e r v e r s e l e c t i o n s c r e e n a s a m o d a l .
2023-02-14 16:25:24 +00:00
let app = Application . launch ( . serverSelection )
2022-07-04 10:00:27 +01:00
2023-02-08 14:11:09 +00:00
// T h e n i t s h o u l d b e c o n f i g u r e d f o r m a t r i x . o r g
app . assertScreenshot ( . serverSelection , step : 0 )
XCTAssertEqual ( app . textFields [ textFieldIdentifier ] . value as ? String , " matrix.org " , " The server shown should be matrix.org with the https scheme hidden. " )
XCTAssertEqual ( app . buttons [ " confirmButton " ] . label , ElementL10n . continue , " The confirm button should say Confirm when in modal presentation. " )
2022-07-04 10:00:27 +01:00
}
func testEmptyAddress ( ) async {
// G i v e n t h e i n i t i a l s e r v e r s e l e c t i o n s c r e e n a s a m o d a l .
2023-02-14 16:25:24 +00:00
let app = Application . launch ( . serverSelection )
2022-07-04 10:00:27 +01:00
// W h e n c l e a r i n g t h e s e r v e r a d d r e s s t e x t f i e l d .
2022-11-24 10:35:00 +02:00
app . textFields [ textFieldIdentifier ] . tap ( )
app . textFields [ textFieldIdentifier ] . buttons . element . tap ( )
2022-07-04 10:00:27 +01:00
// T h e n t h e s c r e e n s h o u l d n o t a l l o w t h e u s e r t o c o n t i n u e .
2023-02-08 14:11:09 +00:00
app . assertScreenshot ( . serverSelection , step : 1 )
2022-11-24 10:35:00 +02:00
XCTAssertEqual ( app . textFields [ textFieldIdentifier ] . value as ? String , ElementL10n . ftueAuthChooseServerEntryHint , " The text field should show placeholder text in this state. " )
2023-02-08 14:11:09 +00:00
XCTAssertFalse ( app . buttons [ " confirmButton " ] . isEnabled , " The confirm button should be disabled when the address is empty. " )
2022-07-04 10:00:27 +01:00
}
func testInvalidAddress ( ) {
// G i v e n t h e i n i t i a l s e r v e r s e l e c t i o n s c r e e n a s a m o d a l .
2023-02-14 16:25:24 +00:00
let app = Application . launch ( . serverSelection )
2022-07-04 10:00:27 +01:00
// W h e n t y p i n g i n a n i n v a l i d h o m e s e r v e r
2022-12-15 15:22:39 +02:00
app . textFields [ textFieldIdentifier ] . clearAndTypeText ( " thisisbad \n " ) // T h e t e s t s o n l y a c c e p t a n a d d r e s s f r o m L o g i n H o m e s e r v e r . m o c k X Y Z
2022-07-04 10:00:27 +01:00
// T h e n a n e r r o r s h o u l d b e s h o w n a n d t h e c o n f i r m a t i o n b u t t o n d i s a b l e d .
2023-02-08 14:11:09 +00:00
app . assertScreenshot ( . serverSelection , step : 2 )
2022-11-24 10:35:00 +02:00
XCTAssertTrue ( app . staticTexts [ ElementL10n . loginErrorHomeserverNotFound ] . exists )
2023-02-08 14:11:09 +00:00
XCTAssertFalse ( app . buttons [ " confirmButton " ] . isEnabled , " The confirm button should be disabled when there is an error. " )
2022-07-04 10:00:27 +01:00
}
func testNonModalPresentation ( ) {
// G i v e n t h e i n i t i a l s e r v e r s e l e c t i o n s c r e e n p u s h e d o n t o t h e s t a c k .
2023-02-14 16:25:24 +00:00
let app = Application . launch ( . serverSelectionNonModal )
2022-07-04 10:00:27 +01:00
// T h e n t h e s c r e e n s h o u l d b e t w e a k e d s l i g h t l y t o r e f l e c t t h e c h a n g e o f n a v i g a t i o n .
2022-08-11 15:02:47 +03:00
app . assertScreenshot ( . serverSelectionNonModal )
2023-02-08 14:11:09 +00:00
XCTAssertFalse ( app . buttons [ " dismissButton " ] . exists , " The dismiss button should be hidden when not in modal presentation. " )
XCTAssertEqual ( app . buttons [ " confirmButton " ] . label , ElementL10n . actionNext , " The confirm button should say Next when not in modal presentation. " )
2022-07-04 10:00:27 +01:00
}
}