Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Nastya Rusina <[email protected]>
  • Loading branch information
anrusina committed Jan 27, 2022
1 parent e87912f commit e528114
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 31 deletions.
6 changes: 3 additions & 3 deletions src/basics/FeatureFlags/FeatureFlags.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import { render, screen, waitFor, act } from '@testing-library/react';

import { FeatureFlagsProvider, useFeatureFlag } from '.';
import { FeatureFlag } from './defaultConfig';
Expand Down Expand Up @@ -46,7 +46,7 @@ describe('FeatureFlags', () => {
window.getFeatureFlag(FeatureFlag.TestFlagUndefined)
).toBeFalsy();

window.setFeatureFlag(FeatureFlag.TestFlagUndefined, true);
act(() => window.setFeatureFlag(FeatureFlag.TestFlagUndefined, true));
await waitFor(() => {
// check that flag cghanged value
expect(
Expand All @@ -60,7 +60,7 @@ describe('FeatureFlags', () => {
expect(screen.getByText(/Disabled/i)).toBeTruthy();

// Enable flag
window.setFeatureFlag(FeatureFlag.TestFlagUndefined, true);
act(() => window.setFeatureFlag(FeatureFlag.TestFlagUndefined, true));
await waitFor(() => {
// check that component was updated accordingly
expect(screen.getByText(/Enabled/i)).toBeTruthy();
Expand Down
25 changes: 12 additions & 13 deletions src/components/Entities/EntityExecutions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { SortDirection } from 'models/AdminEntity/types';
import { ResourceIdentifier } from 'models/Common/types';
import { executionSortFields } from 'models/Execution/constants';
import { executionFilterGenerator } from './generators';
import { compact } from 'lodash';

const useStyles = makeStyles((theme: Theme) => ({
filtersContainer: {
Expand All @@ -39,11 +40,7 @@ export const EntityExecutions: React.FC<EntityExecutionsProps> = ({
const { domain, project, resourceType } = id;
const styles = useStyles();
const filtersState = useWorkflowExecutionFiltersState();
const {
showArchived,
setShowArchived,
getFilter: getAcrhiveFilter
} = useExecutionShowArchivedState();
const archivedFilter = useExecutionShowArchivedState();

const sort = {
key: executionSortFields.createdAt,
Expand All @@ -55,15 +52,16 @@ export const EntityExecutions: React.FC<EntityExecutionsProps> = ({
[id, resourceType]
);

const allFilters = compact([
...baseFilters,
...filtersState.appliedFilters,
archivedFilter.getFilter()
]);
const executions = useWorkflowExecutions(
{ domain, project },
{
sort,
filter: [
...baseFilters,
...filtersState.appliedFilters,
getAcrhiveFilter()
],
filter: allFilters,
limit: 100
}
);
Expand All @@ -75,7 +73,8 @@ export const EntityExecutions: React.FC<EntityExecutionsProps> = ({
}

/** Don't render component until finish fetching user profile */
if (filtersState.filters[4].status !== 'LOADED') {
const lastIndex = filtersState.filters.length - 1;
if (filtersState.filters[lastIndex].status !== 'LOADED') {
return null;
}

Expand All @@ -89,8 +88,8 @@ export const EntityExecutions: React.FC<EntityExecutionsProps> = ({
{...filtersState}
chartIds={chartIds}
clearCharts={clearCharts}
showArchived={showArchived}
onArchiveFilterChange={setShowArchived}
showArchived={archivedFilter.showArchived}
onArchiveFilterChange={archivedFilter.setShowArchived}
/>
</div>
<WaitForData {...executions}>
Expand Down
1 change: 0 additions & 1 deletion src/components/Entities/EntityVersions.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Typography from '@material-ui/core/Typography';
import { makeStyles, Theme } from '@material-ui/core/styles';
import { WaitForData } from 'components/common/WaitForData';
import { useWorkflowExecutionFiltersState } from 'components/Executions/filters/useExecutionFiltersState';
import { WorkflowVersionsTable } from 'components/Executions/Tables/WorkflowVersionsTable';
import { isLoadingState } from 'components/hooks/fetchMachine';
import { useWorkflowVersions } from 'components/hooks/useWorkflowVersions';
Expand Down
14 changes: 9 additions & 5 deletions src/components/Executions/filters/useExecutionArchiveState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ExecutionState } from 'models/Execution/enums';
interface ArchiveFilterState {
showArchived: boolean;
setShowArchived: (newValue: boolean) => void;
getFilter: () => FilterOperation;
getFilter: () => FilterOperation | null;
}

/**
Expand All @@ -14,13 +14,17 @@ interface ArchiveFilterState {
export function useExecutionShowArchivedState(): ArchiveFilterState {
const [showArchived, setShowArchived] = useState(false);

const getFilter = (): FilterOperation => {
// By default all values are returned with EXECUTION_ACTIVE state,
// so filter need to be applied only for ARCHIVED executions
const getFilter = (): FilterOperation | null => {
if (!showArchived) {
return null;
}

return {
key: 'state',
operation: FilterOperationName.EQ,
value: showArchived
? ExecutionState.EXECUTION_ARCHIVED
: ExecutionState.EXECUTION_ACTIVE
value: ExecutionState.EXECUTION_ARCHIVED
};
};

Expand Down
22 changes: 13 additions & 9 deletions src/components/Project/ProjectExecutions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { useExecutionShowArchivedState } from 'components/Executions/filters/use
import { WaitForData } from 'components/common/WaitForData';
import { history } from 'routes/history';
import { Routes } from 'routes/routes';
import { compact } from 'lodash';

const useStyles = makeStyles((theme: Theme) => ({
container: {
Expand Down Expand Up @@ -62,15 +63,16 @@ export const ProjectExecutions: React.FC<ProjectExecutionsProps> = ({
projectId: project
}) => {
const styles = useStyles();
const filtersState = useWorkflowExecutionFiltersState();
const archivedFilter = useExecutionShowArchivedState();
const filtersState = useWorkflowExecutionFiltersState();

const filters = React.useMemo(() => {
return [...filtersState.appliedFilters, archivedFilter.getFilter()];
}, [filtersState, archivedFilter]);
const allFilters = compact([
...filtersState.appliedFilters,
archivedFilter.getFilter()
]);
const config = {
sort: defaultSort,
filter: filters
filter: allFilters
};

// Remount the table whenever we change project/domain/filters to ensure
Expand All @@ -80,9 +82,9 @@ export const ProjectExecutions: React.FC<ProjectExecutionsProps> = ({
getCacheKey({
domain,
project,
filters: filters
filters: allFilters
}),
[domain, project, filters]
[domain, project, allFilters]
);

const query = useInfiniteQuery({
Expand All @@ -106,11 +108,12 @@ export const ProjectExecutions: React.FC<ProjectExecutionsProps> = ({
history.push(Routes.ExecutionDetails.makeUrl(item.metadata));
}, []);

// to show only in bar chart view
const last100Executions = useWorkflowExecutions(
{ domain, project },
{
sort: defaultSort,
filter: filters,
filter: allFilters,
limit: 100
}
);
Expand Down Expand Up @@ -138,7 +141,8 @@ export const ProjectExecutions: React.FC<ProjectExecutionsProps> = ({
);

/** Don't render component until finish fetching user profile */
if (filtersState.filters[4].status === 'LOADED') {
const filterLength = filtersState.filters.length;
if (filtersState.filters[filterLength - 1].status === 'LOADED') {
return (
<div className={styles.container}>
<Typography
Expand Down
3 changes: 3 additions & 0 deletions src/components/Project/test/ProjectExecutions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import { getUserProfile } from 'models/Common/api';
import { UserProfile } from 'models/Common/types';

jest.mock('components/Executions/Tables/WorkflowExecutionsTable');
jest.mock('notistack', () => ({
useSnackbar: () => ({ enqueueSnackbar: jest.fn() })
}));

describe('ProjectExecutions', () => {
let basicPythonFixture: ReturnType<typeof basicPythonWorkflow.generate>;
Expand Down

0 comments on commit e528114

Please sign in to comment.