Skip to content

Commit

Permalink
fix: add missing files
Browse files Browse the repository at this point in the history
Signed-off-by: Olga Nad <[email protected]>
  • Loading branch information
olga-union committed May 16, 2022
1 parent b60709d commit 5a7ac73
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import { createMockNodeExecutions } from 'models/Execution/__mocks__/mockNodeExe
import { TaskType } from 'models/Task/constants';
import { createMockWorkflow } from 'models/__mocks__/workflowData';
import * as React from 'react';
import { mockExecution as mockTaskExecution } from 'models/Execution/__mocks__/mockTaskExecutionsData';
import { NodeExecutionTabs } from '../index';

const getMockNodeExecution = () => createMockNodeExecutions(1).executions[0];
const nodeExecution = getMockNodeExecution();
const workflow = createMockWorkflow('SampleWorkflow');
const taskTemplate = { ...extractTaskTemplates(workflow)[0], type: TaskType.ARRAY };
const phase = TaskExecutionPhase.SUCCEEDED;
const log = { uri: '#', name: 'Kubernetes Logs #0-0' };

jest.mock('components/hooks/useTabState');

Expand All @@ -24,22 +26,24 @@ describe('NodeExecutionTabs', () => {
const { queryByText, queryAllByRole } = render(
<NodeExecutionTabs
nodeExecution={nodeExecution}
shouldShowTaskDetails={true}
selectedTaskExecution={{ ...mockTaskExecution, taskName: 'abc', log }}
phase={phase}
taskTemplate={taskTemplate}
onTaskSelected={jest.fn()}
/>,
);
expect(queryAllByRole('tab')).toHaveLength(4);
expect(queryByText('Execution')).toBeInTheDocument();
expect(queryByText('Executions')).toBeInTheDocument();
});

it('should display proper tab name when it was provided and shouldShow is FALSE', async () => {
const { queryByText, queryAllByRole } = render(
<NodeExecutionTabs
nodeExecution={nodeExecution}
shouldShowTaskDetails={false}
selectedTaskExecution={null}
phase={phase}
taskTemplate={taskTemplate}
onTaskSelected={jest.fn()}
/>,
);

Expand All @@ -51,7 +55,11 @@ describe('NodeExecutionTabs', () => {
describe('without map tasks', () => {
it('should display proper tab name when mapTask was not provided', async () => {
const { queryAllByRole, queryByText } = render(
<NodeExecutionTabs nodeExecution={nodeExecution} shouldShowTaskDetails={false} />,
<NodeExecutionTabs
nodeExecution={nodeExecution}
selectedTaskExecution={null}
onTaskSelected={jest.fn()}
/>,
);

expect(queryAllByRole('tab')).toHaveLength(3);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import * as React from 'react';
import { Typography } from '@material-ui/core';
import { makeStyles, Theme } from '@material-ui/core/styles';
import { Core } from 'flyteidl';
import {
getTaskLogName,
getUniqueTaskExecutionName,
} from 'components/Executions/TaskExecutionsList/utils';
import { MapTaskExecution, TaskExecution } from 'models/Execution/types';
import { noLogsFoundString } from 'components/Executions/constants';
import { useCommonStyles } from '../styles';

interface StyleProps {
isLink: boolean;
}

const useStyles = makeStyles((_theme: Theme) => ({
taskTitle: ({ isLink }: StyleProps) => ({
cursor: isLink ? 'pointer' : 'default',
'&:hover': {
textDecoration: isLink ? 'underline' : 'none',
},
}),
}));

interface TaskNameListProps {
taskExecution: TaskExecution;
logs: Core.ITaskLog[];
onTaskSelected: (val: MapTaskExecution) => void;
}

export const TaskNameList = ({ taskExecution, logs, onTaskSelected }: TaskNameListProps) => {
const commonStyles = useCommonStyles();

if (logs.length === 0) {
return <span className={commonStyles.hintText}>{noLogsFoundString}</span>;
}

const taskName = getUniqueTaskExecutionName(taskExecution);

return (
<>
{logs.map((log) => {
const styles = useStyles({ isLink: !!log.uri });
const taskLogName = getTaskLogName(taskName, log.name ?? '');

const handleClick = () => {
onTaskSelected({ ...taskExecution, taskName: taskLogName, log });
};

return (
<Typography
variant="body1"
color={log.uri ? 'primary' : 'textPrimary'}
onClick={log.uri ? handleClick : undefined}
key={taskLogName}
className={styles.taskTitle}
data-testid="map-task-log"
>
{taskLogName}
</Typography>
);
})}
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ import { noLogsFoundString } from 'components/Executions/constants';
import { getTaskExecutionPhaseConstants } from 'components/Executions/utils';
import { TaskExecutionPhase } from 'models/Execution/enums';
import * as React from 'react';
import { mockExecution as mockTaskExecution } from 'models/Execution/__mocks__/mockTaskExecutionsData';

import { MapTaskStatusInfo } from './MapTaskStatusInfo';
import {
getTaskLogName,
getUniqueTaskExecutionName,
} from 'components/Executions/TaskExecutionsList/utils';
import { MapTaskStatusInfo } from '../MapTaskStatusInfo';

const taskLogs = [
{ uri: '#', name: 'Kubernetes Logs #0-0' },
Expand All @@ -18,7 +23,12 @@ describe('MapTaskStatusInfo', () => {
const phaseData = getTaskExecutionPhaseConstants(phase);

const { queryByText, getByTitle } = render(
<MapTaskStatusInfo taskLogs={taskLogs} phase={phase} isExpanded={false} />,
<MapTaskStatusInfo
taskLogs={taskLogs}
phase={phase}
taskExecution={mockTaskExecution}
onTaskSelected={jest.fn()}
/>,
);

expect(queryByText(phaseData.text)).toBeInTheDocument();
Expand All @@ -29,7 +39,9 @@ describe('MapTaskStatusInfo', () => {
const buttonEl = getByTitle('Expand row');
fireEvent.click(buttonEl);
await waitFor(() => {
expect(queryByText(taskLogs[0].name)).toBeInTheDocument();
const taskName = getUniqueTaskExecutionName(mockTaskExecution);
const taskLogName = getTaskLogName(taskName, taskLogs[0].name);
expect(queryByText(taskLogName)).toBeInTheDocument();
});
});

Expand All @@ -38,7 +50,13 @@ describe('MapTaskStatusInfo', () => {
const phaseData = getTaskExecutionPhaseConstants(phase);

const { queryByText } = render(
<MapTaskStatusInfo taskLogs={[]} phase={phase} isExpanded={true} />,
<MapTaskStatusInfo
taskLogs={[]}
phase={phase}
selectedPhase={phase}
taskExecution={mockTaskExecution}
onTaskSelected={jest.fn()}
/>,
);

expect(queryByText(phaseData.text)).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import ThemeProvider from '@material-ui/styles/ThemeProvider';
import { render } from '@testing-library/react';
import { muiTheme } from 'components/Theme/muiTheme';
import * as React from 'react';
import { mockExecution as mockTaskExecution } from 'models/Execution/__mocks__/mockTaskExecutionsData';

import { TaskNameList } from '../TaskNameList';

const taskLogs = [
{ uri: '#', name: 'Kubernetes Logs #0-0' },
{ uri: '#', name: 'Kubernetes Logs #0-1' },
{ uri: '#', name: 'Kubernetes Logs #0-2' },
];

const taskLogsWithoutUri = [
{ name: 'Kubernetes Logs #0-0' },
{ name: 'Kubernetes Logs #0-1' },
{ name: 'Kubernetes Logs #0-2' },
];

describe('TaskNameList', () => {
it('should render log names in color if they have URI', async () => {
const { queryAllByTestId } = render(
<ThemeProvider theme={muiTheme}>
<TaskNameList
logs={taskLogs}
taskExecution={mockTaskExecution}
onTaskSelected={jest.fn()}
/>
</ThemeProvider>,
);

const logs = queryAllByTestId('map-task-log');
expect(logs).toHaveLength(3);
logs.forEach((log) => {
expect(log).toBeInTheDocument();
expect(log).toHaveStyle({ color: '#8B37FF' });
});
});

it('should render log names in black if they have URI', () => {
const { queryAllByTestId } = render(
<ThemeProvider theme={muiTheme}>
<TaskNameList
logs={taskLogsWithoutUri}
taskExecution={mockTaskExecution}
onTaskSelected={jest.fn()}
/>
</ThemeProvider>,
);

const logs = queryAllByTestId('map-task-log');
expect(logs).toHaveLength(3);
logs.forEach((log) => {
expect(log).toBeInTheDocument();
expect(log).toHaveStyle({ color: '#292936' });
});
});
});

0 comments on commit 5a7ac73

Please sign in to comment.