Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactored test login.spec.js #1881

Merged
merged 3 commits into from
May 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions web/cypress/integration/user/login.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,55 @@
/* eslint-disable no-undef */

context('Login Test', () => {
const selector = {
errorExplain: '.ant-form-item-explain',
usernameInput: '#control-ref_username',
passwordInput: '#control-ref_password',
notification: '.ant-notification-notice-message',
};

liuxiran marked this conversation as resolved.
Show resolved Hide resolved
const data = {
usernamePlaceholder: 'Please input username',
passwordPlaceholder: 'Please input password',
username: 'user',
password: 'user',
invalidPassword: 'invalidPassword',
errorCode: 'Request Error Code: 10000',
successMessage: 'Successfully',
};

beforeEach(() => {
// set default language
localStorage.setItem('umi_locale', 'en-US');
cy.fixture('selector.json').as('domSelector');
});

it('login failed with empty username and password', function () {
cy.visit('/user/Login');
cy.contains('Login').click();
cy.get(this.domSelector.errorExplain).should('contain', 'Please input username');
cy.get(this.domSelector.errorExplain).should('contain', 'Please input password');
cy.get(selector.errorExplain).should('contain', data.usernamePlaceholder);
cy.get(selector.errorExplain).should('contain', data.passwordPlaceholder);
});

it('login with invalid credentials', function () {
cy.visit('/user/Login');
cy.get(this.domSelector.usernameInput).type('user');
cy.get(this.domSelector.passwordInput).type('invalidPassword');
cy.get(selector.usernameInput).type(data.username);
cy.get(selector.passwordInput).type(data.invalidPassword);
cy.contains('Login').click();
cy.get(this.domSelector.notification).should('contain', 'Request Error Code: 10000');
cy.get(selector.notification).should('contain', data.errorCode);
});

it('login success', function () {
cy.visit('/user/Login');
cy.get(this.domSelector.usernameInput).type('user');
cy.get(this.domSelector.passwordInput).type('user');
cy.get(selector.usernameInput).type(data.username);
cy.get(selector.passwordInput).type(data.password);
cy.contains('Login').click();
cy.get(this.domSelector.notification).should('contain', 'Successfully');
cy.get(selector.notification).should('contain', data.successMessage);
});

it('should press Enter to login successfully', function () {
cy.visit('/user/Login');
cy.get(this.domSelector.usernameInput).type('user');
cy.get(this.domSelector.passwordInput).type('user{enter}');
cy.get(this.domSelector.notification).should('contain', 'Successfully');
cy.get(selector.usernameInput).type(data.username);
cy.get(selector.passwordInput).type(data.password).type('{enter}');
cy.get(selector.notification).should('contain', data.successMessage);
});
});