forked from open-webui/open-webui
feat: add basic cypress test as initial work towards e2e tests
This commit is contained in:
parent
81fb53e757
commit
730befce45
13 changed files with 1961 additions and 4 deletions
73
cypress/support/e2e.ts
Normal file
73
cypress/support/e2e.ts
Normal file
|
@ -0,0 +1,73 @@
|
|||
/// <reference types="cypress" />
|
||||
|
||||
export const adminUser = {
|
||||
name: 'Admin User',
|
||||
email: 'admin@example.com',
|
||||
password: 'password'
|
||||
};
|
||||
|
||||
const login = (email: string, password: string) => {
|
||||
return cy.session(
|
||||
email,
|
||||
() => {
|
||||
// Visit auth page
|
||||
cy.visit('/auth');
|
||||
// Fill out the form
|
||||
cy.get('input[autocomplete="email"]').type(email);
|
||||
cy.get('input[type="password"]').type(password);
|
||||
// Submit the form
|
||||
cy.get('button[type="submit"]').click();
|
||||
// Wait until the user is redirected to the home page
|
||||
cy.get('#chat-search').should('exist');
|
||||
// Get the current version to skip the changelog dialog
|
||||
if (localStorage.getItem('version') === null) {
|
||||
cy.get('button').contains("Okay, Let's Go!").click();
|
||||
}
|
||||
},
|
||||
{
|
||||
validate: () => {
|
||||
cy.request({
|
||||
method: 'GET',
|
||||
url: '/api/v1/auths/',
|
||||
headers: {
|
||||
Authorization: 'Bearer ' + localStorage.getItem('token')
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const register = (name: string, email: string, password: string) => {
|
||||
return cy
|
||||
.request({
|
||||
method: 'POST',
|
||||
url: '/api/v1/auths/signup',
|
||||
body: {
|
||||
name: name,
|
||||
email: email,
|
||||
password: password
|
||||
},
|
||||
failOnStatusCode: false
|
||||
})
|
||||
.then((response) => {
|
||||
expect(response.status).to.be.oneOf([200, 400]);
|
||||
});
|
||||
};
|
||||
|
||||
const registerAdmin = () => {
|
||||
return register(adminUser.name, adminUser.email, adminUser.password);
|
||||
};
|
||||
|
||||
const loginAdmin = () => {
|
||||
return login(adminUser.email, adminUser.password);
|
||||
};
|
||||
|
||||
Cypress.Commands.add('login', (email, password) => login(email, password));
|
||||
Cypress.Commands.add('register', (name, email, password) => register(name, email, password));
|
||||
Cypress.Commands.add('registerAdmin', () => registerAdmin());
|
||||
Cypress.Commands.add('loginAdmin', () => loginAdmin());
|
||||
|
||||
before(() => {
|
||||
cy.registerAdmin();
|
||||
});
|
11
cypress/support/index.d.ts
vendored
Normal file
11
cypress/support/index.d.ts
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
// load the global Cypress types
|
||||
/// <reference types="cypress" />
|
||||
|
||||
declare namespace Cypress {
|
||||
interface Chainable {
|
||||
login(email: string, password: string): Chainable<Element>;
|
||||
register(name: string, email: string, password: string): Chainable<Element>;
|
||||
registerAdmin(): Chainable<Element>;
|
||||
loginAdmin(): Chainable<Element>;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue