2022-07-04 10:00:27 +01:00
//
2024-09-06 16:34:30 +03:00
// C o p y r i g h t 2 0 2 2 - 2 0 2 4 N e w V e c t o r L t d .
2022-07-04 10:00:27 +01:00
//
2024-09-06 16:34:30 +03:00
// S P D X - L i c e n s e - I d e n t i f i e r : A G P L - 3 . 0 - o n l y
// P l e a s e s e e L I C E N S E i n t h e r e p o s i t o r y r o o t f o r f u l l d e t a i l s .
2022-07-04 10:00:27 +01:00
//
import XCTest
@ MainActor
2024-03-13 11:24:48 +02:00
class AuthenticationFlowCoordinatorUITests : 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
2024-03-15 13:41:23 +00:00
app . buttons [ A11yIdentifiers . authenticationStartScreen . signIn ] . tap ( )
2022-07-04 10:00:27 +01:00
2023-05-30 10:31:18 +01:00
// S e r v e r C o n f i r m a t i o n : T a p c o n t i n u e b u t t o n
app . buttons [ A11yIdentifiers . serverConfirmationScreen . continue ] . tap ( )
// 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
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 ( )
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
2024-03-15 13:41:23 +00:00
app . buttons [ A11yIdentifiers . authenticationStartScreen . signIn ] . tap ( )
2022-07-04 10:00:27 +01:00
2023-05-30 10:31:18 +01:00
// S e r v e r C o n f i r m a t i o n : T a p c o n t i n u e b u t t o n
app . buttons [ A11yIdentifiers . serverConfirmationScreen . continue ] . 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
2024-03-15 13:41:23 +00:00
app . buttons [ A11yIdentifiers . authenticationStartScreen . signIn ] . tap ( )
2022-07-04 10:00:27 +01:00
2023-05-30 10:31:18 +01:00
// S e r v e r C o n f i r m a t i o n : T a p c h a n g e s e r v e r b u t t o n
app . buttons [ A11yIdentifiers . serverConfirmationScreen . changeServer ] . tap ( )
2022-07-04 10:00:27 +01:00
2023-05-30 10:31:18 +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 , e n t e r O I D C s e r v e r a n d c o n t i n u e .
2023-06-08 11:33:32 +03:00
app . textFields [ A11yIdentifiers . changeServerScreen . server ] . clearAndTypeText ( " company.com \n " )
2022-07-04 10:00:27 +01:00
2023-05-30 10:31:18 +01:00
// S e r v e r C o n f i r m a t i o n : T a p c o n t i n u e b u t t o n
app . buttons [ A11yIdentifiers . serverConfirmationScreen . continue ] . tap ( )
2023-06-02 12:41:45 +01:00
// T h e n t h e l o g i n f o r m s h o u l d n ' t b e s h o w n a s O I D C w i l l b e u s e d i n s t e a d .
XCTAssertFalse ( app . buttons [ A11yIdentifiers . loginScreen . continue ] . waitForExistence ( timeout : 1 ) , " The login screen should not be shown after selecting a homeserver with OIDC. " )
2022-07-04 10:00:27 +01:00
}
}