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
//
2025-01-06 11:27:37 +01: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 O R L i c e n s e R e f - E l e m e n t - C o m m e r c i a l
// P l e a s e s e e L I C E N S E f i l e s 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 ( )
2024-09-25 14:40:18 +01:00
// L o g i n S c r e e n : W a i t f o r c o n t i n u e b u t t o n t o a p p e a r
let continueButton = app . buttons [ A11yIdentifiers . loginScreen . continue ]
XCTAssertTrue ( continueButton . waitForExistence ( timeout : 2.0 ) )
2023-05-30 10:31:18 +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
2024-10-10 08:38:40 +01:00
app . textFields [ A11yIdentifiers . loginScreen . emailUsername ] . clearAndTypeText ( " alice \n " , app : app )
app . secureTextFields [ A11yIdentifiers . loginScreen . password ] . clearAndTypeText ( " 12345678 " , app : app )
2022-08-11 15:02:47 +03:00
2025-03-04 17:17:52 +02:00
try await app . assertScreenshot ( )
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 ( )
2024-09-25 14:40:18 +01:00
// L o g i n S c r e e n : W a i t f o r c o n t i n u e b u t t o n t o a p p e a r
let continueButton = app . buttons [ A11yIdentifiers . loginScreen . continue ]
XCTAssertTrue ( continueButton . waitForExistence ( timeout : 2.0 ) )
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
2024-10-10 08:38:40 +01:00
app . textFields [ A11yIdentifiers . loginScreen . emailUsername ] . clearAndTypeText ( " alice " , app : app )
app . secureTextFields [ A11yIdentifiers . loginScreen . password ] . clearAndTypeText ( " 87654321 " , app : app )
2022-08-11 15:02:47 +03:00
2024-09-25 14:40:18 +01:00
// L o g i n S c r e e n : T a p c o n t i n u e
XCTAssertTrue ( continueButton . isEnabled )
continueButton . 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
}
2024-09-25 14:40:18 +01:00
func testLoginWithUnsupportedUserID ( ) async throws {
// 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 .
let app = Application . launch ( . authenticationFlow )
// 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
app . buttons [ A11yIdentifiers . authenticationStartScreen . signIn ] . tap ( )
// 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 : W a i t f o r c o n t i n u e b u t t o n t o a p p e a r
let continueButton = app . buttons [ A11yIdentifiers . loginScreen . continue ]
XCTAssertTrue ( continueButton . waitForExistence ( timeout : 2.0 ) )
// W h e n e n t e r i n g a u s e r n a m e o n a h o m e s e r v e r w i t h a n u n s u p p o r t e d f l o w .
2024-10-10 08:38:40 +01:00
app . textFields [ A11yIdentifiers . loginScreen . emailUsername ] . clearAndTypeText ( " @test:server.net \n " , app : app )
2024-09-25 14:40:18 +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 l o g i n t o c o n t i n u e .
2025-03-04 17:17:52 +02:00
try await app . assertScreenshot ( )
2024-09-25 14:40:18 +01:00
}
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 .
2024-10-10 08:38:40 +01:00
app . textFields [ A11yIdentifiers . changeServerScreen . server ] . clearAndTypeText ( " company.com \n " , app : app )
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
}
}