Skip to content

Commit

Permalink
rework settings page.
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Nov 15, 2022
1 parent e95e5fd commit 564a1d0
Showing 1 changed file with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,37 @@ describe('/account/settings', () => {
const username = Cypress.env('E2E_USERNAME') ?? 'user';
const password = Cypress.env('E2E_PASSWORD') ?? 'user';

beforeEach(() => {
let account: { email: string };

before(() => {
cy.login(username, password);
cy.visit('/account/settings');
cy.authenticatedRequest({
method: 'GET',
url: '/api/account',
}).then(({ body }) => {
account = body;
});
});

beforeEach(() => {
cy.login(username, password);
cy.visit('/account/settings');
cy.get(emailSettingsSelector).should('have.value', account.email);

cy.intercept('POST', '/api/account').as('settingsSave');
});

afterEach(() => {
cy.login(username, password);
cy.authenticatedRequest({
method: 'POST',
url: '/api/account',
body: account,
})
.its('status')
.should('eq', 200);
});

it('should be accessible through menu', () => {
cy.visit('');
cy.clickOnSettingsItem();
Expand All @@ -49,44 +71,40 @@ describe('/account/settings', () => {
// need to modify email because default email does not match regex in vue
cy.get(emailSettingsSelector).clear().type('[email protected]');
cy.get(submitSettingsSelector).click();
cy.wait('@settingsSave').then(({ response }) => expect(response.statusCode).to.equal(200));
cy.wait('@settingsSave').then(({ response }) => expect(response?.statusCode).to.equal(200));
});

it("should be able to change 'user' lastname settings", () => {
cy.get(lastNameSettingsSelector).clear().type('retspihj');
// need to modify email because default email does not match regex in vue
cy.get(emailSettingsSelector).clear().type('[email protected]');
cy.get(submitSettingsSelector).click();
cy.wait('@settingsSave').then(({ response }) => expect(response.statusCode).to.equal(200));
cy.wait('@settingsSave').then(({ response }) => expect(response?.statusCode).to.equal(200));
});

it("should be able to change 'user' email settings", () => {
cy.get(emailSettingsSelector).should('have.value', '[email protected]');
cy.get(emailSettingsSelector).clear().type('[email protected]');
cy.get(submitSettingsSelector).click();
cy.wait('@settingsSave').then(({ response }) => expect(response.statusCode).to.equal(200));
cy.wait('@settingsSave').then(({ response }) => expect(response?.statusCode).to.equal(200));
});

describe('if there is another user with an email', () => {
let adminEmail: string;

before(() => {
cy.login(adminUsername, adminPassword);
cy.visit('/account/settings');
cy.get(emailSettingsSelector).should('have.value', 'admin@localhost');
cy.get(emailSettingsSelector).clear().type('[email protected]');
cy.intercept({
method: 'POST',
cy.authenticatedRequest({
method: 'GET',
url: '/api/account',
times: 1,
}).as('settingsSave');
cy.get(submitSettingsSelector).click();
cy.wait('@settingsSave');
}).then(({ body }) => {
adminEmail = body.email;
});
});

it("should not be able to change 'user' email to same value", () => {
cy.get(emailSettingsSelector).should('have.value', '[email protected]');
cy.get(emailSettingsSelector).clear().type('[email protected]');
cy.get(emailSettingsSelector).clear().type(adminEmail);
cy.get(submitSettingsSelector).click();
cy.wait('@settingsSave').then(({ response }) => expect(response.statusCode).to.equal(400));
cy.wait('@settingsSave').then(({ response }) => expect(response?.statusCode).to.equal(400));
});
});
});

0 comments on commit 564a1d0

Please sign in to comment.