Skip to content

Commit

Permalink
added test and updated example
Browse files Browse the repository at this point in the history
  • Loading branch information
andreadelrio committed May 13, 2020
1 parent faaa6ad commit 4adbc16
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 32 deletions.
29 changes: 11 additions & 18 deletions src-docs/src/views/expression/expression_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,11 @@ const stringingSnippet = `<div>
import Truncate from './truncate';
const truncateSource = require('!!raw-loader!./truncate');
const truncateHtml = renderToHtml(Truncate);
const truncateSnippet = `<div>
<EuiExpression
description="description1"
value={value1}
onClick={handleClick1}
/>
<EuiExpression
description="description2"
value={value2}
onClick={handleClick2}
/>
</div>`;
const truncateSnippet = `<EuiExpression
description="description"
value={value}
truncate={true}
/>`;

export const ExpressionExample = {
title: 'Expression',
Expand Down Expand Up @@ -144,12 +137,12 @@ export const ExpressionExample = {
],
text: (
<p>
For scenarios where you might want to truncate the text in{' '}
<strong>EuiExpression</strong>. You can opt for this option when space
is limited (e.g. a flyout) and/or when the value in{' '}
<strong>EuiExpression</strong> can be quite long. When truncating, you
can compliment <strong>EuiExpression</strong> with a{' '}
<strong>EuiToolTip</strong> displaying its full value.
There might be cases where you need to truncate the text, to do so use
the <EuiCode>truncate</EuiCode> prop. You can opt for this option when
space is limited and <strong>EuiExpression</strong>&apos;s value can
be quite long. When truncating, you can complement{' '}
<strong>EuiExpression</strong> with an <strong>EuiToolTip</strong>{' '}
displaying its full value.
</p>
),
snippet: truncateSnippet,
Expand Down
21 changes: 10 additions & 11 deletions src-docs/src/views/expression/truncate.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { Component, HTMLAttributes } from 'react';
import { CommonProps } from '../../../../src/components/common';
import { EuiExpression } from '../../../../src/components/expression';
import { EuiToolTip } from '../../../../src/components/tool_tip';
import { EuiPanel } from '../../../../src/components/panel';
Expand All @@ -9,7 +8,7 @@ import {
} from '../../../../src/components/popover';
import { EuiSelect } from '../../../../src/components/form/select';

export type TruncateProps = HTMLAttributes<HTMLDivElement> & CommonProps & {};
export type TruncateProps = HTMLAttributes<HTMLDivElement>;

interface TruncateState {
isOpen: boolean;
Expand Down Expand Up @@ -90,15 +89,15 @@ export default class extends Component<TruncateProps, TruncateState> {
);

return (
<EuiPanel
paddingSize="l"
style={{ paddingRight: '32px', width: '260px' }}>
{this.state.isOpen ? (
popOver
) : (
<EuiToolTip content={this.state.value}>{popOver}</EuiToolTip>
)}
</EuiPanel>
<div>
<EuiPanel paddingSize="l" style={{ width: '272px' }}>
{this.state.isOpen ? (
popOver
) : (
<EuiToolTip content={this.state.value}>{popOver}</EuiToolTip>
)}
</EuiPanel>
</div>
);
}
}
20 changes: 19 additions & 1 deletion src/components/expression/__snapshots__/expression.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,25 @@ exports[`EuiExpression props isActive true renders active 1`] = `
</span>
`;

exports[`EuiExpression props uppercase false renders inherted case 1`] = `
exports[`EuiExpression props truncate true truncates text 1`] = `
<span
class="euiExpression euiExpression-isUppercase euiExpression-isTruncate euiExpression--secondary"
>
<span
class="euiExpression__description"
>
the answer is
</span>
<span
class="euiExpression__value"
>
42
</span>
</span>
`;

exports[`EuiExpression props uppercase false renders inherited case 1`] = `
<span
class="euiExpression euiExpression--secondary"
>
Expand Down
3 changes: 2 additions & 1 deletion src/components/expression/_expression.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* but then wrap long words
*/
.euiExpression {
// @include euiTextBreakWord; /* 1 */
@include euiTextBreakWord; /* 1 */
@include euiFontSizeS;
@include euiCodeFont;

Expand All @@ -30,6 +30,7 @@

.euiExpression-isTruncate {
@include euiTextTruncate;
vertical-align: bottom;
}

.euiExpression-isClickable {
Expand Down
16 changes: 15 additions & 1 deletion src/components/expression/expression.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('EuiExpression', () => {
expect(render(component)).toMatchSnapshot();
});

test('false renders inherted case', () => {
test('false renders inherited case', () => {
const component = (
<EuiExpression
description="the answer is"
Expand All @@ -83,6 +83,20 @@ describe('EuiExpression', () => {
});
});

describe('truncate', () => {
test('true truncates text', () => {
const component = (
<EuiExpression
description="the answer is"
value="42"
truncate={true}
/>
);

expect(render(component)).toMatchSnapshot();
});
});

describe('isActive', () => {
test('true renders active', () => {
const component = (
Expand Down

0 comments on commit 4adbc16

Please sign in to comment.