2020-02-18 08:57:00 +01:00
import onBeforeLoad from "./browser-language" ;
2019-10-05 19:07:50 +02:00
beforeEach ( ( ) => {
2019-10-12 13:16:36 +02:00
cy . clearLocalStorage ( ) ;
2019-10-05 19:07:50 +02:00
} ) ;
2020-02-18 08:57:00 +01:00
describe ( "Login" , ( ) => {
it ( "Tests that everything is present" , ( ) => {
cy . visit ( "/login" , { onBeforeLoad } ) ;
2019-10-05 19:07:50 +02:00
2020-02-18 08:57:00 +01:00
cy . get ( "form .field" ) . first ( ) . contains ( "label" , "Email" ) ;
cy . get ( "form .field" ) . last ( ) . contains ( "label" , "Password" ) ;
cy . get ( "form" ) . contains ( "button.button" , "Login" ) ;
cy . get ( "form" ) . contains ( ".control a.button" , "Forgot your password ?" ) . click ( ) ;
cy . url ( ) . should ( "include" , "/password-reset/send" ) ;
cy . go ( "back" ) ;
2019-10-05 19:07:50 +02:00
2019-10-15 18:14:19 +02:00
cy . wait ( 1000 ) ;
2020-02-18 08:57:00 +01:00
cy . get ( "form" ) . contains ( ".control a.button" , "Register" ) . click ( ) ;
cy . url ( ) . should ( "include" , "/register/user" ) ;
2019-10-05 19:07:50 +02:00
2020-02-18 08:57:00 +01:00
cy . go ( "back" ) ;
2019-10-05 19:07:50 +02:00
} ) ;
2020-02-18 08:57:00 +01:00
it ( "Tries to login with incorrect credentials" , ( ) => {
cy . visit ( "/login" , { onBeforeLoad } ) ;
cy . get ( "input[type=email]" ) . type ( "notanemail" ) . should ( "have.value" , "notanemail" ) ;
cy . get ( "input[type=password]" ) . click ( ) ;
cy . contains ( "button.button.is-primary.is-large" , "Login" ) . click ( ) ;
// cy.get('form .field').first().contains('p.help.is-danger', '@');
// cy.get('form .field').last().contains('p.help.is-danger', 'Please fill out this field.');
2019-10-05 19:07:50 +02:00
} ) ;
2020-02-18 08:57:00 +01:00
it ( "Tries to login with invalid credentials" , ( ) => {
cy . visit ( "/login" , { onBeforeLoad } ) ;
cy . get ( "input[type=email]" ) . type ( "test@email.com" ) . should ( "have.value" , "test@email.com" ) ;
cy . get ( "input[type=password]" ) . type ( "badPassword" ) . should ( "have.value" , "badPassword" ) ;
cy . contains ( "button.button.is-primary.is-large" , "Login" ) . click ( ) ;
2019-10-05 19:07:50 +02:00
2020-02-18 08:57:00 +01:00
cy . contains (
".message.is-danger" ,
"No user account with this email was found. Maybe you made a typo?"
) ;
2019-10-05 19:07:50 +02:00
} ) ;
2019-10-12 13:16:36 +02:00
2020-02-18 08:57:00 +01:00
it ( "Tries to login with valid credentials" , ( ) => {
cy . visit ( "/login" , { onBeforeLoad } ) ;
cy . get ( "input[type=email]" ) . type ( "user@email.com" ) ;
cy . get ( "input[type=password]" ) . type ( "some password" ) ;
cy . get ( "form" ) . submit ( ) ;
cy . wait ( 1000 ) ;
cy . get ( ".navbar-end .navbar-link span.icon i" ) . should ( "have.class" , "mdi-account-circle" ) ;
cy . contains ( "article.message.is-info" , "Welcome back I'm a test user" ) ;
cy . get ( ".navbar-item.has-dropdown" ) . click ( ) ;
cy . get ( ".navbar-item" ) . last ( ) . contains ( "Log out" ) . click ( ) ;
2019-10-12 13:16:36 +02:00
} ) ;
2020-02-18 08:57:00 +01:00
it ( "Tries to login with valid credentials but unconfirmed account" , ( ) => {
cy . visit ( "/login" , { onBeforeLoad } ) ;
cy . get ( "input[type=email]" ) . type ( "unconfirmed@email.com" ) ;
cy . get ( "input[type=password]" ) . type ( "some password" ) ;
cy . get ( "form" ) . submit ( ) ;
cy . contains (
".message.is-danger" ,
"The user account you're trying to login as has not been confirmed yet. Check your email inbox and eventually your spam folder.You may also ask to resend confirmation email."
) ;
2019-10-12 13:16:36 +02:00
} ) ;
2020-02-18 08:57:00 +01:00
it ( "Tries to login with valid credentials, confirmed account but no profile" , ( ) => {
cy . visit ( "/login" , { onBeforeLoad } ) ;
cy . get ( "input[type=email]" ) . type ( "confirmed@email.com" ) ;
cy . get ( "input[type=password]" ) . type ( "some password" ) ;
cy . get ( "form" ) . submit ( ) ;
2019-10-12 13:16:36 +02:00
2020-02-18 08:57:00 +01:00
cy . contains (
".message" ,
"To achieve your registration, please create a first identity profile."
) ;
cy . get ( "form > .field" )
. eq ( 1 )
. contains ( "label" , "Username" )
. parent ( )
. find ( "input" )
. type ( "test_user" ) ;
cy . get ( "form > .field" )
. first ( )
. contains ( "label" , "Display name" )
. parent ( )
. find ( "input" )
. type ( "Duplicate" ) ;
cy . get ( "form > .field" )
. eq ( 2 )
. contains ( "label" , "Description" )
. parent ( )
. find ( "textarea" )
. type ( "This shouln't work because it' using a dupublicated username" ) ;
cy . get ( ".control.has-text-centered" ) . contains ( "button" , "Create my profile" ) . click ( ) ;
cy . contains ( ".help.is-danger" , "Username is already taken" ) ;
2019-10-12 13:16:36 +02:00
2020-02-18 08:57:00 +01:00
cy . get ( "form .field input" ) . first ( 0 ) . clear ( ) . type ( "test_user_2" ) ;
cy . get ( "form .field input" ) . eq ( 1 ) . type ( "Not" ) ;
cy . get ( "form .field textarea" ) . clear ( ) . type ( "This will now work" ) ;
cy . get ( "form" ) . submit ( ) ;
2019-10-12 13:16:36 +02:00
cy . wait ( 1000 ) ;
2020-02-18 08:57:00 +01:00
cy . get ( ".navbar-link span.icon i" ) . should ( "have.class" , "mdi-account-circle" ) ;
cy . contains ( "article.message.is-info" , "Welcome to Mobilizon, test_user_2!" ) ;
2019-10-12 13:16:36 +02:00
} ) ;
2019-10-05 19:07:50 +02:00
} ) ;