Improve tests structure

This commit is contained in:
SleepWalker
2019-12-28 12:25:44 +02:00
parent 5d411fd6ca
commit ba49382fb6
6 changed files with 906 additions and 887 deletions

View File

@@ -1,6 +1,7 @@
import { account1 } from '../../fixtures/accounts.json';
it('should request password reset', () => {
describe('Forgot / reset password', () => {
it('should request password reset', () => {
const captchaCode = 'captchaCode';
const emailMask = 'fo*@gm*l.**m';
@@ -28,7 +29,10 @@ it('should request password reset', () => {
cy.location('pathname').should('eq', '/forgot-password');
cy.getByTestId('forgot-password-login').should('contain', account1.username);
cy.getByTestId('forgot-password-login').should(
'contain',
account1.username,
);
cy.window().should('have.property', 'e2eCaptchaSetCode');
cy.window().then(win => {
@@ -53,9 +57,9 @@ it('should request password reset', () => {
cy.location('pathname').should('eq', '/recover-password');
cy.getByTestId('auth-body').should('contain', emailMask);
});
});
it('should allow change login', () => {
it('should allow change login', () => {
const captchaCode = 'captchaCode';
const login = 'foo';
const emailMask = 'fo*@gm*l.**m';
@@ -109,9 +113,9 @@ it('should allow change login', () => {
);
cy.location('pathname').should('eq', '/recover-password');
});
});
it('should allow enter login', () => {
it('should allow enter login', () => {
const captchaCode = 'captchaCode';
const login = 'foo';
const emailMask = 'fo*@gm*l.**m';
@@ -152,9 +156,9 @@ it('should allow enter login', () => {
);
cy.location('pathname').should('eq', '/recover-password');
});
});
it('should recover password', () => {
it('should recover password', () => {
const key = 'key';
const newPassword = 'newPassword';
@@ -213,4 +217,5 @@ it('should recover password', () => {
newRePassword: newPassword,
}).toString(),
);
});
});

View File

@@ -1,6 +1,6 @@
// account1 - authenticated
// account2 - invalid refreshToken
import { account1, account2 } from '../fixtures/accounts.json';
import { account1, account2 } from '../../fixtures/accounts.json';
const multiAccount = createState();
const multiAccountWithBadTokens = createState();

View File

@@ -8,15 +8,16 @@ const defaults = {
scope: 'account_info,account_email',
};
it('should complete oauth', () => {
describe('OAuth', () => {
it('should complete oauth', () => {
cy.login({ accounts: ['default'] });
cy.visit(`/oauth2/v1/ely?${new URLSearchParams(defaults)}`);
cy.url().should('equal', 'https://ely.by/');
});
});
it('should restore previous oauthData if any', () => {
it('should restore previous oauthData if any', () => {
localStorage.setItem(
'oauthData',
JSON.stringify({
@@ -37,9 +38,9 @@ it('should restore previous oauthData if any', () => {
cy.visit('/');
cy.url().should('equal', 'https://ely.by/');
});
});
it('should ask to choose an account if user has multiple', () => {
it('should ask to choose an account if user has multiple', () => {
cy.login({ accounts: ['default', 'default2'] }).then(
({ accounts: [account] }) => {
cy.visit(`/oauth2/v1/ely?${new URLSearchParams(defaults)}`);
@@ -55,10 +56,10 @@ it('should ask to choose an account if user has multiple', () => {
cy.url().should('equal', 'https://ely.by/');
},
);
});
});
// TODO: remove api mocks, when we will be able to revoke permissions
it('should prompt for permissions', () => {
// TODO: remove api mocks, when we will be able to revoke permissions
it('should prompt for permissions', () => {
cy.server();
cy.route({
@@ -95,9 +96,9 @@ it('should prompt for permissions', () => {
.click();
cy.url().should('match', /^http:\/\/localhost:8080\/?\?code=[^&]+&state=$/);
});
});
it('should allow sign in during oauth (guest oauth)', () => {
it('should allow sign in during oauth (guest oauth)', () => {
cy.visit(`/oauth2/v1/ely?${new URLSearchParams(defaults)}`);
cy.url().should('include', '/login');
@@ -109,10 +110,10 @@ it('should allow sign in during oauth (guest oauth)', () => {
cy.get('[name=password]').type(`${account1.password}{enter}`);
cy.url().should('equal', 'https://ely.by/');
});
});
// TODO: enable, when backend api will return correct response on auth decline
xit('should redirect to error page, when permission request declined', () => {
// TODO: enable, when backend api will return correct response on auth decline
xit('should redirect to error page, when permission request declined', () => {
cy.server();
cy.route({
@@ -149,9 +150,9 @@ xit('should redirect to error page, when permission request declined', () => {
.click();
cy.url().should('include', 'error=access_denied');
});
});
describe('login_hint', () => {
describe('login_hint', () => {
it('should automatically choose account, when id in login_hint is present', () => {
cy.login({ accounts: ['default', 'default2'] }).then(
({ accounts: [account] }) => {
@@ -205,9 +206,9 @@ describe('login_hint', () => {
},
);
});
});
});
describe('prompts', () => {
describe('prompts', () => {
it('should prompt for account', () => {
cy.login({ accounts: ['default'] }).then(({ accounts: [account] }) => {
cy.visit(
@@ -274,7 +275,10 @@ describe('prompts', () => {
.contains('Approve')
.click();
cy.url().should('match', /^http:\/\/localhost:8080\/?\?code=[^&]+&state=$/);
cy.url().should(
'match',
/^http:\/\/localhost:8080\/?\?code=[^&]+&state=$/,
);
});
// TODO: enable, when backend api will return correct response on auth decline
@@ -355,11 +359,14 @@ describe('prompts', () => {
.contains('Approve')
.click();
cy.url().should('match', /^http:\/\/localhost:8080\/?\?code=[^&]+&state=$/);
cy.url().should(
'match',
/^http:\/\/localhost:8080\/?\?code=[^&]+&state=$/,
);
});
});
});
describe('static pages', () => {
describe('static pages', () => {
it('should authenticate using static page', () => {
cy.login({ accounts: ['default'] });
@@ -403,9 +410,9 @@ describe('static pages', () => {
force: true,
});
});
});
});
function assertPermissions() {
function assertPermissions() {
cy.url().should('include', '/oauth/permissions');
cy.getByTestId('auth-header').should('contain', 'Application permissions');
@@ -417,4 +424,5 @@ function assertPermissions() {
'contain',
'Access to your Email address',
);
}
}
});

View File

@@ -1,4 +1,5 @@
it('should register', () => {
describe('Register', () => {
it('should register', () => {
const username = `test${Date.now()}`;
const email = `${Date.now()}@gmail.com`;
const password = String(Date.now());
@@ -73,9 +74,9 @@ it('should register', () => {
.should('eq', `key=${activationKey}`);
cy.location('pathname').should('eq', '/');
});
});
it('should allow activation', () => {
it('should allow activation', () => {
const activationKey = 'activationKey';
cy.server();
@@ -105,9 +106,9 @@ it('should allow activation', () => {
.should('eq', `key=${activationKey}`);
cy.location('pathname').should('eq', '/');
});
});
it('should allow resend code', () => {
it('should allow resend code', () => {
const email = `${Date.now()}@gmail.com`;
const captchaCode = 'captchaCode';
@@ -142,4 +143,5 @@ it('should allow resend code', () => {
);
cy.location('pathname').should('eq', '/activation');
});
});

View File

@@ -1,6 +1,7 @@
import { account1, account2 } from '../../fixtures/accounts.json';
it('should sign in', () => {
describe('Sign in / Log out', () => {
it('should sign in', () => {
cy.visit('/');
cy.url().should('include', '/login');
@@ -43,9 +44,9 @@ it('should sign in', () => {
expect(user.username).to.be.equal(account.username);
expect(user.isGuest).to.be.false;
});
});
});
it('should sign in without remember me', () => {
it('should sign in without remember me', () => {
cy.visit('/');
cy.get('[name=login]').type(`${account1.login}{enter}`);
@@ -87,9 +88,9 @@ it('should sign in without remember me', () => {
expect(user.username).to.be.equal(account.username);
expect(user.isGuest).to.be.false;
});
});
});
it('should sign in with totp', () => {
it('should sign in with totp', () => {
cy.visit('/');
cy.get('[name=login]').type(`${account1.login}{enter}`);
@@ -123,9 +124,9 @@ it('should sign in with totp', () => {
.should('include', 'totp=123');
cy.location('pathname').should('eq', '/');
});
});
it('should allow logout', () => {
it('should allow logout', () => {
cy.login({ accounts: ['default'] });
cy.visit('/');
@@ -140,9 +141,9 @@ it('should allow logout', () => {
cy.location('pathname').should('eq', '/login');
cy.getByTestId('toolbar').should('contain', 'Join');
});
});
describe('multi account', () => {
describe('multi account', () => {
it('should allow sign in with another account', () => {
cy.login({ accounts: ['default2'] });
@@ -249,4 +250,5 @@ describe('multi account', () => {
.click();
cy.get('[data-e2e-account-id]').should('have.length', 0);
});
});
});

View File

@@ -1,6 +1,7 @@
import { account1 } from '../../fixtures/accounts.json';
it('should send feedback', () => {
describe('feedback popup', () => {
it('should send feedback', () => {
const subject = 'Hello world';
const message = 'This is a feedback message';
@@ -48,4 +49,5 @@ it('should send feedback', () => {
cy.getByTestId('feedback-popup-close-button').click();
cy.getByTestId('feedbackPopup').should('not.be.visible');
});
});