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

View File

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

View File

@@ -8,15 +8,16 @@ const defaults = {
scope: 'account_info,account_email', scope: 'account_info,account_email',
}; };
it('should complete oauth', () => { describe('OAuth', () => {
it('should complete oauth', () => {
cy.login({ accounts: ['default'] }); cy.login({ accounts: ['default'] });
cy.visit(`/oauth2/v1/ely?${new URLSearchParams(defaults)}`); cy.visit(`/oauth2/v1/ely?${new URLSearchParams(defaults)}`);
cy.url().should('equal', 'https://ely.by/'); cy.url().should('equal', 'https://ely.by/');
}); });
it('should restore previous oauthData if any', () => { it('should restore previous oauthData if any', () => {
localStorage.setItem( localStorage.setItem(
'oauthData', 'oauthData',
JSON.stringify({ JSON.stringify({
@@ -37,9 +38,9 @@ it('should restore previous oauthData if any', () => {
cy.visit('/'); cy.visit('/');
cy.url().should('equal', 'https://ely.by/'); 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( cy.login({ accounts: ['default', 'default2'] }).then(
({ accounts: [account] }) => { ({ accounts: [account] }) => {
cy.visit(`/oauth2/v1/ely?${new URLSearchParams(defaults)}`); 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/'); cy.url().should('equal', 'https://ely.by/');
}, },
); );
}); });
// TODO: remove api mocks, when we will be able to revoke permissions // TODO: remove api mocks, when we will be able to revoke permissions
it('should prompt for permissions', () => { it('should prompt for permissions', () => {
cy.server(); cy.server();
cy.route({ cy.route({
@@ -95,9 +96,9 @@ it('should prompt for permissions', () => {
.click(); .click();
cy.url().should('match', /^http:\/\/localhost:8080\/?\?code=[^&]+&state=$/); 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.visit(`/oauth2/v1/ely?${new URLSearchParams(defaults)}`);
cy.url().should('include', '/login'); 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.get('[name=password]').type(`${account1.password}{enter}`);
cy.url().should('equal', 'https://ely.by/'); cy.url().should('equal', 'https://ely.by/');
}); });
// TODO: enable, when backend api will return correct response on auth decline // TODO: enable, when backend api will return correct response on auth decline
xit('should redirect to error page, when permission request declined', () => { xit('should redirect to error page, when permission request declined', () => {
cy.server(); cy.server();
cy.route({ cy.route({
@@ -149,9 +150,9 @@ xit('should redirect to error page, when permission request declined', () => {
.click(); .click();
cy.url().should('include', 'error=access_denied'); 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', () => { it('should automatically choose account, when id in login_hint is present', () => {
cy.login({ accounts: ['default', 'default2'] }).then( cy.login({ accounts: ['default', 'default2'] }).then(
({ accounts: [account] }) => { ({ accounts: [account] }) => {
@@ -205,9 +206,9 @@ describe('login_hint', () => {
}, },
); );
}); });
}); });
describe('prompts', () => { describe('prompts', () => {
it('should prompt for account', () => { it('should prompt for account', () => {
cy.login({ accounts: ['default'] }).then(({ accounts: [account] }) => { cy.login({ accounts: ['default'] }).then(({ accounts: [account] }) => {
cy.visit( cy.visit(
@@ -274,7 +275,10 @@ describe('prompts', () => {
.contains('Approve') .contains('Approve')
.click(); .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 // TODO: enable, when backend api will return correct response on auth decline
@@ -355,11 +359,14 @@ describe('prompts', () => {
.contains('Approve') .contains('Approve')
.click(); .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', () => { it('should authenticate using static page', () => {
cy.login({ accounts: ['default'] }); cy.login({ accounts: ['default'] });
@@ -403,9 +410,9 @@ describe('static pages', () => {
force: true, force: true,
}); });
}); });
}); });
function assertPermissions() { function assertPermissions() {
cy.url().should('include', '/oauth/permissions'); cy.url().should('include', '/oauth/permissions');
cy.getByTestId('auth-header').should('contain', 'Application permissions'); cy.getByTestId('auth-header').should('contain', 'Application permissions');
@@ -417,4 +424,5 @@ function assertPermissions() {
'contain', 'contain',
'Access to your Email address', '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 username = `test${Date.now()}`;
const email = `${Date.now()}@gmail.com`; const email = `${Date.now()}@gmail.com`;
const password = String(Date.now()); const password = String(Date.now());
@@ -73,9 +74,9 @@ it('should register', () => {
.should('eq', `key=${activationKey}`); .should('eq', `key=${activationKey}`);
cy.location('pathname').should('eq', '/'); cy.location('pathname').should('eq', '/');
}); });
it('should allow activation', () => { it('should allow activation', () => {
const activationKey = 'activationKey'; const activationKey = 'activationKey';
cy.server(); cy.server();
@@ -105,9 +106,9 @@ it('should allow activation', () => {
.should('eq', `key=${activationKey}`); .should('eq', `key=${activationKey}`);
cy.location('pathname').should('eq', '/'); cy.location('pathname').should('eq', '/');
}); });
it('should allow resend code', () => { it('should allow resend code', () => {
const email = `${Date.now()}@gmail.com`; const email = `${Date.now()}@gmail.com`;
const captchaCode = 'captchaCode'; const captchaCode = 'captchaCode';
@@ -142,4 +143,5 @@ it('should allow resend code', () => {
); );
cy.location('pathname').should('eq', '/activation'); cy.location('pathname').should('eq', '/activation');
});
}); });

View File

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

View File

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