focalboard/webapp/cypress/integration/loginActions.ts

129 lines
4.8 KiB
TypeScript
Raw Normal View History

[GH-42] Cypress tests for login actions (#1679) * Testing API added to server: - registered only if `enableTestingAPI` is set to `true` in the config file - has only one route `test/reset` - reset clears the tables in db for blocks, users, sessions - functions `DeleteAllBlocks` and `DeleteAllUsers` added to `Store` interface - new functions implemented for `SQLStore` * Cypress tests (initial version) for login actions added: - redirect to login page, - register user, - test for loading home page deleted, - allow js in `tsconfig.json` for cypress tests. * Cypress tests for login actions: - check that main page with workspace is visible after registration, - initial version of test for login of register user. * Cypress tests for login actions: - function for checking that workspace is available added, - functions for login and logout added, - test for password change added, - session parameters added to server config for cypress testing. * Switch Cypress tests to typescript. * Use ids for inputs instead of placeholder text. * Use cypress request for login without loading login page. * Cypress custom command for login added. * Cypress tests fixed: - new cypress commands for server reset, register/login user - single test for "create and delete board/card" - fixes for `BoardPage` component useEffect callbacks - npm script `runserver-test` doesn't use single user mode * Deletion of all blocks changed: - also deletes blocks from history - public function renamed to DeleteAllBlocksPermanently - code for mocks and public methods generated * Server tests for files fixed on windows. * Cypress tests for the registration of second user via invite link added. * Added `baseUrl` in main `tsconfig.json` (required by cypress configuration). * Cypress test fixed. Comments as well as log messages added. * Log a message if testing API is enabled. * Single cypress test for register/login actions. * Revert changes to server. * More convenient cypress commands: - all API calls made as separate commands - declarations for commands moved to separate global.d.ts file - utility functions moved after test actions in 'Login actions' test
2021-11-22 16:59:01 +01:00
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
describe('Login actions', () => {
const username = Cypress.env('username')
const email = Cypress.env('email')
const password = Cypress.env('password')
2022-04-06 16:22:47 +02:00
beforeEach(() => {
localStorage.setItem('language', 'en')
})
[GH-42] Cypress tests for login actions (#1679) * Testing API added to server: - registered only if `enableTestingAPI` is set to `true` in the config file - has only one route `test/reset` - reset clears the tables in db for blocks, users, sessions - functions `DeleteAllBlocks` and `DeleteAllUsers` added to `Store` interface - new functions implemented for `SQLStore` * Cypress tests (initial version) for login actions added: - redirect to login page, - register user, - test for loading home page deleted, - allow js in `tsconfig.json` for cypress tests. * Cypress tests for login actions: - check that main page with workspace is visible after registration, - initial version of test for login of register user. * Cypress tests for login actions: - function for checking that workspace is available added, - functions for login and logout added, - test for password change added, - session parameters added to server config for cypress testing. * Switch Cypress tests to typescript. * Use ids for inputs instead of placeholder text. * Use cypress request for login without loading login page. * Cypress custom command for login added. * Cypress tests fixed: - new cypress commands for server reset, register/login user - single test for "create and delete board/card" - fixes for `BoardPage` component useEffect callbacks - npm script `runserver-test` doesn't use single user mode * Deletion of all blocks changed: - also deletes blocks from history - public function renamed to DeleteAllBlocksPermanently - code for mocks and public methods generated * Server tests for files fixed on windows. * Cypress tests for the registration of second user via invite link added. * Added `baseUrl` in main `tsconfig.json` (required by cypress configuration). * Cypress test fixed. Comments as well as log messages added. * Log a message if testing API is enabled. * Single cypress test for register/login actions. * Revert changes to server. * More convenient cypress commands: - all API calls made as separate commands - declarations for commands moved to separate global.d.ts file - utility functions moved after test actions in 'Login actions' test
2021-11-22 16:59:01 +01:00
it('Can perform login/register actions', () => {
// Redirects to login page
2022-04-01 19:43:49 +02:00
cy.log('**Redirects to login page (except plugin mode) **')
[GH-42] Cypress tests for login actions (#1679) * Testing API added to server: - registered only if `enableTestingAPI` is set to `true` in the config file - has only one route `test/reset` - reset clears the tables in db for blocks, users, sessions - functions `DeleteAllBlocks` and `DeleteAllUsers` added to `Store` interface - new functions implemented for `SQLStore` * Cypress tests (initial version) for login actions added: - redirect to login page, - register user, - test for loading home page deleted, - allow js in `tsconfig.json` for cypress tests. * Cypress tests for login actions: - check that main page with workspace is visible after registration, - initial version of test for login of register user. * Cypress tests for login actions: - function for checking that workspace is available added, - functions for login and logout added, - test for password change added, - session parameters added to server config for cypress testing. * Switch Cypress tests to typescript. * Use ids for inputs instead of placeholder text. * Use cypress request for login without loading login page. * Cypress custom command for login added. * Cypress tests fixed: - new cypress commands for server reset, register/login user - single test for "create and delete board/card" - fixes for `BoardPage` component useEffect callbacks - npm script `runserver-test` doesn't use single user mode * Deletion of all blocks changed: - also deletes blocks from history - public function renamed to DeleteAllBlocksPermanently - code for mocks and public methods generated * Server tests for files fixed on windows. * Cypress tests for the registration of second user via invite link added. * Added `baseUrl` in main `tsconfig.json` (required by cypress configuration). * Cypress test fixed. Comments as well as log messages added. * Log a message if testing API is enabled. * Single cypress test for register/login actions. * Revert changes to server. * More convenient cypress commands: - all API calls made as separate commands - declarations for commands moved to separate global.d.ts file - utility functions moved after test actions in 'Login actions' test
2021-11-22 16:59:01 +01:00
cy.visit('/')
cy.location('pathname').should('eq', '/login')
cy.get('.LoginPage').contains('Log in')
cy.get('#login-username').should('exist')
cy.get('#login-password').should('exist')
cy.get('button').contains('Log in')
cy.get('a').contains('create an account', {matchCase: false})
[GH-42] Cypress tests for login actions (#1679) * Testing API added to server: - registered only if `enableTestingAPI` is set to `true` in the config file - has only one route `test/reset` - reset clears the tables in db for blocks, users, sessions - functions `DeleteAllBlocks` and `DeleteAllUsers` added to `Store` interface - new functions implemented for `SQLStore` * Cypress tests (initial version) for login actions added: - redirect to login page, - register user, - test for loading home page deleted, - allow js in `tsconfig.json` for cypress tests. * Cypress tests for login actions: - check that main page with workspace is visible after registration, - initial version of test for login of register user. * Cypress tests for login actions: - function for checking that workspace is available added, - functions for login and logout added, - test for password change added, - session parameters added to server config for cypress testing. * Switch Cypress tests to typescript. * Use ids for inputs instead of placeholder text. * Use cypress request for login without loading login page. * Cypress custom command for login added. * Cypress tests fixed: - new cypress commands for server reset, register/login user - single test for "create and delete board/card" - fixes for `BoardPage` component useEffect callbacks - npm script `runserver-test` doesn't use single user mode * Deletion of all blocks changed: - also deletes blocks from history - public function renamed to DeleteAllBlocksPermanently - code for mocks and public methods generated * Server tests for files fixed on windows. * Cypress tests for the registration of second user via invite link added. * Added `baseUrl` in main `tsconfig.json` (required by cypress configuration). * Cypress test fixed. Comments as well as log messages added. * Log a message if testing API is enabled. * Single cypress test for register/login actions. * Revert changes to server. * More convenient cypress commands: - all API calls made as separate commands - declarations for commands moved to separate global.d.ts file - utility functions moved after test actions in 'Login actions' test
2021-11-22 16:59:01 +01:00
// Can register a user
cy.log('**Can register a user**')
cy.visit('/login')
cy.get('a').contains('create an account', {matchCase: false}).click()
[GH-42] Cypress tests for login actions (#1679) * Testing API added to server: - registered only if `enableTestingAPI` is set to `true` in the config file - has only one route `test/reset` - reset clears the tables in db for blocks, users, sessions - functions `DeleteAllBlocks` and `DeleteAllUsers` added to `Store` interface - new functions implemented for `SQLStore` * Cypress tests (initial version) for login actions added: - redirect to login page, - register user, - test for loading home page deleted, - allow js in `tsconfig.json` for cypress tests. * Cypress tests for login actions: - check that main page with workspace is visible after registration, - initial version of test for login of register user. * Cypress tests for login actions: - function for checking that workspace is available added, - functions for login and logout added, - test for password change added, - session parameters added to server config for cypress testing. * Switch Cypress tests to typescript. * Use ids for inputs instead of placeholder text. * Use cypress request for login without loading login page. * Cypress custom command for login added. * Cypress tests fixed: - new cypress commands for server reset, register/login user - single test for "create and delete board/card" - fixes for `BoardPage` component useEffect callbacks - npm script `runserver-test` doesn't use single user mode * Deletion of all blocks changed: - also deletes blocks from history - public function renamed to DeleteAllBlocksPermanently - code for mocks and public methods generated * Server tests for files fixed on windows. * Cypress tests for the registration of second user via invite link added. * Added `baseUrl` in main `tsconfig.json` (required by cypress configuration). * Cypress test fixed. Comments as well as log messages added. * Log a message if testing API is enabled. * Single cypress test for register/login actions. * Revert changes to server. * More convenient cypress commands: - all API calls made as separate commands - declarations for commands moved to separate global.d.ts file - utility functions moved after test actions in 'Login actions' test
2021-11-22 16:59:01 +01:00
cy.location('pathname').should('eq', '/register')
cy.get('.RegisterPage').contains('Sign up')
cy.get('#login-email').type(email)
cy.get('#login-username').type(username)
cy.get('#login-password').type(password)
cy.get('button').contains('Register').click()
workspaceIsAvailable()
// Can log out user
cy.log('**Can log out user**')
cy.get('.SidebarUserMenu').click()
cy.get('.menu-name').contains('Log out').click()
cy.location('pathname').should('eq', '/login')
// User should not be logged in automatically
cy.log('**User should not be logged in automatically**')
cy.visit('/')
2022-04-01 19:43:49 +02:00
cy.location('pathname').should('eq', '/login')
[GH-42] Cypress tests for login actions (#1679) * Testing API added to server: - registered only if `enableTestingAPI` is set to `true` in the config file - has only one route `test/reset` - reset clears the tables in db for blocks, users, sessions - functions `DeleteAllBlocks` and `DeleteAllUsers` added to `Store` interface - new functions implemented for `SQLStore` * Cypress tests (initial version) for login actions added: - redirect to login page, - register user, - test for loading home page deleted, - allow js in `tsconfig.json` for cypress tests. * Cypress tests for login actions: - check that main page with workspace is visible after registration, - initial version of test for login of register user. * Cypress tests for login actions: - function for checking that workspace is available added, - functions for login and logout added, - test for password change added, - session parameters added to server config for cypress testing. * Switch Cypress tests to typescript. * Use ids for inputs instead of placeholder text. * Use cypress request for login without loading login page. * Cypress custom command for login added. * Cypress tests fixed: - new cypress commands for server reset, register/login user - single test for "create and delete board/card" - fixes for `BoardPage` component useEffect callbacks - npm script `runserver-test` doesn't use single user mode * Deletion of all blocks changed: - also deletes blocks from history - public function renamed to DeleteAllBlocksPermanently - code for mocks and public methods generated * Server tests for files fixed on windows. * Cypress tests for the registration of second user via invite link added. * Added `baseUrl` in main `tsconfig.json` (required by cypress configuration). * Cypress test fixed. Comments as well as log messages added. * Log a message if testing API is enabled. * Single cypress test for register/login actions. * Revert changes to server. * More convenient cypress commands: - all API calls made as separate commands - declarations for commands moved to separate global.d.ts file - utility functions moved after test actions in 'Login actions' test
2021-11-22 16:59:01 +01:00
// Can log in registered user
cy.log('**Can log in registered user**')
loginUser(password)
// Can change password
cy.log('**Can change password**')
const newPassword = 'new_password'
cy.get('.SidebarUserMenu').click()
cy.get('.menu-name').contains('Change password').click()
cy.location('pathname').should('eq', '/change_password')
cy.get('.ChangePasswordPage').contains('Change Password')
cy.get('#login-oldpassword').type(password)
cy.get('#login-newpassword').type(newPassword)
cy.get('button').contains('Change password').click()
cy.get('.succeeded').click()
workspaceIsAvailable()
2022-03-30 23:17:39 +02:00
logoutUser()
[GH-42] Cypress tests for login actions (#1679) * Testing API added to server: - registered only if `enableTestingAPI` is set to `true` in the config file - has only one route `test/reset` - reset clears the tables in db for blocks, users, sessions - functions `DeleteAllBlocks` and `DeleteAllUsers` added to `Store` interface - new functions implemented for `SQLStore` * Cypress tests (initial version) for login actions added: - redirect to login page, - register user, - test for loading home page deleted, - allow js in `tsconfig.json` for cypress tests. * Cypress tests for login actions: - check that main page with workspace is visible after registration, - initial version of test for login of register user. * Cypress tests for login actions: - function for checking that workspace is available added, - functions for login and logout added, - test for password change added, - session parameters added to server config for cypress testing. * Switch Cypress tests to typescript. * Use ids for inputs instead of placeholder text. * Use cypress request for login without loading login page. * Cypress custom command for login added. * Cypress tests fixed: - new cypress commands for server reset, register/login user - single test for "create and delete board/card" - fixes for `BoardPage` component useEffect callbacks - npm script `runserver-test` doesn't use single user mode * Deletion of all blocks changed: - also deletes blocks from history - public function renamed to DeleteAllBlocksPermanently - code for mocks and public methods generated * Server tests for files fixed on windows. * Cypress tests for the registration of second user via invite link added. * Added `baseUrl` in main `tsconfig.json` (required by cypress configuration). * Cypress test fixed. Comments as well as log messages added. * Log a message if testing API is enabled. * Single cypress test for register/login actions. * Revert changes to server. * More convenient cypress commands: - all API calls made as separate commands - declarations for commands moved to separate global.d.ts file - utility functions moved after test actions in 'Login actions' test
2021-11-22 16:59:01 +01:00
// Can log in user with new password
cy.log('**Can log in user with new password**')
loginUser(newPassword).then(() => resetPassword(newPassword))
2022-03-30 23:17:39 +02:00
logoutUser()
[GH-42] Cypress tests for login actions (#1679) * Testing API added to server: - registered only if `enableTestingAPI` is set to `true` in the config file - has only one route `test/reset` - reset clears the tables in db for blocks, users, sessions - functions `DeleteAllBlocks` and `DeleteAllUsers` added to `Store` interface - new functions implemented for `SQLStore` * Cypress tests (initial version) for login actions added: - redirect to login page, - register user, - test for loading home page deleted, - allow js in `tsconfig.json` for cypress tests. * Cypress tests for login actions: - check that main page with workspace is visible after registration, - initial version of test for login of register user. * Cypress tests for login actions: - function for checking that workspace is available added, - functions for login and logout added, - test for password change added, - session parameters added to server config for cypress testing. * Switch Cypress tests to typescript. * Use ids for inputs instead of placeholder text. * Use cypress request for login without loading login page. * Cypress custom command for login added. * Cypress tests fixed: - new cypress commands for server reset, register/login user - single test for "create and delete board/card" - fixes for `BoardPage` component useEffect callbacks - npm script `runserver-test` doesn't use single user mode * Deletion of all blocks changed: - also deletes blocks from history - public function renamed to DeleteAllBlocksPermanently - code for mocks and public methods generated * Server tests for files fixed on windows. * Cypress tests for the registration of second user via invite link added. * Added `baseUrl` in main `tsconfig.json` (required by cypress configuration). * Cypress test fixed. Comments as well as log messages added. * Log a message if testing API is enabled. * Single cypress test for register/login actions. * Revert changes to server. * More convenient cypress commands: - all API calls made as separate commands - declarations for commands moved to separate global.d.ts file - utility functions moved after test actions in 'Login actions' test
2021-11-22 16:59:01 +01:00
// Can't register second user without invite link
cy.log('**Can\'t register second user without invite link**')
cy.visit('/register')
cy.get('#login-email').type(email)
cy.get('#login-username').type(username)
cy.get('#login-password').type(password)
cy.get('button').contains('Register').click()
cy.get('.error').contains('Invalid registration link').should('exist')
// Can register second user using invite link
cy.log('**Can register second user using invite link**')
// Copy invite link
cy.log('**Copy invite link**')
loginUser(password)
cy.get('.Sidebar .SidebarUserMenu').click()
cy.get('.menu-name').contains('Invite users').click()
cy.get('.Button').contains('Copy link').click()
cy.get('.Button').contains('Copied').should('exist')
cy.get('a.shareUrl').invoke('attr', 'href').then((inviteLink) => {
2022-03-30 23:17:39 +02:00
logoutUser()
[GH-42] Cypress tests for login actions (#1679) * Testing API added to server: - registered only if `enableTestingAPI` is set to `true` in the config file - has only one route `test/reset` - reset clears the tables in db for blocks, users, sessions - functions `DeleteAllBlocks` and `DeleteAllUsers` added to `Store` interface - new functions implemented for `SQLStore` * Cypress tests (initial version) for login actions added: - redirect to login page, - register user, - test for loading home page deleted, - allow js in `tsconfig.json` for cypress tests. * Cypress tests for login actions: - check that main page with workspace is visible after registration, - initial version of test for login of register user. * Cypress tests for login actions: - function for checking that workspace is available added, - functions for login and logout added, - test for password change added, - session parameters added to server config for cypress testing. * Switch Cypress tests to typescript. * Use ids for inputs instead of placeholder text. * Use cypress request for login without loading login page. * Cypress custom command for login added. * Cypress tests fixed: - new cypress commands for server reset, register/login user - single test for "create and delete board/card" - fixes for `BoardPage` component useEffect callbacks - npm script `runserver-test` doesn't use single user mode * Deletion of all blocks changed: - also deletes blocks from history - public function renamed to DeleteAllBlocksPermanently - code for mocks and public methods generated * Server tests for files fixed on windows. * Cypress tests for the registration of second user via invite link added. * Added `baseUrl` in main `tsconfig.json` (required by cypress configuration). * Cypress test fixed. Comments as well as log messages added. * Log a message if testing API is enabled. * Single cypress test for register/login actions. * Revert changes to server. * More convenient cypress commands: - all API calls made as separate commands - declarations for commands moved to separate global.d.ts file - utility functions moved after test actions in 'Login actions' test
2021-11-22 16:59:01 +01:00
// Register a new user
cy.log('**Register new user**')
cy.visit(inviteLink as string)
cy.get('#login-email').type('new-user@mail.com')
cy.get('#login-username').type('new-user')
cy.get('#login-password').type('new-password')
cy.get('button').contains('Register').click()
workspaceIsAvailable()
})
})
const workspaceIsAvailable = () => {
cy.location('pathname').should('eq', '/')
cy.get('.Workspace').should('exist')
return cy.get('.Sidebar').should('exist')
}
const loginUser = (withPassword: string) => {
cy.visit('/login')
cy.get('#login-username').type(username)
cy.get('#login-password').type(withPassword)
cy.get('button').contains('Log in').click()
return workspaceIsAvailable()
}
2022-03-30 23:17:39 +02:00
const logoutUser = () => {
cy.log('**Log out existing user**')
cy.get('.SidebarUserMenu').click()
cy.get('.menu-name').contains('Log out').click()
cy.location('pathname').should('eq', '/login')
}
[GH-42] Cypress tests for login actions (#1679) * Testing API added to server: - registered only if `enableTestingAPI` is set to `true` in the config file - has only one route `test/reset` - reset clears the tables in db for blocks, users, sessions - functions `DeleteAllBlocks` and `DeleteAllUsers` added to `Store` interface - new functions implemented for `SQLStore` * Cypress tests (initial version) for login actions added: - redirect to login page, - register user, - test for loading home page deleted, - allow js in `tsconfig.json` for cypress tests. * Cypress tests for login actions: - check that main page with workspace is visible after registration, - initial version of test for login of register user. * Cypress tests for login actions: - function for checking that workspace is available added, - functions for login and logout added, - test for password change added, - session parameters added to server config for cypress testing. * Switch Cypress tests to typescript. * Use ids for inputs instead of placeholder text. * Use cypress request for login without loading login page. * Cypress custom command for login added. * Cypress tests fixed: - new cypress commands for server reset, register/login user - single test for "create and delete board/card" - fixes for `BoardPage` component useEffect callbacks - npm script `runserver-test` doesn't use single user mode * Deletion of all blocks changed: - also deletes blocks from history - public function renamed to DeleteAllBlocksPermanently - code for mocks and public methods generated * Server tests for files fixed on windows. * Cypress tests for the registration of second user via invite link added. * Added `baseUrl` in main `tsconfig.json` (required by cypress configuration). * Cypress test fixed. Comments as well as log messages added. * Log a message if testing API is enabled. * Single cypress test for register/login actions. * Revert changes to server. * More convenient cypress commands: - all API calls made as separate commands - declarations for commands moved to separate global.d.ts file - utility functions moved after test actions in 'Login actions' test
2021-11-22 16:59:01 +01:00
const resetPassword = (oldPassword: string) => {
cy.apiGetMe().then((userId) => cy.apiChangePassword(userId, oldPassword, password))
}
})