Fix regressions found by cypress tests

This commit is contained in:
SleepWalker
2019-12-07 23:53:22 +02:00
parent 8734956c79
commit c82468333f
9 changed files with 36 additions and 23 deletions

View File

@@ -51,7 +51,7 @@ export class AccountSwitcher extends React.Component<Props> {
const activeAccount = getActiveAccount({ accounts }); const activeAccount = getActiveAccount({ accounts });
if (!activeAccount) { if (!activeAccount) {
throw new Error('Can not find active account'); return null;
} }
let { available } = accounts; let { available } = accounts;

View File

@@ -53,7 +53,9 @@ export default class BaseAuthBody extends React.Component<
renderErrors: false, renderErrors: false,
}); });
bindField = this.form.bindField.bind(this.form); bindField(name: string) {
return this.form.bindField(name);
}
serialize() { serialize() {
return this.form.serialize(); return this.form.serialize();

View File

@@ -1,6 +1,5 @@
import React from 'react'; import React from 'react';
import { AccountsState } from 'app/components/accounts'; import { AccountsState } from 'app/components/accounts';
import { AuthState } from 'app/components/auth';
import { User } from 'app/components/user'; import { User } from 'app/components/user';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
@@ -11,18 +10,18 @@ import {
PanelFooter, PanelFooter,
PanelHeader, PanelHeader,
} from 'app/components/ui/Panel'; } from 'app/components/ui/Panel';
import { getLogin } from 'app/components/auth/reducer';
import { Form } from 'app/components/ui/form'; import { Form } from 'app/components/ui/form';
import MeasureHeight from 'app/components/MeasureHeight'; import MeasureHeight from 'app/components/MeasureHeight';
import defaultHelpLinksStyles from 'app/components/auth/helpLinks.scss';
import panelStyles from 'app/components/ui/panel.scss'; import panelStyles from 'app/components/ui/panel.scss';
import icons from 'app/components/ui/icons.scss'; import icons from 'app/components/ui/icons.scss';
import authFlow from 'app/services/authFlow'; import authFlow from 'app/services/authFlow';
import { userShape } from 'app/components/user/User'; import { userShape } from 'app/components/user/User';
import * as actions from './actions';
import { RootState } from 'app/reducers'; import { RootState } from 'app/reducers';
import { getLogin, State as AuthState } from './reducer';
import * as actions from './actions';
import helpLinks from './helpLinks.scss';
const opacitySpringConfig = { stiffness: 300, damping: 20 }; const opacitySpringConfig = { stiffness: 300, damping: 20 };
const transformSpringConfig = { stiffness: 500, damping: 50, precision: 0.5 }; const transformSpringConfig = { stiffness: 500, damping: 50, precision: 0.5 };
const changeContextSpringConfig = { const changeContextSpringConfig = {
@@ -31,7 +30,7 @@ const changeContextSpringConfig = {
precision: 0.5, precision: 0.5,
}; };
const { helpLinksStyles } = defaultHelpLinksStyles; const { helpLinks: helpLinksStyles } = helpLinks;
type PanelId = string; type PanelId = string;

View File

@@ -11,7 +11,6 @@ import messages from './Register.intl.json';
// TODO: password and username can be validate for length and sameness // TODO: password and username can be validate for length and sameness
export default class RegisterBody extends BaseAuthBody { export default class RegisterBody extends BaseAuthBody {
static displayName = 'RegisterBody';
static panelId = 'register'; static panelId = 'register';
autoFocusField = 'username'; autoFocusField = 'username';

View File

@@ -7,11 +7,13 @@ import { omit } from 'app/functions';
import styles from './form.scss'; import styles from './form.scss';
import FormInputComponent from './FormInputComponent'; import FormInputComponent from './FormInputComponent';
export default class Checkbox extends FormInputComponent<{ export default class Checkbox extends FormInputComponent<
color: Color; React.InputHTMLAttributes<HTMLInputElement> & {
skin: Skin; color: Color;
label: string | MessageDescriptor; skin: Skin;
}> { label: string | MessageDescriptor | React.ReactElement;
}
> {
static defaultProps = { static defaultProps = {
color: COLOR_GREEN, color: COLOR_GREEN,
skin: SKIN_DARK, skin: SKIN_DARK,
@@ -23,7 +25,7 @@ export default class Checkbox extends FormInputComponent<{
const { color, skin } = this.props; const { color, skin } = this.props;
let { label } = this.props; let { label } = this.props;
label = this.formatMessage(label); label = React.isValidElement(label) ? label : this.formatMessage(label);
const props = omit(this.props, ['color', 'skin', 'label']); const props = omit(this.props, ['color', 'skin', 'label']);

View File

@@ -3,8 +3,9 @@ import { MessageDescriptor } from 'react-intl';
import FormComponent from './FormComponent'; import FormComponent from './FormComponent';
import FormError from './FormError'; import FormError from './FormError';
import { ValidationError } from './FormModel';
type Error = string | MessageDescriptor; type Error = ValidationError | MessageDescriptor;
export default class FormInputComponent<P, S = {}> extends FormComponent< export default class FormInputComponent<P, S = {}> extends FormComponent<
P & { P & {

View File

@@ -2,7 +2,7 @@ import FormInputComponent from './FormInputComponent';
type LoadingListener = (isLoading: boolean) => void; type LoadingListener = (isLoading: boolean) => void;
type ValidationError = export type ValidationError =
| string | string
| { | {
type: string; type: string;
@@ -37,10 +37,20 @@ export default class FormModel {
* *
* @returns {object} - ref and name props for component * @returns {object} - ref and name props for component
*/ */
bindField(name: string) { bindField(
name: string,
): {
name: string;
ref: (el: any) => void;
error?: ValidationError;
} {
this.fields[name] = {}; this.fields[name] = {};
const props: { [key: string]: any } = { const props: {
name: string;
ref: (el: any) => void;
error?: ValidationError;
} = {
name, name,
ref: (el: FormInputComponent<any> | null) => { ref: (el: FormInputComponent<any> | null) => {
if (el) { if (el) {
@@ -55,8 +65,10 @@ export default class FormModel {
}, },
}; };
if (this.renderErrors && this.getError(name)) { const error = this.getError(name);
props.error = this.getError(name);
if (this.renderErrors && error) {
props.error = error;
} }
return props; return props;

View File

@@ -19,7 +19,6 @@ export default class Input extends FormInputComponent<
disabled: boolean; disabled: boolean;
label?: string | MessageDescriptor; label?: string | MessageDescriptor;
placeholder?: string | MessageDescriptor; placeholder?: string | MessageDescriptor;
error?: string | { type: string; payload: string };
icon?: string; icon?: string;
copy?: boolean; copy?: boolean;
}, },

View File

@@ -20,7 +20,6 @@ export default class TextArea extends FormInputComponent<
{ {
placeholder?: string | MessageDescriptor; placeholder?: string | MessageDescriptor;
label?: string | MessageDescriptor; label?: string | MessageDescriptor;
error?: string;
skin: Skin; skin: Skin;
color: Color; color: Color;
} & TextareaAutosizeProps & } & TextareaAutosizeProps &