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
//
2022-08-11 08:54:24 +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 .
2022-07-04 10:00:27 +01:00
//
import XCTest
@ testable import ElementX
@ MainActor
class AuthenticationCoordinatorUITests : XCTestCase {
2023-05-15 15:42:40 +02:00
func testLoginWithPassword ( ) async throws {
2022-07-04 10:00:27 +01:00
// G i v e n t h e a u t h e n t i c a t i o n f l o w .
2023-02-14 16:25:24 +00:00
let app = Application . launch ( . authenticationFlow )
2022-07-04 10:00:27 +01:00
// S p l a s h S c r e e n : T a p g e t s t a r t e d b u t t o n
2023-02-15 05:53:04 +00:00
app . buttons [ A11yIdentifiers . onboardingScreen . signIn ] . tap ( )
2022-07-04 10:00:27 +01:00
// L o g i n S c r e e n : E n t e r v a l i d c r e d e n t i a l s
2022-12-15 15:22:39 +02:00
2023-02-15 05:53:04 +00:00
app . textFields [ A11yIdentifiers . loginScreen . emailUsername ] . clearAndTypeText ( " alice \n " )
app . secureTextFields [ A11yIdentifiers . loginScreen . password ] . clearAndTypeText ( " 12345678 " )
2022-08-11 15:02:47 +03:00
2023-05-15 15:42:40 +02:00
try await app . assertScreenshot ( . authenticationFlow )
2022-07-04 10:00:27 +01:00
// L o g i n S c r e e n : T a p n e x t
2023-02-15 05:53:04 +00:00
app . buttons [ A11yIdentifiers . loginScreen . continue ] . tap ( )
2023-05-15 15:42:40 +02:00
XCTAssertTrue ( app . staticTexts [ A11yIdentifiers . analyticsPromptScreen . title ] . waitForExistence ( timeout : 1.0 ) , " The analytics prompt screen should be seen after login " )
2022-07-04 10:00:27 +01:00
}
2022-08-11 15:02:47 +03:00
func testLoginWithIncorrectPassword ( ) async throws {
2022-07-04 10:00:27 +01:00
// G i v e n t h e a u t h e n t i c a t i o n f l o w .
2023-02-14 16:25:24 +00:00
let app = Application . launch ( . authenticationFlow )
2022-07-04 10:00:27 +01:00
// S p l a s h S c r e e n : T a p g e t s t a r t e d b u t t o n
2023-02-15 05:53:04 +00:00
app . buttons [ A11yIdentifiers . onboardingScreen . signIn ] . tap ( )
2022-07-04 10:00:27 +01:00
// L o g i n S c r e e n : E n t e r i n v a l i d c r e d e n t i a l s
2023-02-15 05:53:04 +00:00
app . textFields [ A11yIdentifiers . loginScreen . emailUsername ] . clearAndTypeText ( " alice " )
app . secureTextFields [ A11yIdentifiers . loginScreen . password ] . clearAndTypeText ( " 87654321 " )
2022-08-11 15:02:47 +03:00
// L o g i n S c r e e n : T a p n e x t
2023-02-15 05:53:04 +00:00
let nextButton = app . buttons [ A11yIdentifiers . loginScreen . continue ]
2022-08-18 16:32:29 +03:00
XCTAssertTrue ( nextButton . waitForExistence ( timeout : 2.0 ) )
XCTAssertTrue ( nextButton . isEnabled )
nextButton . tap ( )
2022-07-04 10:00:27 +01:00
// T h e n l o g i n s h o u l d f a i l .
2022-08-18 16:32:29 +03:00
XCTAssertTrue ( app . alerts . element . waitForExistence ( timeout : 2.0 ) , " An error alert should be shown when attempting login with invalid credentials. " )
2022-07-04 10:00:27 +01:00
}
func testSelectingOIDCServer ( ) {
// G i v e n t h e a u t h e n t i c a t i o n f l o w .
2023-02-14 16:25:24 +00:00
let app = Application . launch ( . authenticationFlow )
2022-07-04 10:00:27 +01:00
// S p l a s h S c r e e n : T a p g e t s t a r t e d b u t t o n
2023-02-15 05:53:04 +00:00
app . buttons [ A11yIdentifiers . onboardingScreen . signIn ] . tap ( )
2022-07-04 10:00:27 +01:00
// L o g i n S c r e e n : T a p e d i t s e r v e r b u t t o n .
2023-02-15 05:53:04 +00:00
XCTAssertFalse ( app . buttons [ A11yIdentifiers . loginScreen . oidc ] . exists , " The OIDC button shouldn't be shown before entering a supported homeserver. " )
app . buttons [ A11yIdentifiers . loginScreen . changeServer ] . tap ( )
2022-07-04 10:00:27 +01:00
// S e r v e r S e l e c t i o n : C l e a r t h e d e f a u l t a n d e n t e r O I D C s e r v e r .
2023-02-15 05:53:04 +00:00
app . textFields [ A11yIdentifiers . changeServerScreen . server ] . clearAndTypeText ( " company.com " )
2022-07-04 10:00:27 +01:00
// D i s m i s s s e r v e r s c r e e n .
2023-02-15 05:53:04 +00:00
app . buttons [ A11yIdentifiers . changeServerScreen . continue ] . tap ( )
2022-07-04 10:00:27 +01:00
// T h e n t h e l o g i n f o r m s h o u l d b e u p d a t e d f o r O I D C .
2023-02-15 05:53:04 +00:00
XCTAssertTrue ( app . buttons [ A11yIdentifiers . loginScreen . oidc ] . waitForExistence ( timeout : 1 ) , " The OIDC button should be shown after selecting a homeserver with OIDC. " )
2022-07-04 10:00:27 +01:00
}
}