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

feat: Press Enter key can trigger the Login button #1472

Merged
merged 7 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 3 additions & 1 deletion web/cypress/fixtures/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@
"updateSuccessfully": "Update Configuration Successfully",
"deleteSSLSuccess": "Remove target SSL successfully",
"sslErrorAlert": "key and cert don't match",
"pluginErrorAlert": "Invalid plugin data"
"pluginErrorAlert": "Invalid plugin data",
"successfully": "Successfully",
juzhiyuan marked this conversation as resolved.
Show resolved Hide resolved
"user": "user"
juzhiyuan marked this conversation as resolved.
Show resolved Hide resolved
}
6 changes: 5 additions & 1 deletion web/cypress/fixtures/selector.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,9 @@
"grafanaURL": "#grafanaURL",
"explain": ".ant-form-item-explain",

"upstreamType": ".ant-select-item-option-content"
"upstreamType": ".ant-select-item-option-content",

"errorExplain": ".ant-form-item-explain",
"usernameInput": "#control-ref_username",
"passwordInput": "#control-ref_password"
}
31 changes: 20 additions & 11 deletions web/cypress/integration/user/login.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,37 @@ context('Login Test', () => {
beforeEach(() => {
// set default language
localStorage.setItem('umi_locale', 'en-US');
cy.fixture('selector.json').as('domSelector');
cy.fixture('data.json').as('data');
});

it('login failed with empty username and password', () => {
it('login failed with empty username and password', function () {
cy.visit('/user/Login');
cy.contains('Login').click();
cy.get('.ant-form-item-explain').should('contain', 'Please input username');
cy.get('.ant-form-item-explain').should('contain', 'Please input password');
cy.get(this.domSelector.errorExplain).should('contain', 'Please input username');
cy.get(this.domSelector.errorExplain).should('contain', 'Please input password');
});

it('login with invalid credentials', () => {
it('login with invalid credentials', function () {
cy.visit('/user/Login');
cy.get('#control-ref_username').type('user');
cy.get('#control-ref_password').type('invalidPassword');
cy.get(this.domSelector.usernameInput).type(this.data.user);
cy.get(this.domSelector.passwordInput).type('invalidPassword');
cy.contains('Login').click();
cy.get('.ant-notification-notice-message').should('contain', 'Request Error Code: 10000');
cy.get(this.domSelector.notification).should('contain', 'Request Error Code: 10000');
});

it('login success', () => {
it('login success', function () {
cy.visit('/user/Login');
cy.get('#control-ref_username').type('user');
cy.get('#control-ref_password').type('user');
cy.get(this.domSelector.usernameInput).type(this.data.user);
cy.get(this.domSelector.passwordInput).type(this.data.user);
cy.contains('Login').click();
cy.get('.ant-notification-notice-message').should('contain', 'Successfully');
cy.get(this.domSelector.notification).should('contain', this.data.successfully);
});

it('should press Enter to login successfully', function () {
cy.visit('/user/Login');
cy.get(this.domSelector.usernameInput).type(this.data.user);
cy.get(this.domSelector.passwordInput).type('user{enter}');
cy.get(this.domSelector.notification).should('contain', this.data.successfully);
});
});
8 changes: 7 additions & 1 deletion web/src/pages/User/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ const Page: React.FC = () => {
});
};

const onKeyDown = (event: React.KeyboardEvent) => {
if (event.key === 'Enter') {
onSubmit();
}
}

if (localStorage.getItem('token')) {
history.replace('/');
return null;
Expand All @@ -99,7 +105,7 @@ const Page: React.FC = () => {
</div>
</div>
<div className={styles.main}>
<Tabs activeKey={loginMethod.id} onChange={onTabChange}>
<Tabs activeKey={loginMethod.id} onChange={onTabChange} onKeyDown={onKeyDown}>
{loginMethods.map((item) => (
<Tab key={item.id} tab={item.name}>
{item.render()}
Expand Down