Skip to content
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
@@ -0,0 +1,87 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import * as React from 'react';
import { mountWithIntl } from 'test_utils/enzyme_helpers';

import { TestProviders } from '../../../../mock';

import { ExitCodeDraggable } from './exit_code_draggable';

describe('ExitCodeDraggable', () => {
test('it renders the expected text and exit code, when both text and an endgameExitCode are provided', () => {
const wrapper = mountWithIntl(
<TestProviders>
<ExitCodeDraggable contextId="test" endgameExitCode="0" eventId="1" text="with exit code" />
</TestProviders>
);
expect(wrapper.text()).toEqual('with exit code0');
});

test('it returns an empty string when text is provided, but endgameExitCode is undefined', () => {
const wrapper = mountWithIntl(
<TestProviders>
<ExitCodeDraggable
contextId="test"
endgameExitCode={undefined}
eventId="1"
text="with exit code"
/>
</TestProviders>
);
expect(wrapper.text()).toEqual('');
});

test('it returns an empty string when text is provided, but endgameExitCode is null', () => {
const wrapper = mountWithIntl(
<TestProviders>
<ExitCodeDraggable
contextId="test"
endgameExitCode={null}
eventId="1"
text="with exit code"
/>
</TestProviders>
);
expect(wrapper.text()).toEqual('');
});

test('it returns an empty string when text is provided, but endgameExitCode is an empty string', () => {
const wrapper = mountWithIntl(
<TestProviders>
<ExitCodeDraggable contextId="test" endgameExitCode="" eventId="1" text="with exit code" />
</TestProviders>
);
expect(wrapper.text()).toEqual('');
});

test('it renders just the exit code when text is undefined', () => {
const wrapper = mountWithIntl(
<TestProviders>
<ExitCodeDraggable contextId="test" endgameExitCode="1" eventId="1" text={undefined} />
</TestProviders>
);
expect(wrapper.text()).toEqual('1');
});

test('it renders just the exit code when text is null', () => {
const wrapper = mountWithIntl(
<TestProviders>
<ExitCodeDraggable contextId="test" endgameExitCode="1" eventId="1" text={null} />
</TestProviders>
);
expect(wrapper.text()).toEqual('1');
});

test('it renders just the exit code when text is an empty string', () => {
const wrapper = mountWithIntl(
<TestProviders>
<ExitCodeDraggable contextId="test" endgameExitCode="1" eventId="1" text="" />
</TestProviders>
);
expect(wrapper.text()).toEqual('1');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import * as React from 'react';
import { mountWithIntl } from 'test_utils/enzyme_helpers';

import { TestProviders } from '../../../../mock';

import { FileDraggable } from './file_draggable';

describe('FileDraggable', () => {
test('it prefers fileName and filePath over endgameFileName and endgameFilePath when all of them are provided', () => {
const wrapper = mountWithIntl(
<TestProviders>
<FileDraggable
contextId="test"
endgameFileName="[endgameFileName]"
endgameFilePath="[endgameFilePath]"
eventId="1"
fileName="[fileName]"
filePath="[filePath]"
></FileDraggable>
</TestProviders>
);
expect(wrapper.text()).toEqual('[fileName]in[filePath]');
});

test('it returns an empty string when none of the files or paths are provided', () => {
const wrapper = mountWithIntl(
<TestProviders>
<FileDraggable
contextId="test"
endgameFileName={undefined}
endgameFilePath={undefined}
eventId="1"
fileName={undefined}
filePath={undefined}
></FileDraggable>
</TestProviders>
);
expect(wrapper.text()).toEqual('');
});

test('it renders just the endgameFileName if only endgameFileName is provided', () => {
const wrapper = mountWithIntl(
<TestProviders>
<FileDraggable
contextId="test"
endgameFileName="[endgameFileName]"
endgameFilePath={undefined}
eventId="1"
fileName={undefined}
filePath={undefined}
/>
</TestProviders>
);
expect(wrapper.text()).toEqual('[endgameFileName]');
});

test('it renders "in endgameFilePath" if only endgameFilePath is provided', () => {
const wrapper = mountWithIntl(
<TestProviders>
<FileDraggable
contextId="test"
endgameFileName={undefined}
endgameFilePath="[endgameFilePath]"
eventId="1"
fileName={undefined}
filePath={undefined}
/>
</TestProviders>
);
expect(wrapper.text()).toEqual('in[endgameFilePath]');
});

test('it renders just the filename if only fileName is provided', () => {
const wrapper = mountWithIntl(
<TestProviders>
<FileDraggable
contextId="test"
endgameFileName={undefined}
endgameFilePath={undefined}
eventId="1"
fileName="[fileName]"
filePath={undefined}
/>
</TestProviders>
);
expect(wrapper.text()).toEqual('[fileName]');
});

test('it renders "in filePath" if only filePath is provided', () => {
const wrapper = mountWithIntl(
<TestProviders>
<FileDraggable
contextId="test"
endgameFileName={undefined}
endgameFilePath={undefined}
eventId="1"
fileName={undefined}
filePath="[filePath]"
/>
</TestProviders>
);
expect(wrapper.text()).toEqual('in[filePath]');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export const FileDraggable = React.memo<Props>(
return null;
}

const fileNameIsKnown =
!isNillEmptyOrNotFinite(fileName) || !isNillEmptyOrNotFinite(endgameFileName);
const filePathIsKnown =
!isNillEmptyOrNotFinite(filePath) || !isNillEmptyOrNotFinite(endgameFilePath);

return (
<>
Expand All @@ -58,7 +58,7 @@ export const FileDraggable = React.memo<Props>(
</TokensFlexItem>
) : null}

{fileNameIsKnown && (
{filePathIsKnown && (
<TokensFlexItem data-test-subj="in" grow={false} component="span">
{i18n.IN}
</TokensFlexItem>
Expand Down
Loading