mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-23 21:49:54 +05:30
Fix signin and add more signin e2e tests cases
This commit is contained in:
parent
d9fc503f9e
commit
f6f0aedc65
@ -69,7 +69,7 @@ class RootPage extends React.PureComponent<{
|
|||||||
[styles.isPopupActive]: isPopupActive,
|
[styles.isPopupActive]: isPopupActive,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<div className={styles.header} data-e2e-toolbar>
|
<div className={styles.header} data-testid="toolbar">
|
||||||
<div className={styles.headerContent}>
|
<div className={styles.headerContent}>
|
||||||
<Link to="/" className={styles.logo} onClick={onLogoClick}>
|
<Link to="/" className={styles.logo} onClick={onLogoClick}>
|
||||||
<Message {...messages.siteName} />
|
<Message {...messages.siteName} />
|
||||||
@ -90,7 +90,7 @@ class RootPage extends React.PureComponent<{
|
|||||||
<Route path="/dev" component={DevPage} />
|
<Route path="/dev" component={DevPage} />
|
||||||
|
|
||||||
{!user.isGuest && (
|
{!user.isGuest && (
|
||||||
<AuthFlowRoute exact path="/" component={ProfilePage} />
|
<PrivateRoute exact path="/" component={ProfilePage} />
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<AuthFlowRoute path="/" component={AuthPage} />
|
<AuthFlowRoute path="/" component={AuthPage} />
|
||||||
|
0
tests-e2e/cypress/integration/auth/register.test.ts
Normal file
0
tests-e2e/cypress/integration/auth/register.test.ts
Normal file
124
tests-e2e/cypress/integration/auth/sign-in.test.ts
Normal file
124
tests-e2e/cypress/integration/auth/sign-in.test.ts
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
import { account1 } from '../../fixtures/accounts.json';
|
||||||
|
|
||||||
|
it('should sign in', () => {
|
||||||
|
cy.visit('/');
|
||||||
|
|
||||||
|
cy.get('[name=login]').type(`${account1.login}{enter}`);
|
||||||
|
|
||||||
|
cy.url().should('include', '/password');
|
||||||
|
|
||||||
|
cy.get('[name=password]').type(account1.password);
|
||||||
|
cy.get('[name=rememberMe]').should('be.checked');
|
||||||
|
cy.get('[type=submit]').click();
|
||||||
|
|
||||||
|
cy.location('pathname').should('eq', '/');
|
||||||
|
|
||||||
|
cy.getByTestId('toolbar')
|
||||||
|
.contains(account1.username)
|
||||||
|
.should(() => {
|
||||||
|
const state = JSON.parse(localStorage.getItem('redux-storage') || '');
|
||||||
|
expect(state.accounts.available).to.have.length(1);
|
||||||
|
|
||||||
|
const [account] = state.accounts.available;
|
||||||
|
expect(account.username).to.be.equal(account1.username);
|
||||||
|
expect(account.id)
|
||||||
|
.to.be.a('number')
|
||||||
|
.and.to.be.gt(0);
|
||||||
|
expect(account.email)
|
||||||
|
.to.be.a('string')
|
||||||
|
.and.have.length.gt(0);
|
||||||
|
expect(account.token)
|
||||||
|
.to.be.a('string')
|
||||||
|
.and.have.length.gt(0);
|
||||||
|
expect(account.refreshToken)
|
||||||
|
.to.be.a('string')
|
||||||
|
.and.have.length.gt(0);
|
||||||
|
|
||||||
|
expect(state.accounts.active).to.be.equal(account.id);
|
||||||
|
|
||||||
|
const { user } = state;
|
||||||
|
expect(user.id).to.be.equal(account.id);
|
||||||
|
expect(user.username).to.be.equal(account.username);
|
||||||
|
expect(user.isGuest).to.be.false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should sign in without remember me', () => {
|
||||||
|
cy.visit('/');
|
||||||
|
|
||||||
|
cy.get('[name=login]').type(`${account1.login}{enter}`);
|
||||||
|
|
||||||
|
cy.url().should('include', '/password');
|
||||||
|
|
||||||
|
cy.get('[name=password]').type(account1.password);
|
||||||
|
cy.get('[name=rememberMe]')
|
||||||
|
.parent()
|
||||||
|
.click();
|
||||||
|
cy.get('[name=rememberMe]').should('not.be.checked');
|
||||||
|
cy.get('[type=submit]').click();
|
||||||
|
|
||||||
|
cy.location('pathname').should('eq', '/');
|
||||||
|
|
||||||
|
cy.getByTestId('toolbar')
|
||||||
|
.contains(account1.username)
|
||||||
|
.should(() => {
|
||||||
|
const state = JSON.parse(localStorage.getItem('redux-storage') || '');
|
||||||
|
expect(state.accounts.available).to.have.length(1);
|
||||||
|
|
||||||
|
const [account] = state.accounts.available;
|
||||||
|
expect(account.username).to.be.equal(account1.username);
|
||||||
|
expect(account.id)
|
||||||
|
.to.be.a('number')
|
||||||
|
.and.to.be.gt(0);
|
||||||
|
expect(account.email)
|
||||||
|
.to.be.a('string')
|
||||||
|
.and.have.length.gt(0);
|
||||||
|
expect(account.token)
|
||||||
|
.to.be.a('string')
|
||||||
|
.and.have.length.gt(0);
|
||||||
|
expect(account.refreshToken).eql(null);
|
||||||
|
|
||||||
|
expect(state.accounts.active).to.be.equal(account.id);
|
||||||
|
|
||||||
|
const { user } = state;
|
||||||
|
expect(user.id).to.be.equal(account.id);
|
||||||
|
expect(user.username).to.be.equal(account.username);
|
||||||
|
expect(user.isGuest).to.be.false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should sign in with totp', () => {
|
||||||
|
cy.visit('/');
|
||||||
|
|
||||||
|
cy.get('[name=login]').type(`${account1.login}{enter}`);
|
||||||
|
|
||||||
|
cy.url().should('include', '/password');
|
||||||
|
|
||||||
|
cy.server();
|
||||||
|
cy.route({
|
||||||
|
method: 'POST',
|
||||||
|
url: '/api/authentication/login',
|
||||||
|
response: {
|
||||||
|
success: false,
|
||||||
|
errors: { totp: 'error.totp_required' },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
cy.get('[name=password]').type(account1.password);
|
||||||
|
cy.get('[type=submit]').click();
|
||||||
|
|
||||||
|
cy.url().should('include', '/mfa');
|
||||||
|
|
||||||
|
cy.route({
|
||||||
|
method: 'POST',
|
||||||
|
url: '/api/authentication/login',
|
||||||
|
}).as('login');
|
||||||
|
|
||||||
|
cy.get('[name=totp]').type('123{enter}');
|
||||||
|
|
||||||
|
cy.wait('@login')
|
||||||
|
.its('requestBody')
|
||||||
|
.should('include', 'totp=123');
|
||||||
|
|
||||||
|
cy.location('pathname').should('eq', '/');
|
||||||
|
});
|
@ -55,7 +55,8 @@ describe("when user's token and refreshToken are invalid", () => {
|
|||||||
|
|
||||||
cy.url().should('include', '/password');
|
cy.url().should('include', '/password');
|
||||||
|
|
||||||
cy.get('[data-e2e-toolbar] a')
|
cy.getByTestId('toolbar')
|
||||||
|
.get('a')
|
||||||
.contains('Ely.by')
|
.contains('Ely.by')
|
||||||
.click();
|
.click();
|
||||||
|
|
||||||
@ -96,7 +97,7 @@ describe("when user's token and refreshToken are invalid", () => {
|
|||||||
|
|
||||||
cy.url().should('include', '/login');
|
cy.url().should('include', '/login');
|
||||||
|
|
||||||
cy.get('[data-e2e-toolbar]').contains('Join');
|
cy.getByTestId('toolbar').contains('Join');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow logout', () => {
|
it('should allow logout', () => {
|
||||||
@ -107,10 +108,10 @@ describe("when user's token and refreshToken are invalid", () => {
|
|||||||
`/api/v1/accounts/${account2.id}`,
|
`/api/v1/accounts/${account2.id}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
cy.get('[data-e2e-toolbar]')
|
cy.getByTestId('toolbar')
|
||||||
.contains(account2.username)
|
.contains(account2.username)
|
||||||
.click();
|
.click();
|
||||||
cy.get('[data-e2e-toolbar]')
|
cy.getByTestId('toolbar')
|
||||||
.contains('Log out')
|
.contains('Log out')
|
||||||
.click();
|
.click();
|
||||||
|
|
||||||
@ -118,10 +119,10 @@ describe("when user's token and refreshToken are invalid", () => {
|
|||||||
'be.calledWith',
|
'be.calledWith',
|
||||||
'/api/authentication/logout',
|
'/api/authentication/logout',
|
||||||
);
|
);
|
||||||
cy.get('[data-e2e-toolbar]')
|
cy.getByTestId('toolbar')
|
||||||
.contains(account2.email)
|
.contains(account2.email)
|
||||||
.should('not.exist');
|
.should('not.exist');
|
||||||
cy.get('[data-e2e-toolbar]')
|
cy.getByTestId('toolbar')
|
||||||
.contains(account2.username)
|
.contains(account2.username)
|
||||||
.should('not.exist');
|
.should('not.exist');
|
||||||
});
|
});
|
||||||
@ -167,7 +168,7 @@ describe("when user's token and refreshToken are invalid", () => {
|
|||||||
|
|
||||||
cy.url().should('include', '/login');
|
cy.url().should('include', '/login');
|
||||||
|
|
||||||
cy.get('[data-e2e-toolbar]').contains('a', 'Join');
|
cy.getByTestId('toolbar').contains('a', 'Join');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should ask for password if selected account with bad token', () => {
|
it('should ask for password if selected account with bad token', () => {
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
import { account1 } from '../fixtures/accounts.json';
|
|
||||||
|
|
||||||
describe('sign in', () => {
|
|
||||||
it('should sign in', () => {
|
|
||||||
cy.visit('/');
|
|
||||||
|
|
||||||
cy.get('[name=login]').type(`${account1.login}{enter}`);
|
|
||||||
|
|
||||||
cy.url().should('include', '/password');
|
|
||||||
|
|
||||||
cy.get('[name=password]').type(account1.password);
|
|
||||||
cy.get('[name=rememberMe]').should('be.checked');
|
|
||||||
cy.get('[type=submit]').click();
|
|
||||||
|
|
||||||
cy.location('pathname', { timeout: 15000 }).should('eq', '/');
|
|
||||||
|
|
||||||
cy.get('[data-e2e-toolbar]')
|
|
||||||
.contains(account1.username)
|
|
||||||
.should(() => {
|
|
||||||
const state = JSON.parse(localStorage.getItem('redux-storage') || '');
|
|
||||||
expect(state.accounts.available).to.have.length(1);
|
|
||||||
|
|
||||||
const [account] = state.accounts.available;
|
|
||||||
expect(account.username).to.be.equal(account1.username);
|
|
||||||
expect(account.id)
|
|
||||||
.to.be.a('number')
|
|
||||||
.and.to.be.gt(0);
|
|
||||||
expect(account.email)
|
|
||||||
.to.be.a('string')
|
|
||||||
.and.have.length.gt(0);
|
|
||||||
expect(account.token)
|
|
||||||
.to.be.a('string')
|
|
||||||
.and.have.length.gt(0);
|
|
||||||
expect(account.refreshToken)
|
|
||||||
.to.be.a('string')
|
|
||||||
.and.have.length.gt(0);
|
|
||||||
|
|
||||||
expect(state.accounts.active).to.be.equal(account.id);
|
|
||||||
|
|
||||||
const { user } = state;
|
|
||||||
expect(user.id).to.be.equal(account.id);
|
|
||||||
expect(user.username).to.be.equal(account.username);
|
|
||||||
expect(user.isGuest).to.be.false;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
Loading…
Reference in New Issue
Block a user