Skip to content

Commit

Permalink
feat: implement tests sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowusr committed Dec 2, 2024
1 parent 9598789 commit 9f38add
Show file tree
Hide file tree
Showing 27 changed files with 671 additions and 68 deletions.
5 changes: 4 additions & 1 deletion lib/static/modules/action-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@ export default {
SUITES_PAGE_SET_ALL_TREE_NODES: 'SUITES_PAGE_SET_ALL_TREE_NODES',
SUITES_PAGE_REVEAL_TREE_NODE: 'SUITES_PAGE_REVEAL_TREE_NODE',
SUITES_PAGE_SET_STEPS_EXPANDED: 'SUITES_PAGE_SET_STEPS_EXPANDED',
SUITES_PAGE_SET_TREE_VIEW_MODE: 'SUITES_PAGE_SET_TREE_VIEW_MODE',
VISUAL_CHECKS_PAGE_SET_CURRENT_NAMED_IMAGE: 'VISUAL_CHECKS_PAGE_SET_CURRENT_NAMED_IMAGE',
UPDATE_LOADING_PROGRESS: 'UPDATE_LOADING_PROGRESS',
UPDATE_LOADING_VISIBILITY: 'UPDATE_LOADING_VISIBILITY',
UPDATE_LOADING_TITLE: 'UPDATE_LOADING_TITLE',
UPDATE_LOADING_IS_IN_PROGRESS: 'UPDATE_LOADING_IS_IN_PROGRESS',
SELECT_ALL: 'SELECT_ALL',
DESELECT_ALL: 'DESELECT_ALL'
DESELECT_ALL: 'DESELECT_ALL',
SORT_TESTS_SET_CURRENT_EXPRESSION: 'SORT_TESTS_SET_CURRENT_EXPRESSION',
SORT_TESTS_SET_DIRECTION: 'SORT_TESTS_SET_DIRECTION'
} as const;
19 changes: 19 additions & 0 deletions lib/static/modules/actions/sort-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import actionNames from '@/static/modules/action-names';
import {Action} from '@/static/modules/actions/types';
import {SortDirection} from '@/static/new-ui/types/store';

type SetCurrentSortByExpressionAction = Action<typeof actionNames.SORT_TESTS_SET_CURRENT_EXPRESSION, {
expressionIds: string[];
}>;
export const setCurrentSortByExpression = (payload: SetCurrentSortByExpressionAction['payload']): SetCurrentSortByExpressionAction =>
({type: actionNames.SORT_TESTS_SET_CURRENT_EXPRESSION, payload});

type SetSortByDirectionAction = Action<typeof actionNames.SORT_TESTS_SET_DIRECTION, {
direction: SortDirection
}>;
export const setSortByDirection = (payload: SetSortByDirectionAction['payload']): SetSortByDirectionAction =>
({type: actionNames.SORT_TESTS_SET_DIRECTION, payload});

export type SortTestsAction =
| SetCurrentSortByExpressionAction
| SetSortByDirectionAction;
10 changes: 9 additions & 1 deletion lib/static/modules/actions/suites-page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import actionNames from '@/static/modules/action-names';
import {Action} from '@/static/modules/actions/types';
import {TreeViewMode} from '@/static/new-ui/types/store';

export type SuitesPageSetCurrentTreeNodeAction = Action<typeof actionNames.SUITES_PAGE_SET_CURRENT_SUITE, Partial<{
treeNodeId: string;
Expand Down Expand Up @@ -43,10 +44,17 @@ type SetStepsExpandedStateAction = Action<typeof actionNames.SUITES_PAGE_SET_STE
export const setStepsExpandedState = (payload: SetStepsExpandedStateAction['payload']): SetStepsExpandedStateAction =>
({type: actionNames.SUITES_PAGE_SET_STEPS_EXPANDED, payload});

type SetTreeViewModeAction = Action<typeof actionNames.SUITES_PAGE_SET_TREE_VIEW_MODE, {
treeViewMode: TreeViewMode;
}>;
export const setTreeViewMode = (payload: SetTreeViewModeAction['payload']): SetTreeViewModeAction =>
({type: actionNames.SUITES_PAGE_SET_TREE_VIEW_MODE, payload});

export type SuitesPageAction =
| SetTreeNodeExpandedStateAction
| SetAllTreeNodesStateAction
| SuitesPageSetCurrentTreeNodeAction
| SetSectionExpandedStateAction
| SetStepsExpandedStateAction
| RevealTreeNodeAction;
| RevealTreeNodeAction
| SetTreeViewModeAction;
4 changes: 3 additions & 1 deletion lib/static/modules/actions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {ThunkAction} from 'redux-thunk';
import {State} from '@/static/new-ui/types/store';
import {LifecycleAction} from '@/static/modules/actions/lifecycle';
import {SuitesPageAction} from '@/static/modules/actions/suites-page';
import {SortTestsAction} from '@/static/modules/actions/sort-tests';

export type {Dispatch} from 'redux';

Expand All @@ -22,4 +23,5 @@ export type AppThunk<ReturnType = Promise<void>> = ThunkAction<ReturnType, State
export type SomeAction =
| GroupTestsAction
| LifecycleAction
| SuitesPageAction;
| SuitesPageAction
| SortTestsAction;
8 changes: 7 additions & 1 deletion lib/static/modules/default-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {DiffModes} from '../../constants/diff-modes';
import {EXPAND_ERRORS} from '../../constants/expand-modes';
import {RESULT_KEYS} from '../../constants/group-tests';
import {ToolName} from '../../constants';
import {State} from '@/static/new-ui/types/store';
import {SortDirection, State, TreeViewMode} from '@/static/new-ui/types/store';

export default Object.assign({config: configDefaults}, {
gui: true,
Expand Down Expand Up @@ -121,10 +121,16 @@ export default Object.assign({config: configDefaults}, {
availableSections: [],
availableExpressions: [],
currentExpressionIds: []
},
sortTestsData: {
availableExpressions: [],
currentExpressionIds: [],
currentDirection: SortDirection.Asc
}
},
ui: {
suitesPage: {
treeViewMode: TreeViewMode.Tree,
retryIndexByTreeNodeId: {},
expandedSectionsById: {},
expandedStepsByResultId: {},
Expand Down
2 changes: 2 additions & 0 deletions lib/static/modules/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import suitesPage from './suites-page';
import visualChecksPage from './visual-checks-page';
import isInitialized from './is-initialized';
import newUiGroupedTests from './new-ui-grouped-tests';
import sortTests from './sort-tests';

// The order of specifying reducers is important.
// At the top specify reducers that does not depend on other state fields.
Expand Down Expand Up @@ -60,6 +61,7 @@ export default reduceReducers(
tree,
groupedTests,
newUiGroupedTests,
sortTests,
plugins,
progressBar,
suitesPage,
Expand Down
24 changes: 15 additions & 9 deletions lib/static/modules/reducers/new-ui-grouped-tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const extractErrors = (result: ResultEntity, images: ImageEntity[]): string[] =>
const groupTestsByMeta = (expr: GroupByMetaExpression, resultsById: Record<string, ResultEntity>): Record<string, GroupEntity> => {
const DEFAULT_GROUP = `__${GroupByType.Meta}__DEFAULT_GROUP`;
const results = Object.values(resultsById);
const groups: Record<string | symbol, GroupEntity> = {};
const groupsById: Record<string | symbol, GroupEntity> = {};
const groupingKeyToId: Record<string, string> = {};
let id = 1;

for (const result of results) {
Expand All @@ -59,24 +60,29 @@ const groupTestsByMeta = (expr: GroupByMetaExpression, resultsById: Record<strin
groupingKey = `${GroupByType.Meta}__${expr.key}__${stringify(result.metaInfo[expr.key])}`;
}

if (!groups[groupingKey]) {
groups[groupingKey] = {
id: id.toString(),
if (!groupingKeyToId[groupingKey]) {
groupingKeyToId[groupingKey] = id.toString();
id++;
}

const groupId = groupingKeyToId[groupingKey];
if (!groupsById[groupId]) {
groupsById[groupId] = {
id: groupId,
key: expr.key,
label: stringify(result.metaInfo[expr.key]),
resultIds: [],
browserIds: []
};
id++;
}

groups[groupingKey].resultIds.push(result.id);
if (!groups[groupingKey].browserIds.includes(result.parentId)) {
groups[groupingKey].browserIds.push(result.parentId);
groupsById[groupId].resultIds.push(result.id);
if (!groupsById[groupId].browserIds.includes(result.parentId)) {
groupsById[groupId].browserIds.push(result.parentId);
}
}

return groups;
return groupsById;
};

const groupTestsByError = (resultsById: Record<string, ResultEntity>, imagesById: Record<string, ImageEntity>, errorPatterns: State['config']['errorPatterns']): Record<string, GroupEntity> => {
Expand Down
44 changes: 44 additions & 0 deletions lib/static/modules/reducers/sort-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {SortByExpression, SortType, State} from '@/static/new-ui/types/store';
import {SomeAction} from '@/static/modules/actions/types';
import actionNames from '@/static/modules/action-names';
import {applyStateUpdate} from '@/static/modules/utils';

export default (state: State, action: SomeAction): State => {
switch (action.type) {
case actionNames.INIT_STATIC_REPORT:
case actionNames.INIT_GUI_REPORT: {
const availableExpressions: SortByExpression[] = [
{id: 'by-name', label: 'name', type: SortType.ByName},
{id: 'by-retries', label: 'failed retries', type: SortType.ByRetries}
];

return applyStateUpdate(state, {
app: {
sortTestsData: {
availableExpressions
}
}
});
}
case actionNames.SORT_TESTS_SET_CURRENT_EXPRESSION: {
return applyStateUpdate(state, {
app: {
sortTestsData: {
currentExpressionIds: action.payload.expressionIds
}
}
});
}
case actionNames.SORT_TESTS_SET_DIRECTION: {
return applyStateUpdate(state, {
app: {
sortTestsData: {
currentDirection: action.payload.direction
}
}
});
}
default:
return state;
}
};
11 changes: 9 additions & 2 deletions lib/static/modules/reducers/suites-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default (state: State, action: SomeAction): State => {
switch (action.type) {
case actionNames.INIT_STATIC_REPORT:
case actionNames.INIT_GUI_REPORT:
case actionNames.SUITES_PAGE_SET_TREE_VIEW_MODE:
case actionNames.GROUP_TESTS_SET_CURRENT_EXPRESSION: {
const {allTreeNodeIds} = getTreeViewItems(state);

Expand All @@ -20,7 +21,8 @@ export default (state: State, action: SomeAction): State => {

let currentGroupId: string | null | undefined = null;
let currentTreeNodeId: string | null | undefined;
if (action.type === actionNames.GROUP_TESTS_SET_CURRENT_EXPRESSION) {
let treeViewMode = state.ui.suitesPage.treeViewMode;
if (action.type === actionNames.GROUP_TESTS_SET_CURRENT_EXPRESSION || action.type === actionNames.SUITES_PAGE_SET_TREE_VIEW_MODE) {
const {currentBrowserId} = state.app.suitesPage;
if (currentBrowserId) {
const {tree} = getTreeViewItems(state);
Expand All @@ -32,6 +34,10 @@ export default (state: State, action: SomeAction): State => {
}
}

if (action.type === actionNames.SUITES_PAGE_SET_TREE_VIEW_MODE) {
treeViewMode = action.payload.treeViewMode;
}

return applyStateUpdate(state, {
app: {
suitesPage: {
Expand All @@ -41,7 +47,8 @@ export default (state: State, action: SomeAction): State => {
},
ui: {
suitesPage: {
expandedTreeNodesById
expandedTreeNodesById,
treeViewMode
}
}
});
Expand Down
94 changes: 94 additions & 0 deletions lib/static/new-ui/components/AdaptiveSelect/index.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
.selectPopup {
width: 150px;
font-size: var(--g-text-body-1-font-size);
}

.selectPopup :global(.g-select-list__option) {
padding: 0;
}

.selectPopup :global(.g-select-list__option .g-select-list__tick-icon) {
display: none;
}

.option-container {
display: flex;
align-items: center;
width: 100%;
height: 100%;
padding: 0 10px;
gap: 4px;
}

.current-option-icons-container {
margin-left: auto;
display: flex;
gap: 4px;
}

.label-icons-container {
display: none;
position: relative;
padding-right: 2px;
}

.label-icon-right {
margin-left: -6px;
}

.label-dot {
display: none;
position: absolute;
right: 0;
top: 0;
height: 4px;
width: 4px;
border-radius: 100vh;
background-color: var(--g-color-private-red-600-solid);
}

.direction-icon {
margin-left: auto;
}

.clear-button {
display: none;
margin-left: auto;
}

.clear-button:hover {
opacity: 0.7;
cursor: pointer;
}

.container div:has(.tooltip) {
display: none;
}

@container (max-width: 500px) {
.label-text {
display: none;
}

.container div:has(.tooltip) {
display: block;
}

.label-icons-container {
display: block;
}
}

@container (max-width: 450px) {
.select :global(.g-select-control__option-text), .select :global(.g-select-clear) {
display: none;
}

.clear-button {
display: block;
}

.label-dot {
display: block;
}
}
Loading

0 comments on commit 9f38add

Please sign in to comment.