mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-01-12 23:02:16 +05:30
Add e2e tests for contact form
This commit is contained in:
parent
951f538ee5
commit
5d411fd6ca
@ -20,14 +20,14 @@ import { User } from 'app/components/user';
|
|||||||
import styles from './contactForm.scss';
|
import styles from './contactForm.scss';
|
||||||
import messages from './contactForm.intl.json';
|
import messages from './contactForm.intl.json';
|
||||||
|
|
||||||
const CONTACT_CATEGORIES = [
|
const CONTACT_CATEGORIES = {
|
||||||
// TODO: сюда позже проставить реальные id категорий с backend
|
// TODO: сюда позже проставить реальные id категорий с backend
|
||||||
<Message key="m1" {...messages.cannotAccessMyAccount} />,
|
0: <Message {...messages.cannotAccessMyAccount} />,
|
||||||
<Message key="m2" {...messages.foundBugOnSite} />,
|
1: <Message {...messages.foundBugOnSite} />,
|
||||||
<Message key="m3" {...messages.improvementsSuggestion} />,
|
2: <Message {...messages.improvementsSuggestion} />,
|
||||||
<Message key="m4" {...messages.integrationQuestion} />,
|
3: <Message {...messages.integrationQuestion} />,
|
||||||
<Message key="m5" {...messages.other} />,
|
4: <Message {...messages.other} />,
|
||||||
];
|
};
|
||||||
|
|
||||||
export class ContactForm extends React.Component<
|
export class ContactForm extends React.Component<
|
||||||
{
|
{
|
||||||
@ -161,7 +161,12 @@ export class ContactForm extends React.Component<
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={styles.footer}>
|
<div className={styles.footer}>
|
||||||
<Button label={messages.close} block onClick={onClose} />
|
<Button
|
||||||
|
label={messages.close}
|
||||||
|
block
|
||||||
|
onClick={onClose}
|
||||||
|
data-testid="feedback-popup-close-button"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -16,7 +16,7 @@ type Props = {
|
|||||||
class FooterMenu extends React.Component<Props> {
|
class FooterMenu extends React.Component<Props> {
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className={styles.footerMenu}>
|
<div className={styles.footerMenu} data-testid="footer">
|
||||||
<Link to="/rules">
|
<Link to="/rules">
|
||||||
<Message {...messages.rules} />
|
<Message {...messages.rules} />
|
||||||
</Link>
|
</Link>
|
||||||
|
@ -1,42 +1,38 @@
|
|||||||
import PropTypes from 'prop-types';
|
import React, { InputHTMLAttributes } from 'react';
|
||||||
import React from 'react';
|
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
|
import { MessageDescriptor } from 'react-intl';
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
|
import { COLOR_GREEN, Color } from 'app/components/ui';
|
||||||
import { omit } from 'app/functions';
|
|
||||||
import { colors, COLOR_GREEN } from 'app/components/ui';
|
|
||||||
|
|
||||||
import styles from './dropdown.scss';
|
import styles from './dropdown.scss';
|
||||||
import FormInputComponent from './FormInputComponent';
|
import FormInputComponent from './FormInputComponent';
|
||||||
|
|
||||||
export default class Dropdown extends FormInputComponent {
|
type I18nString = string | MessageDescriptor;
|
||||||
static displayName = 'Dropdown';
|
type ItemLabel = I18nString | React.ReactElement;
|
||||||
|
|
||||||
static propTypes = {
|
interface Props extends InputHTMLAttributes<HTMLInputElement> {
|
||||||
label: PropTypes.oneOfType([
|
label: I18nString;
|
||||||
PropTypes.shape({
|
items: { [value: string]: ItemLabel };
|
||||||
id: PropTypes.string,
|
block?: boolean;
|
||||||
}),
|
color: Color;
|
||||||
PropTypes.string,
|
}
|
||||||
]).isRequired,
|
|
||||||
items: PropTypes.arrayOf(
|
|
||||||
PropTypes.oneOfType([
|
|
||||||
PropTypes.string,
|
|
||||||
PropTypes.shape({
|
|
||||||
id: PropTypes.string,
|
|
||||||
}),
|
|
||||||
]),
|
|
||||||
).isRequired,
|
|
||||||
block: PropTypes.bool,
|
|
||||||
color: PropTypes.oneOf(colors),
|
|
||||||
};
|
|
||||||
|
|
||||||
static defaultProps = {
|
interface OptionItem {
|
||||||
|
label: ItemLabel;
|
||||||
|
value: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface State {
|
||||||
|
isActive: boolean;
|
||||||
|
activeItem: OptionItem | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class Dropdown extends FormInputComponent<Props, State> {
|
||||||
|
static defaultProps: Partial<Props> = {
|
||||||
color: COLOR_GREEN,
|
color: COLOR_GREEN,
|
||||||
};
|
};
|
||||||
|
|
||||||
state = {
|
state: State = {
|
||||||
isActive: false,
|
isActive: false,
|
||||||
activeItem: null,
|
activeItem: null,
|
||||||
};
|
};
|
||||||
@ -52,12 +48,15 @@ export default class Dropdown extends FormInputComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { color, block, items } = this.props;
|
const { color, block, items, ...restProps } = this.props;
|
||||||
const { isActive } = this.state;
|
const { isActive } = this.state;
|
||||||
|
|
||||||
|
delete restProps.label;
|
||||||
|
|
||||||
const activeItem = this.getActiveItem();
|
const activeItem = this.getActiveItem();
|
||||||
const label = this.formatMessage(activeItem.label);
|
const label = React.isValidElement(activeItem.label)
|
||||||
const props = omit(this.props, Object.keys(Dropdown.propTypes));
|
? activeItem.label
|
||||||
|
: this.formatMessage(activeItem.label);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@ -66,10 +65,13 @@ export default class Dropdown extends FormInputComponent {
|
|||||||
[styles.block]: block,
|
[styles.block]: block,
|
||||||
[styles.opened]: isActive,
|
[styles.opened]: isActive,
|
||||||
})}
|
})}
|
||||||
{...props}
|
data-e2e-select-name={restProps.name}
|
||||||
|
{...restProps}
|
||||||
onClick={this.onToggle}
|
onClick={this.onToggle}
|
||||||
>
|
>
|
||||||
<span className={styles.label}>{label}</span>
|
<span className={styles.label} data-testid="select-label">
|
||||||
|
{label}
|
||||||
|
</span>
|
||||||
<span className={styles.toggleIcon} />
|
<span className={styles.toggleIcon} />
|
||||||
|
|
||||||
<div className={styles.menu}>
|
<div className={styles.menu}>
|
||||||
@ -96,7 +98,7 @@ export default class Dropdown extends FormInputComponent {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onSelectItem(item) {
|
onSelectItem(item: OptionItem) {
|
||||||
return event => {
|
return event => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
@ -106,9 +108,9 @@ export default class Dropdown extends FormInputComponent {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
getActiveItem() {
|
getActiveItem(): OptionItem {
|
||||||
const { items } = this.props;
|
const { items } = this.props;
|
||||||
let { activeItem } = /** @type {any} */ (this.state);
|
let { activeItem } = this.state;
|
||||||
|
|
||||||
if (!activeItem) {
|
if (!activeItem) {
|
||||||
activeItem = {
|
activeItem = {
|
||||||
@ -130,20 +132,20 @@ export default class Dropdown extends FormInputComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getValue() {
|
getValue() {
|
||||||
return this.getActiveItem().value;
|
return this.getActiveItem()?.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
onToggle = event => {
|
onToggle = (event: React.MouseEvent<HTMLDivElement>) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
this.toggle();
|
this.toggle();
|
||||||
};
|
};
|
||||||
|
|
||||||
onBodyClick = event => {
|
onBodyClick = (event: MouseEvent) => {
|
||||||
if (this.state.isActive) {
|
if (this.state.isActive) {
|
||||||
const el = ReactDOM.findDOMNode(this);
|
const el = ReactDOM.findDOMNode(this);
|
||||||
|
|
||||||
if (!el.contains(event.target) && el !== event.taget) {
|
if (!el.contains(event.target) && el !== event.target) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
@ -2,6 +2,11 @@ import request from 'app/services/request';
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
send({ subject = '', email = '', message = '', category = '' }) {
|
send({ subject = '', email = '', message = '', category = '' }) {
|
||||||
return request.post('/api/feedback', { subject, email, message, category });
|
return request.post('/api/feedback', {
|
||||||
|
subject,
|
||||||
|
email,
|
||||||
|
message,
|
||||||
|
category,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
51
tests-e2e/cypress/integration/profile/feedback-popup.test.ts
Normal file
51
tests-e2e/cypress/integration/profile/feedback-popup.test.ts
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import { account1 } from '../../fixtures/accounts.json';
|
||||||
|
|
||||||
|
it('should send feedback', () => {
|
||||||
|
const subject = 'Hello world';
|
||||||
|
const message = 'This is a feedback message';
|
||||||
|
|
||||||
|
cy.server();
|
||||||
|
cy.route({
|
||||||
|
url: '/api/feedback',
|
||||||
|
method: 'POST',
|
||||||
|
response: { success: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
cy.login({ accounts: ['default'] });
|
||||||
|
|
||||||
|
cy.visit('/');
|
||||||
|
|
||||||
|
cy.getByTestId('footer')
|
||||||
|
.contains('Contact Us')
|
||||||
|
.click();
|
||||||
|
cy.getByTestId('feedbackPopup').should('be.visible');
|
||||||
|
|
||||||
|
cy.get('[name=subject]').type(subject);
|
||||||
|
cy.get('[name=email]').should('have.value', account1.email);
|
||||||
|
cy.get('[name=message]').type(message);
|
||||||
|
|
||||||
|
cy.get('[data-e2e-select-name=category]')
|
||||||
|
.getByTestId('select-label')
|
||||||
|
.should('contain', 'What are you interested');
|
||||||
|
cy.get('[data-e2e-select-name=category]').click();
|
||||||
|
cy.get('[data-e2e-select-name=category]')
|
||||||
|
.contains('bug')
|
||||||
|
.click();
|
||||||
|
cy.get('[data-e2e-select-name=category]')
|
||||||
|
.getByTestId('select-label')
|
||||||
|
.should('contain', 'bug');
|
||||||
|
|
||||||
|
cy.getByTestId('feedbackPopup')
|
||||||
|
.get('[type=submit]')
|
||||||
|
.click();
|
||||||
|
|
||||||
|
cy.getByTestId('feedbackPopup').should(
|
||||||
|
'contain',
|
||||||
|
'Your message was received',
|
||||||
|
);
|
||||||
|
cy.getByTestId('feedbackPopup').should('contain', account1.email);
|
||||||
|
|
||||||
|
cy.getByTestId('feedback-popup-close-button').click();
|
||||||
|
|
||||||
|
cy.getByTestId('feedbackPopup').should('not.be.visible');
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user