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

[Emotion] Pre-emptively fix/regression test form components with tricky className/css locations #6254

Merged
merged 4 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,7 @@ exports[`EuiBasicTable with initial selection 1`] = `
class="euiFlexItem euiFlexItem--flexGrowZero"
>
<div
class="euiCheckbox"
class="euiCheckbox emotion-euiCheckbox"
>
<input
aria-label="Select all rows"
Expand Down Expand Up @@ -1460,7 +1460,7 @@ exports[`EuiBasicTable with initial selection 1`] = `
class="euiTableCellContent"
>
<div
class="euiCheckbox euiCheckbox--inList euiCheckbox--noLabel"
class="euiCheckbox euiCheckbox--inList euiCheckbox--noLabel emotion-euiCheckbox"
>
<input
aria-label="Select all rows"
Expand Down Expand Up @@ -1510,7 +1510,7 @@ exports[`EuiBasicTable with initial selection 1`] = `
class="euiTableCellContent"
>
<div
class="euiCheckbox euiCheckbox--inList euiCheckbox--noLabel"
class="euiCheckbox euiCheckbox--inList euiCheckbox--noLabel emotion-euiCheckbox"
>
<input
aria-label="Select this row"
Expand Down Expand Up @@ -1555,7 +1555,7 @@ exports[`EuiBasicTable with initial selection 1`] = `
class="euiTableCellContent"
>
<div
class="euiCheckbox euiCheckbox--inList euiCheckbox--noLabel"
class="euiCheckbox euiCheckbox--inList euiCheckbox--noLabel emotion-euiCheckbox"
>
<input
aria-label="Select this row"
Expand Down Expand Up @@ -1600,7 +1600,7 @@ exports[`EuiBasicTable with initial selection 1`] = `
class="euiTableCellContent"
>
<div
class="euiCheckbox euiCheckbox--inList euiCheckbox--noLabel"
class="euiCheckbox euiCheckbox--inList euiCheckbox--noLabel emotion-euiCheckbox"
>
<input
aria-label="Select this row"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ exports[`EuiCheckableCard renders a checkbox when specified 1`] = `
class="euiPanel euiPanel--subdued euiPanel--paddingMedium euiSplitPanel__inner emotion-euiPanel-none-m-subdued-isClickable"
>
<div
class="euiCheckbox euiCheckbox--noLabel"
class="euiCheckbox euiCheckbox--noLabel emotion-euiCheckbox"
>
<input
aria-label="aria-label"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ exports[`useDataGridColumnSelector columnSelector renders a toolbar button/popov
class="euiFlexItem"
>
<div
class="euiSwitch euiSwitch--compressed euiSwitch--mini"
class="euiSwitch euiSwitch--compressed euiSwitch--mini emotion-euiSwitch"
>
<button
aria-checked="true"
Expand Down Expand Up @@ -174,7 +174,7 @@ exports[`useDataGridColumnSelector columnSelector renders a toolbar button/popov
class="euiFlexItem"
>
<div
class="euiSwitch euiSwitch--compressed euiSwitch--mini"
class="euiSwitch euiSwitch--compressed euiSwitch--mini emotion-euiSwitch"
>
<button
aria-checked="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`EuiCheckbox is rendered 1`] = `
<div
class="euiCheckbox euiCheckbox--noLabel testClass1 testClass2"
class="euiCheckbox euiCheckbox--noLabel testClass1 testClass2 emotion-euiCheckbox"
>
<input
aria-label="aria-label"
Expand All @@ -19,7 +19,7 @@ exports[`EuiCheckbox is rendered 1`] = `

exports[`EuiCheckbox props check is rendered 1`] = `
<div
class="euiCheckbox euiCheckbox--noLabel"
class="euiCheckbox euiCheckbox--noLabel emotion-euiCheckbox"
>
<input
checked=""
Expand All @@ -35,7 +35,7 @@ exports[`EuiCheckbox props check is rendered 1`] = `

exports[`EuiCheckbox props disabled disabled is rendered 1`] = `
<div
class="euiCheckbox euiCheckbox--noLabel"
class="euiCheckbox euiCheckbox--noLabel emotion-euiCheckbox"
>
<input
class="euiCheckbox__input"
Expand All @@ -51,7 +51,7 @@ exports[`EuiCheckbox props disabled disabled is rendered 1`] = `

exports[`EuiCheckbox props label is rendered 1`] = `
<div
class="euiCheckbox"
class="euiCheckbox emotion-euiCheckbox"
>
<input
class="euiCheckbox__input"
Expand All @@ -74,7 +74,7 @@ exports[`EuiCheckbox props label is rendered 1`] = `

exports[`EuiCheckbox props labelProps is rendered 1`] = `
<div
class="euiCheckbox"
class="euiCheckbox emotion-euiCheckbox"
>
<input
class="euiCheckbox__input"
Expand All @@ -97,7 +97,7 @@ exports[`EuiCheckbox props labelProps is rendered 1`] = `

exports[`EuiCheckbox props type inList is rendered 1`] = `
<div
class="euiCheckbox euiCheckbox--inList euiCheckbox--noLabel"
class="euiCheckbox euiCheckbox--inList euiCheckbox--noLabel emotion-euiCheckbox"
>
<input
class="euiCheckbox__input"
Expand Down
10 changes: 10 additions & 0 deletions src/components/form/checkbox/checkbox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
startThrowingReactWarnings,
stopThrowingReactWarnings,
} from '../../../test';
import { shouldRenderCustomStyles } from '../../../test/internal';

import { EuiCheckbox, TYPES } from './checkbox';

Expand All @@ -25,6 +26,15 @@ const checkboxRequiredProps = {
};

describe('EuiCheckbox', () => {
shouldRenderCustomStyles(
<EuiCheckbox {...checkboxRequiredProps} />,
{ skipStyles: true } // styles get applied to the nested input, not to the className wrapper
);
shouldRenderCustomStyles(
<EuiCheckbox {...checkboxRequiredProps} label="test" />,
{ childProps: ['labelProps'], skipParentTest: true }
);

test('is rendered', () => {
const component = render(
<EuiCheckbox id="id" onChange={() => {}} {...requiredProps} />
Expand Down
7 changes: 6 additions & 1 deletion src/components/form/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import React, {
InputHTMLAttributes,
LabelHTMLAttributes,
} from 'react';
import { css } from '@emotion/react';
import classNames from 'classnames';

import { keysOf, CommonProps } from '../../common';
Expand Down Expand Up @@ -67,6 +68,7 @@ export class EuiCheckbox extends Component<EuiCheckboxProps> {
render() {
const {
className,
css: customCss,
id,
checked,
label,
Expand Down Expand Up @@ -103,8 +105,11 @@ export class EuiCheckbox extends Component<EuiCheckboxProps> {
);
}

const styles = { euiCheckbox: css`` }; // TODO: Emotion conversion
const cssStyles = [styles.euiCheckbox, customCss];

return (
<div className={classes}>
<div css={cssStyles} className={classes}>
<input
className="euiCheckbox__input"
type="checkbox"
Expand Down
28 changes: 14 additions & 14 deletions src/components/form/range/__snapshots__/dual_range.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`EuiDualRange allows value prop to accept empty strings 1`] = `
<div
class="euiRangeWrapper euiDualRange"
class="euiRangeWrapper euiDualRange emotion-euiDualRange"
>
<div
aria-hidden="false"
Expand All @@ -24,7 +24,7 @@ exports[`EuiDualRange allows value prop to accept empty strings 1`] = `

exports[`EuiDualRange allows value prop to accept numbers 1`] = `
<div
class="euiRangeWrapper euiDualRange"
class="euiRangeWrapper euiDualRange emotion-euiDualRange"
>
<div
aria-hidden="false"
Expand Down Expand Up @@ -54,7 +54,7 @@ exports[`EuiDualRange allows value prop to accept numbers 1`] = `

exports[`EuiDualRange input props can be applied to min and max inputs 1`] = `
<div
class="euiRangeWrapper euiDualRange"
class="euiRangeWrapper euiDualRange emotion-euiDualRange"
>
<div
class="euiFormControlLayout"
Expand Down Expand Up @@ -129,7 +129,7 @@ exports[`EuiDualRange input props can be applied to min and max inputs 1`] = `

exports[`EuiDualRange is rendered 1`] = `
<div
class="euiRangeWrapper euiDualRange testClass1 testClass2"
class="euiRangeWrapper euiDualRange testClass1 testClass2 emotion-euiDualRange"
>
<div
aria-hidden="false"
Expand Down Expand Up @@ -162,7 +162,7 @@ exports[`EuiDualRange is rendered 1`] = `

exports[`EuiDualRange props compressed should render 1`] = `
<div
class="euiRangeWrapper euiRangeWrapper--compressed euiDualRange"
class="euiRangeWrapper euiRangeWrapper--compressed euiDualRange emotion-euiDualRange"
>
<div
aria-hidden="false"
Expand Down Expand Up @@ -192,7 +192,7 @@ exports[`EuiDualRange props compressed should render 1`] = `

exports[`EuiDualRange props custom ticks should render 1`] = `
<div
class="euiRangeWrapper euiDualRange"
class="euiRangeWrapper euiDualRange emotion-euiDualRange"
>
<div
aria-hidden="false"
Expand Down Expand Up @@ -251,7 +251,7 @@ exports[`EuiDualRange props custom ticks should render 1`] = `

exports[`EuiDualRange props disabled should render 1`] = `
<div
class="euiRangeWrapper euiDualRange"
class="euiRangeWrapper euiDualRange emotion-euiDualRange"
>
<div
aria-hidden="false"
Expand Down Expand Up @@ -282,7 +282,7 @@ exports[`EuiDualRange props disabled should render 1`] = `

exports[`EuiDualRange props fullWidth should render 1`] = `
<div
class="euiRangeWrapper euiRangeWrapper--fullWidth euiDualRange"
class="euiRangeWrapper euiRangeWrapper--fullWidth euiDualRange emotion-euiDualRange"
>
<div
aria-hidden="false"
Expand Down Expand Up @@ -312,7 +312,7 @@ exports[`EuiDualRange props fullWidth should render 1`] = `

exports[`EuiDualRange props inputs should render 1`] = `
<div
class="euiRangeWrapper euiDualRange testClass1 testClass2"
class="euiRangeWrapper euiDualRange testClass1 testClass2 emotion-euiDualRange"
>
<div
class="euiFormControlLayout"
Expand Down Expand Up @@ -389,7 +389,7 @@ exports[`EuiDualRange props inputs should render 1`] = `

exports[`EuiDualRange props isDraggable should render 1`] = `
<div
class="euiRangeWrapper euiDualRange"
class="euiRangeWrapper euiDualRange emotion-euiDualRange"
>
<div
aria-hidden="false"
Expand Down Expand Up @@ -419,7 +419,7 @@ exports[`EuiDualRange props isDraggable should render 1`] = `

exports[`EuiDualRange props labels should render 1`] = `
<div
class="euiRangeWrapper euiDualRange"
class="euiRangeWrapper euiDualRange emotion-euiDualRange"
>
<label
class="euiRangeLabel euiRangeLabel--min"
Expand Down Expand Up @@ -459,7 +459,7 @@ exports[`EuiDualRange props labels should render 1`] = `

exports[`EuiDualRange props levels should render 1`] = `
<div
class="euiRangeWrapper euiDualRange"
class="euiRangeWrapper euiDualRange emotion-euiDualRange"
>
<div
aria-hidden="false"
Expand Down Expand Up @@ -556,7 +556,7 @@ exports[`EuiDualRange props loading should display when showInput="inputWithPopo

exports[`EuiDualRange props range should render 1`] = `
<div
class="euiRangeWrapper euiDualRange"
class="euiRangeWrapper euiDualRange emotion-euiDualRange"
>
<div
aria-hidden="false"
Expand Down Expand Up @@ -632,7 +632,7 @@ exports[`EuiDualRange props slider should display in popover 1`] = `

exports[`EuiDualRange props ticks should render 1`] = `
<div
class="euiRangeWrapper euiDualRange"
class="euiRangeWrapper euiDualRange emotion-euiDualRange"
>
<div
aria-hidden="false"
Expand Down
10 changes: 10 additions & 0 deletions src/components/form/range/dual_range.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import React from 'react';
import { render } from 'enzyme';
import { requiredProps } from '../../../test/required_props';
import { shouldRenderCustomStyles } from '../../../test/internal';

import { EuiDualRange } from './dual_range';

Expand All @@ -17,6 +18,15 @@ const props = {
};

describe('EuiDualRange', () => {
shouldRenderCustomStyles(
<EuiDualRange {...props} value={['1', '8']} />,
{ skipStyles: true } // styles get applied to the underlying slider instead of the className wrapper
);
shouldRenderCustomStyles(
<EuiDualRange {...props} value={['1', '8']} showInput />,
{ childProps: ['minInputProps', 'maxInputProps'], skipParentTest: true }
);

test('is rendered', () => {
const component = render(
<EuiDualRange
Expand Down
7 changes: 7 additions & 0 deletions src/components/form/range/dual_range.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import React, { Component } from 'react';
import { css } from '@emotion/react';
import classNames from 'classnames';

import { keys } from '../../../services';
Expand Down Expand Up @@ -501,6 +502,7 @@ export class EuiDualRange extends Component<EuiDualRangeProps> {
render() {
const {
className,
css: customCss,
compressed,
disabled,
fullWidth,
Expand Down Expand Up @@ -613,8 +615,13 @@ export class EuiDualRange extends Component<EuiDualRangeProps> {
this.state.rangeWidth
)
: { left: '0' };

const styles = { euiDualRange: css`` }; // TODO: Emotion conversion
const cssStyles = [styles.euiDualRange, customCss];

const theRange = (
<EuiRangeWrapper
css={cssStyles}
className={classes}
fullWidth={fullWidth}
compressed={compressed}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`EuiSwitch assigns automatically generated ID to label 1`] = `
<div
class="euiSwitch"
class="euiSwitch emotion-euiSwitch"
>
<button
aria-checked="false"
Expand Down Expand Up @@ -43,7 +43,7 @@ exports[`EuiSwitch assigns automatically generated ID to label 1`] = `

exports[`EuiSwitch is rendered 1`] = `
<div
class="euiSwitch testClass1 testClass2"
class="euiSwitch testClass1 testClass2 emotion-euiSwitch"
>
<button
aria-checked="false"
Expand Down Expand Up @@ -86,7 +86,7 @@ exports[`EuiSwitch is rendered 1`] = `

exports[`EuiSwitch labelProps is rendered 1`] = `
<div
class="euiSwitch"
class="euiSwitch emotion-euiSwitch"
>
<button
aria-checked="false"
Expand Down
Loading