-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
3,504 additions
and
9,343 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/// <reference types="cypress" /> | ||
/// <reference types="../support" /> | ||
|
||
describe("Login", () => { | ||
const username = Cypress.env('USERNAME') || 'admin'; | ||
const password = Cypress.env('PASSWORD') || 'Admin123'; | ||
|
||
const submitForm = () => cy.get('#login-form form').submit(); | ||
|
||
beforeEach(() => { | ||
cy.logout(); | ||
cy.visit('/login'); | ||
}); | ||
|
||
it("should allow user to login", () => { | ||
cy.get('#username').type(username); | ||
cy.get('#password').type(password); | ||
cy.get('button[type="submit"]').click(); | ||
|
||
cy.url().should('not.contain', '/login'); | ||
}); | ||
|
||
it("should allow user to login by pressing enter", () => { | ||
cy.get('#username').type(username); | ||
cy.get('#password').type(password).type('{enter}'); | ||
|
||
cy.url().should('not.contain', '/login'); | ||
}); | ||
|
||
it("should require a user name to login", () => { | ||
cy.get('#password').type(password); | ||
submitForm(); | ||
|
||
cy.get('#username').should('have.attr', 'aria-invalid'); | ||
}); | ||
|
||
it("should require a password to login", () => { | ||
cy.get('#username').type(username); | ||
submitForm(); | ||
|
||
cy.get('#password').should('have.attr', 'aria-invalid'); | ||
}); | ||
|
||
it("should display an error with invalid credentials", () => { | ||
cy.get('#username').type('badusername'); | ||
cy.get('#password').type('badpassword'); | ||
submitForm(); | ||
|
||
cy.url().should('contain', '/login'); | ||
|
||
cy.get('[data-testid="login-status-message"]').should("be.visible") | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import '@testing-library/cypress/add-commands'; | ||
import { LOGIN_ACTION, LOGOUT_ACTION } from '../../src/apps/authentication/redux/actionTypes'; | ||
import { nanoid } from 'nanoid'; | ||
import { getStore } from '../utils'; | ||
|
||
const apiUrl: string = Cypress.env('API_URL') || 'http://localhost:8000'; | ||
|
||
Cypress.Commands.add('login', ( | ||
username = Cypress.env('USERNAME') || 'admin', | ||
password = Cypress.env('PASSWORD') || 'Admin123') => { | ||
|
||
const store = getStore(); | ||
|
||
// already logged in | ||
if (store.getState().auth.profile?.username === username && | ||
store.getState().auth.token) { | ||
return; | ||
} | ||
|
||
const token = Cypress.env('TOKEN'); | ||
|
||
if (!token) { | ||
cy.request({ | ||
method: 'POST', | ||
url: `${apiUrl}/users/login`, | ||
body: { | ||
"username": username, | ||
"password": password | ||
} | ||
}).then((response) => { | ||
store | ||
.dispatch({ type: LOGIN_ACTION, payload: { token: response.body['token'] } }); | ||
}); | ||
} else { | ||
store.dispatch({ type: LOGIN_ACTION, payload: { token: token} }); | ||
} | ||
|
||
// delay until we've added the token to the store | ||
while (!store.getState().auth.isLoggedIn && !store.getState().auth.token); | ||
}); | ||
|
||
Cypress.Commands.add('logout', () => { | ||
const store = getStore(); | ||
if (typeof store === 'undefined') { | ||
return; | ||
} | ||
|
||
store.dispatch({ type: LOGOUT_ACTION }); | ||
// delay until we're actually logged out | ||
while (store.getState().auth.isLoggedIn); | ||
}); | ||
|
||
Cypress.Commands.add('createDictionary', ( | ||
username = Cypress.env('USERNAME') || 'admin', | ||
dictionary = `TD-${nanoid()}`) => { | ||
|
||
cy.request(`${apiUrl}/users/${username}/collections/${dictionary}`) | ||
.then((response) => { | ||
if (response.status !== 200) { | ||
cy.request({ | ||
method: 'POST', | ||
headers: { | ||
'Authorization': `Token ${getStore().getState().auth.token}` | ||
}, | ||
url: `${apiUrl}/users/${username}/collections/`, | ||
body: { | ||
"short_code": `${dictionary}`, | ||
"name": "Test Dictionary", | ||
"public_access": "None" | ||
} | ||
}); | ||
} | ||
}) | ||
|
||
return cy.wrap(dictionary); | ||
}); | ||
|
||
Cypress.Commands.add('deleteDictionary', ( | ||
dictionary, | ||
username = Cypress.env('USERNAME') || 'admin' | ||
) => { | ||
|
||
cy.request({ | ||
method: 'DELETE', | ||
headers: { | ||
'Authorization': `Token ${getStore().getState().auth.token}` | ||
}, | ||
url: `${apiUrl}/usrs/${username}/collections/${dictionary}` | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './commands'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Store } from 'redux'; | ||
import { AppState } from '../src/redux/types'; | ||
|
||
export const getStore = (): Store<AppState> => window.store; | ||
export const currentUser = (): string => | ||
getStore().getState().auth.profile?.username || 'admin' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.