mirror of
				https://github.com/elyby/accounts-frontend.git
				synced 2025-05-31 14:11:58 +05:30 
			
		
		
		
	Cover forgot password with e2e tests
This commit is contained in:
		@@ -298,7 +298,7 @@ class PanelTransition extends React.PureComponent<Props, State> {
 | 
				
			|||||||
                </Panel>
 | 
					                </Panel>
 | 
				
			||||||
                <div
 | 
					                <div
 | 
				
			||||||
                  className={helpLinksStyles}
 | 
					                  className={helpLinksStyles}
 | 
				
			||||||
                  data-testid="auth-secondary-controls"
 | 
					                  data-testid="auth-controls-secondary"
 | 
				
			||||||
                >
 | 
					                >
 | 
				
			||||||
                  {panels.map(config => this.getLinks(config))}
 | 
					                  {panels.map(config => this.getLinks(config))}
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -48,10 +48,14 @@ export default class ForgotPasswordBody extends BaseAuthBody {
 | 
				
			|||||||
            />
 | 
					            />
 | 
				
			||||||
          </div>
 | 
					          </div>
 | 
				
			||||||
        ) : (
 | 
					        ) : (
 | 
				
			||||||
          <div>
 | 
					          <div data-testid="forgot-password-login">
 | 
				
			||||||
            <div className={styles.login}>
 | 
					            <div className={styles.login}>
 | 
				
			||||||
              {login}
 | 
					              {login}
 | 
				
			||||||
              <span className={styles.editLogin} onClick={this.onClickEdit} />
 | 
					              <span
 | 
				
			||||||
 | 
					                className={styles.editLogin}
 | 
				
			||||||
 | 
					                onClick={this.onClickEdit}
 | 
				
			||||||
 | 
					                data-testid="edit-login"
 | 
				
			||||||
 | 
					              />
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
            <p className={styles.descriptionText}>
 | 
					            <p className={styles.descriptionText}>
 | 
				
			||||||
              <Message {...messages.pleasePressButton} />
 | 
					              <Message {...messages.pleasePressButton} />
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -58,7 +58,7 @@ export class ContactForm extends React.Component<
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
      <div
 | 
					      <div
 | 
				
			||||||
        data-e2e="feedbackPopup"
 | 
					        data-testid="feedbackPopup"
 | 
				
			||||||
        className={
 | 
					        className={
 | 
				
			||||||
          isSuccessfullySent ? styles.successState : styles.contactForm
 | 
					          isSuccessfullySent ? styles.successState : styles.contactForm
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -71,6 +71,7 @@ export class ContactForm extends React.Component<
 | 
				
			|||||||
            <span
 | 
					            <span
 | 
				
			||||||
              className={clsx(icons.close, popupStyles.close)}
 | 
					              className={clsx(icons.close, popupStyles.close)}
 | 
				
			||||||
              onClick={onClose}
 | 
					              onClick={onClose}
 | 
				
			||||||
 | 
					              data-testid="feedback-popup-close"
 | 
				
			||||||
            />
 | 
					            />
 | 
				
			||||||
          </div>
 | 
					          </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										216
									
								
								tests-e2e/cypress/integration/auth/forgot-password.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										216
									
								
								tests-e2e/cypress/integration/auth/forgot-password.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,216 @@
 | 
				
			|||||||
 | 
					import { account1 } from '../../fixtures/accounts.json';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					it('should request password reset', () => {
 | 
				
			||||||
 | 
					  const captchaCode = 'captchaCode';
 | 
				
			||||||
 | 
					  const emailMask = 'fo*@gm*l.**m';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.server();
 | 
				
			||||||
 | 
					  cy.route({
 | 
				
			||||||
 | 
					    method: 'POST',
 | 
				
			||||||
 | 
					    url: '/api/authentication/forgot-password',
 | 
				
			||||||
 | 
					    response: {
 | 
				
			||||||
 | 
					      success: true,
 | 
				
			||||||
 | 
					      data: {
 | 
				
			||||||
 | 
					        emailMask,
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					  }).as('forgot');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.visit('/');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.get('[name=login]').type(`${account1.username}{enter}`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.location('pathname').should('eq', '/password');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.getByTestId('auth-controls-secondary')
 | 
				
			||||||
 | 
					    .contains('Forgot password')
 | 
				
			||||||
 | 
					    .click();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.location('pathname').should('eq', '/forgot-password');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.getByTestId('forgot-password-login').should('contain', account1.username);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.window().should('have.property', 'e2eCaptchaSetCode');
 | 
				
			||||||
 | 
					  cy.window().then(win => {
 | 
				
			||||||
 | 
					    // fake captcha response
 | 
				
			||||||
 | 
					    // @ts-ignore
 | 
				
			||||||
 | 
					    win.e2eCaptchaSetCode(captchaCode);
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  cy.get('[type=submit]')
 | 
				
			||||||
 | 
					    .should('have.length', 1)
 | 
				
			||||||
 | 
					    .click();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.wait('@forgot')
 | 
				
			||||||
 | 
					    .its('requestBody')
 | 
				
			||||||
 | 
					    .should(
 | 
				
			||||||
 | 
					      'eq',
 | 
				
			||||||
 | 
					      new URLSearchParams({
 | 
				
			||||||
 | 
					        login: account1.username,
 | 
				
			||||||
 | 
					        captcha: captchaCode,
 | 
				
			||||||
 | 
					      }).toString(),
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.location('pathname').should('eq', '/recover-password');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.getByTestId('auth-body').should('contain', emailMask);
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					it('should allow change login', () => {
 | 
				
			||||||
 | 
					  const captchaCode = 'captchaCode';
 | 
				
			||||||
 | 
					  const login = 'foo';
 | 
				
			||||||
 | 
					  const emailMask = 'fo*@gm*l.**m';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.server();
 | 
				
			||||||
 | 
					  cy.route({
 | 
				
			||||||
 | 
					    method: 'POST',
 | 
				
			||||||
 | 
					    url: '/api/authentication/forgot-password',
 | 
				
			||||||
 | 
					    response: {
 | 
				
			||||||
 | 
					      success: true,
 | 
				
			||||||
 | 
					      data: {
 | 
				
			||||||
 | 
					        emailMask,
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					  }).as('forgot');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.visit('/');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.get('[name=login]').type(`${account1.username}{enter}`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.location('pathname').should('eq', '/password');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.getByTestId('auth-controls-secondary')
 | 
				
			||||||
 | 
					    .contains('Forgot password')
 | 
				
			||||||
 | 
					    .click();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.location('pathname').should('eq', '/forgot-password');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.getByTestId('edit-login').click();
 | 
				
			||||||
 | 
					  cy.get('[name=login]').should('have.value', account1.username);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.get('[name=login]').type(`{selectall}${login}`);
 | 
				
			||||||
 | 
					  cy.window().should('have.property', 'e2eCaptchaSetCode');
 | 
				
			||||||
 | 
					  cy.window().then(win => {
 | 
				
			||||||
 | 
					    // fake captcha response
 | 
				
			||||||
 | 
					    // @ts-ignore
 | 
				
			||||||
 | 
					    win.e2eCaptchaSetCode(captchaCode);
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  cy.get('[type=submit]')
 | 
				
			||||||
 | 
					    .should('have.length', 1)
 | 
				
			||||||
 | 
					    .click();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.wait('@forgot')
 | 
				
			||||||
 | 
					    .its('requestBody')
 | 
				
			||||||
 | 
					    .should(
 | 
				
			||||||
 | 
					      'eq',
 | 
				
			||||||
 | 
					      new URLSearchParams({
 | 
				
			||||||
 | 
					        login,
 | 
				
			||||||
 | 
					        captcha: captchaCode,
 | 
				
			||||||
 | 
					      }).toString(),
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.location('pathname').should('eq', '/recover-password');
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					it('should allow enter login', () => {
 | 
				
			||||||
 | 
					  const captchaCode = 'captchaCode';
 | 
				
			||||||
 | 
					  const login = 'foo';
 | 
				
			||||||
 | 
					  const emailMask = 'fo*@gm*l.**m';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.server();
 | 
				
			||||||
 | 
					  cy.route({
 | 
				
			||||||
 | 
					    method: 'POST',
 | 
				
			||||||
 | 
					    url: '/api/authentication/forgot-password',
 | 
				
			||||||
 | 
					    response: {
 | 
				
			||||||
 | 
					      success: true,
 | 
				
			||||||
 | 
					      data: {
 | 
				
			||||||
 | 
					        emailMask,
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					  }).as('forgot');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.visit('/forgot-password');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.get('[name=login]').type(login);
 | 
				
			||||||
 | 
					  cy.window().should('have.property', 'e2eCaptchaSetCode');
 | 
				
			||||||
 | 
					  cy.window().then(win => {
 | 
				
			||||||
 | 
					    // fake captcha response
 | 
				
			||||||
 | 
					    // @ts-ignore
 | 
				
			||||||
 | 
					    win.e2eCaptchaSetCode(captchaCode);
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  cy.get('[type=submit]')
 | 
				
			||||||
 | 
					    .should('have.length', 1)
 | 
				
			||||||
 | 
					    .click();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.wait('@forgot')
 | 
				
			||||||
 | 
					    .its('requestBody')
 | 
				
			||||||
 | 
					    .should(
 | 
				
			||||||
 | 
					      'eq',
 | 
				
			||||||
 | 
					      new URLSearchParams({
 | 
				
			||||||
 | 
					        login,
 | 
				
			||||||
 | 
					        captcha: captchaCode,
 | 
				
			||||||
 | 
					      }).toString(),
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.location('pathname').should('eq', '/recover-password');
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					it('should recover password', () => {
 | 
				
			||||||
 | 
					  const key = 'key';
 | 
				
			||||||
 | 
					  const newPassword = 'newPassword';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.server();
 | 
				
			||||||
 | 
					  cy.login({
 | 
				
			||||||
 | 
					    accounts: ['default'],
 | 
				
			||||||
 | 
					    updateState: false,
 | 
				
			||||||
 | 
					    rawApiResp: true,
 | 
				
			||||||
 | 
					  }).then(({ accounts: [account] }) => {
 | 
				
			||||||
 | 
					    cy.route({
 | 
				
			||||||
 | 
					      method: 'POST',
 | 
				
			||||||
 | 
					      url: '/api/authentication/recover-password',
 | 
				
			||||||
 | 
					      response: account,
 | 
				
			||||||
 | 
					    }).as('recover');
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.visit('/');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.get('[name=login]').type(`${account1.username}{enter}`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.location('pathname').should('eq', '/password');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.getByTestId('auth-controls-secondary')
 | 
				
			||||||
 | 
					    .contains('Forgot password')
 | 
				
			||||||
 | 
					    .click();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.location('pathname').should('eq', '/forgot-password');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.getByTestId('auth-controls-secondary')
 | 
				
			||||||
 | 
					    .contains('Already have')
 | 
				
			||||||
 | 
					    .click();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.location('pathname').should('eq', '/recover-password');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.getByTestId('auth-controls-secondary')
 | 
				
			||||||
 | 
					    .contains('Contact support')
 | 
				
			||||||
 | 
					    .click();
 | 
				
			||||||
 | 
					  cy.getByTestId('feedbackPopup').should('be.visible');
 | 
				
			||||||
 | 
					  cy.getByTestId('feedback-popup-close').click();
 | 
				
			||||||
 | 
					  cy.getByTestId('feedbackPopup').should('not.be.visible');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.get('[name=key]').type(key);
 | 
				
			||||||
 | 
					  cy.get('[name=newPassword]').type(newPassword);
 | 
				
			||||||
 | 
					  cy.get('[name=newRePassword]').type(newPassword);
 | 
				
			||||||
 | 
					  cy.get('[type=submit]')
 | 
				
			||||||
 | 
					    .should('have.length', 1)
 | 
				
			||||||
 | 
					    .click();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  cy.wait('@recover')
 | 
				
			||||||
 | 
					    .its('requestBody')
 | 
				
			||||||
 | 
					    .should(
 | 
				
			||||||
 | 
					      'eq',
 | 
				
			||||||
 | 
					      new URLSearchParams({
 | 
				
			||||||
 | 
					        key,
 | 
				
			||||||
 | 
					        newPassword,
 | 
				
			||||||
 | 
					        newRePassword: newPassword,
 | 
				
			||||||
 | 
					      }).toString(),
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
@@ -92,7 +92,7 @@ it('should allow activation', () => {
 | 
				
			|||||||
  });
 | 
					  });
 | 
				
			||||||
  cy.visit('/register');
 | 
					  cy.visit('/register');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  cy.getByTestId('auth-secondary-controls')
 | 
					  cy.getByTestId('auth-controls-secondary')
 | 
				
			||||||
    .contains('Already have')
 | 
					    .contains('Already have')
 | 
				
			||||||
    .click();
 | 
					    .click();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -119,7 +119,7 @@ it('should allow resend code', () => {
 | 
				
			|||||||
  }).as('resend');
 | 
					  }).as('resend');
 | 
				
			||||||
  cy.visit('/register');
 | 
					  cy.visit('/register');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  cy.getByTestId('auth-secondary-controls')
 | 
					  cy.getByTestId('auth-controls-secondary')
 | 
				
			||||||
    .contains('not received')
 | 
					    .contains('not received')
 | 
				
			||||||
    .click();
 | 
					    .click();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,6 +23,6 @@ describe('/dev/applications - guest', () => {
 | 
				
			|||||||
    cy.visit('/dev/applications');
 | 
					    cy.visit('/dev/applications');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    cy.get('[data-e2e-content] [data-e2e-button="feedbackPopup"]').click();
 | 
					    cy.get('[data-e2e-content] [data-e2e-button="feedbackPopup"]').click();
 | 
				
			||||||
    cy.get('[data-e2e="feedbackPopup"]').should('be.visible');
 | 
					    cy.getByTestId('feedbackPopup').should('be.visible');
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -105,7 +105,7 @@ xit('should redirect to error page, when permission request declined', () => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  cy.server({ enable: false });
 | 
					  cy.server({ enable: false });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  cy.getByTestId('auth-secondary-controls')
 | 
					  cy.getByTestId('auth-controls-secondary')
 | 
				
			||||||
    .contains('Decline')
 | 
					    .contains('Decline')
 | 
				
			||||||
    .click();
 | 
					    .click();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -220,7 +220,7 @@ describe('prompts', () => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    cy.url().should('include', '/oauth/permissions');
 | 
					    cy.url().should('include', '/oauth/permissions');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    cy.getByTestId('auth-secondary-controls')
 | 
					    cy.getByTestId('auth-controls-secondary')
 | 
				
			||||||
      .contains('Decline')
 | 
					      .contains('Decline')
 | 
				
			||||||
      .click();
 | 
					      .click();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user