From ebd8b23be51a745282c79f721156500254e1b1ae Mon Sep 17 00:00:00 2001 From: shadowusr Date: Thu, 7 Nov 2024 18:59:51 +0300 Subject: [PATCH] fix: refactoring and minor fixes --- lib/static/modules/reducers/tree/index.js | 3 -- .../Card/EmptyReportCard.module.css | 39 ++++++++++++++++++ .../components/Card/EmptyReportCard.tsx | 27 +++++++++++++ .../components/MainLayout/index.module.css | 40 ------------------- .../new-ui/components/MainLayout/index.tsx | 19 +-------- .../TreeActionsToolbar/index.module.css | 2 - .../components/TreeActionsToolbar/index.tsx | 8 ++-- .../modules/reducers/static-image-accepter.ts | 2 +- .../lib/static/modules/reducers/tree/index.js | 14 +++---- test/unit/lib/static/utils.tsx | 2 + 10 files changed, 82 insertions(+), 74 deletions(-) create mode 100644 lib/static/new-ui/components/Card/EmptyReportCard.module.css create mode 100644 lib/static/new-ui/components/Card/EmptyReportCard.tsx diff --git a/lib/static/modules/reducers/tree/index.js b/lib/static/modules/reducers/tree/index.js index 3c46d6eae..89834ba94 100644 --- a/lib/static/modules/reducers/tree/index.js +++ b/lib/static/modules/reducers/tree/index.js @@ -279,9 +279,6 @@ export default ((state, action) => { calcSuitesShowness({tree, suiteIds: [failedSuiteId], diff: diff.tree}); } - console.log('applying diff'); - console.log(diff); - return applyStateUpdate(state, diff); } diff --git a/lib/static/new-ui/components/Card/EmptyReportCard.module.css b/lib/static/new-ui/components/Card/EmptyReportCard.module.css new file mode 100644 index 000000000..c71431920 --- /dev/null +++ b/lib/static/new-ui/components/Card/EmptyReportCard.module.css @@ -0,0 +1,39 @@ +.container { + padding: 10px; + height: 100%; +} + +.hint-card { + height: 100%; + display: flex; + flex-direction: column; +} + +.empty-report-icon { + width: 40px; +} + +.card-title { + color: #000; + margin-top: 16px; +} + +.hints-container { + max-width: 450px; + margin-top: 8px; +} + +.hint { + margin-top: 12px; + display: flex; +} + +.hint-item-icon { + flex-shrink: 0; + margin-right: 8px; + color: var(--g-color-base-brand); +} + +.hint-item-text { + line-height: 1.4; +} diff --git a/lib/static/new-ui/components/Card/EmptyReportCard.tsx b/lib/static/new-ui/components/Card/EmptyReportCard.tsx new file mode 100644 index 000000000..391cdebb0 --- /dev/null +++ b/lib/static/new-ui/components/Card/EmptyReportCard.tsx @@ -0,0 +1,27 @@ +import {TextHintCard} from '@/static/new-ui/components/Card/TextHintCard'; +import EmptyReport from '@/static/icons/empty-report.svg'; +import classNames from 'classnames'; +import {Icon} from '@gravity-ui/uikit'; +import {Check} from '@gravity-ui/icons'; +import React, {ReactNode} from 'react'; + +import styles from './EmptyReportCard.module.css'; + +export function EmptyReportCard(): ReactNode { + return
+ + icon + This report is empty +
+ {[ + 'Check if your project contains any tests', + 'Check if the tool you are using is configured correctly and is able to find your tests', + 'Check logs to see if some critical error has occurred and prevented report from collecting any results' + ].map((hintText, index) =>
+ +
{hintText}
+
)} +
+
+
; +} diff --git a/lib/static/new-ui/components/MainLayout/index.module.css b/lib/static/new-ui/components/MainLayout/index.module.css index 395e9f3b9..9171ac42f 100644 --- a/lib/static/new-ui/components/MainLayout/index.module.css +++ b/lib/static/new-ui/components/MainLayout/index.module.css @@ -19,43 +19,3 @@ .footer-item--active { color: var(--gn-aside-header-item-current-icon-color) !important; } - -.hint-card-container { - padding: 10px; - height: 100%; -} - -.hint-card { - height: 100%; - display: flex; - flex-direction: column; -} - -.hint-card-icon { - width: 40px; -} - -.hint-card-title { - color: #000; - margin-top: 16px; -} - -.hint-card-hints-container { - max-width: 450px; - margin-top: 8px; -} - -.hint-card-hint { - margin-top: 12px; - display: flex; -} - -.hint-card-check { - flex-shrink: 0; - margin-right: 8px; - color: var(--g-color-base-brand); -} - -.hint-card-hint-text { - line-height: 1.4; -} diff --git a/lib/static/new-ui/components/MainLayout/index.tsx b/lib/static/new-ui/components/MainLayout/index.tsx index 7fef64fbb..53f0b65c3 100644 --- a/lib/static/new-ui/components/MainLayout/index.tsx +++ b/lib/static/new-ui/components/MainLayout/index.tsx @@ -10,10 +10,7 @@ import TestplaneIcon from '../../../icons/testplane-mono.svg'; import styles from './index.module.css'; import {Footer} from './Footer'; import {State} from '@/static/new-ui/types/store'; -import {TextHintCard} from '@/static/new-ui/components/Card/TextHintCard'; -import EmptyReport from '../../../icons/empty-report.svg'; -import {Check} from '@gravity-ui/icons'; -import {Icon} from '@gravity-ui/uikit'; +import {EmptyReportCard} from '@/static/new-ui/components/Card/EmptyReportCard'; export enum PanelId { Settings = 'settings', @@ -62,19 +59,7 @@ export function MainLayout(props: MainLayoutProps): ReactNode { customBackgroundClassName={styles.asideHeaderBgWrapper} renderContent={(): React.ReactNode => { if (isReportEmpty) { - return
- - icon - This report is empty -
- {[ - 'Check if your project contains any tests', - 'Check if the tool you are using is configured correctly and is able to find your tests', - 'Check logs to see if some critical error has occurred and prevented report from collecting any results' - ].map((hintText, index) =>
{hintText}
)} -
-
-
; + return ; } return props.children; diff --git a/lib/static/new-ui/features/suites/components/TreeActionsToolbar/index.module.css b/lib/static/new-ui/features/suites/components/TreeActionsToolbar/index.module.css index dade1808c..b36906ae1 100644 --- a/lib/static/new-ui/features/suites/components/TreeActionsToolbar/index.module.css +++ b/lib/static/new-ui/features/suites/components/TreeActionsToolbar/index.module.css @@ -31,13 +31,11 @@ transition: scale .15s ease, visibility 0.15s ease, opacity 0.15s ease; visibility: hidden; - /*scale: 0.95;*/ opacity: 0; } .selected-container--visible { visibility: visible; - /*scale: 1;*/ opacity: 1; } diff --git a/lib/static/new-ui/features/suites/components/TreeActionsToolbar/index.tsx b/lib/static/new-ui/features/suites/components/TreeActionsToolbar/index.tsx index dbd90c9dc..3f0ba2af0 100644 --- a/lib/static/new-ui/features/suites/components/TreeActionsToolbar/index.tsx +++ b/lib/static/new-ui/features/suites/components/TreeActionsToolbar/index.tsx @@ -157,11 +157,11 @@ export function TreeActionsToolbar(props: TreeActionsToolbarProps): ReactNode { {isRunTestsAvailable && } tooltip={isSelectedAtLeastOne ? 'Run selected' : 'Run visible'} view={'flat'} onClick={handleRun} disabled={isRunning || !isInitialized}>} - {isEditScreensAvailable && <> + {isEditScreensAvailable && ( isUndoButtonVisible ? - } tooltip={isSelectedAtLeastOne ? 'Undo accepting selected screenshots' : 'Undo accepting visible screenshots'} view={'flat'} onClick={handleUndo} disabled={isRunning || !isInitialized}> : - } tooltip={isSelectedAtLeastOne ? 'Accept selected screenshots' : 'Accept visible screenshots'} view={'flat'} onClick={handleAccept} disabled={isRunning || !isInitialized}> - } + } tooltip={isSelectedAtLeastOne ? 'Undo accepting selected screenshots' : 'Undo accepting visible screenshots'} view={'flat'} onClick={handleUndo} disabled={isRunning || !isInitialized}> : + } tooltip={isSelectedAtLeastOne ? 'Accept selected screenshots' : 'Accept visible screenshots'} view={'flat'} onClick={handleAccept} disabled={isRunning || !isInitialized}> + )}
} tooltip={'Focus on active test'} view={'flat'} onClick={props.onHighlightCurrentTest} disabled={!isInitialized}/> } tooltip={'Expand all'} view={'flat'} onClick={handleExpandAll} disabled={!isInitialized}/> diff --git a/test/unit/lib/static/modules/reducers/static-image-accepter.ts b/test/unit/lib/static/modules/reducers/static-image-accepter.ts index d2a4f08ab..0757fea1e 100644 --- a/test/unit/lib/static/modules/reducers/static-image-accepter.ts +++ b/test/unit/lib/static/modules/reducers/static-image-accepter.ts @@ -156,7 +156,7 @@ describe('lib/static/modules/reducers/static-image-accepter', () => { const state = {staticImageAccepter, tree}; - const newState = reducer(state, {type: actionNames.STATIC_ACCEPTER_UNSTAGE_SCREENSHOT, payload: {imageId: 'imageId'}}); + const newState = reducer(state, {type: actionNames.STATIC_ACCEPTER_UNSTAGE_SCREENSHOT, payload: ['imageId']}); assert.equal(newState.staticImageAccepter.acceptableImages['imageId'].commitStatus, null); diff --git a/test/unit/lib/static/modules/reducers/tree/index.js b/test/unit/lib/static/modules/reducers/tree/index.js index 5150058ca..d701f082d 100644 --- a/test/unit/lib/static/modules/reducers/tree/index.js +++ b/test/unit/lib/static/modules/reducers/tree/index.js @@ -1854,7 +1854,7 @@ describe('lib/static/modules/reducers/tree', () => { it('should return original image status', () => { const newState = reducer(state, {type: actionNames.STATIC_ACCEPTER_STAGE_SCREENSHOT, payload: ['i1']}); - const nextState = reducer(newState, {type: actionNames.STATIC_ACCEPTER_UNSTAGE_SCREENSHOT, payload: {imageId: 'i1'}}); + const nextState = reducer(newState, {type: actionNames.STATIC_ACCEPTER_UNSTAGE_SCREENSHOT, payload: ['i1']}); assert.equal(nextState.tree.images.byId['i1'].status, FAIL); }); @@ -1862,8 +1862,8 @@ describe('lib/static/modules/reducers/tree', () => { it('should return original result status', () => { const firstState = reducer(state, {type: actionNames.STATIC_ACCEPTER_STAGE_SCREENSHOT, payload: ['i1', 'i2']}); - const secondState = reducer(firstState, {type: actionNames.STATIC_ACCEPTER_UNSTAGE_SCREENSHOT, payload: {imageId: 'i1'}}); - const thirdState = reducer(secondState, {type: actionNames.STATIC_ACCEPTER_UNSTAGE_SCREENSHOT, payload: {imageId: 'i2'}}); + const secondState = reducer(firstState, {type: actionNames.STATIC_ACCEPTER_UNSTAGE_SCREENSHOT, payload: ['i1']}); + const thirdState = reducer(secondState, {type: actionNames.STATIC_ACCEPTER_UNSTAGE_SCREENSHOT, payload: ['i2']}); assert.equal(thirdState.tree.results.byId['r1'].status, FAIL); }); @@ -1871,9 +1871,9 @@ describe('lib/static/modules/reducers/tree', () => { it('should return original suite status', () => { const firstState = reducer(state, {type: actionNames.STATIC_ACCEPTER_STAGE_SCREENSHOT, payload: ['i1', 'i2', 'i3']}); - const secondState = reducer(firstState, {type: actionNames.STATIC_ACCEPTER_UNSTAGE_SCREENSHOT, payload: {imageId: 'i1'}}); - const thirdState = reducer(secondState, {type: actionNames.STATIC_ACCEPTER_UNSTAGE_SCREENSHOT, payload: {imageId: 'i2'}}); - const fourthState = reducer(thirdState, {type: actionNames.STATIC_ACCEPTER_UNSTAGE_SCREENSHOT, payload: {imageId: 'i3'}}); + const secondState = reducer(firstState, {type: actionNames.STATIC_ACCEPTER_UNSTAGE_SCREENSHOT, payload: ['i1']}); + const thirdState = reducer(secondState, {type: actionNames.STATIC_ACCEPTER_UNSTAGE_SCREENSHOT, payload: ['i2']}); + const fourthState = reducer(thirdState, {type: actionNames.STATIC_ACCEPTER_UNSTAGE_SCREENSHOT, payload: ['i3']}); assert.equal(fourthState.tree.suites.byId['s1'].status, FAIL); }); @@ -1884,7 +1884,7 @@ describe('lib/static/modules/reducers/tree', () => { state.tree.results.byId['r1'].status = STAGED; state.tree.images.byId['i1'].status = STAGED; - const nextState = reducer(state, {type: actionNames.STATIC_ACCEPTER_UNSTAGE_SCREENSHOT, payload: {imageId: 'i1'}}); + const nextState = reducer(state, {type: actionNames.STATIC_ACCEPTER_UNSTAGE_SCREENSHOT, payload: ['i1']}); assert.equal(nextState.tree.suites.byId['s0'].status, FAIL); assert.equal(nextState.tree.suites.byId['s1'].status, FAIL); diff --git a/test/unit/lib/static/utils.tsx b/test/unit/lib/static/utils.tsx index d72ff0ae4..dcd617a61 100644 --- a/test/unit/lib/static/utils.tsx +++ b/test/unit/lib/static/utils.tsx @@ -12,6 +12,7 @@ import {TestStatus} from '@/constants'; import reducer from '@/static/modules/reducers'; import localStorage from '@/static/modules/middlewares/local-storage'; import {BrowserEntity, ImageEntityFail, State, SuiteEntity, TreeEntity} from '@/static/new-ui/types/store'; +import {UNCHECKED} from '@/constants/checked-statuses'; export const mkState = ({initialState}: { initialState: Partial }): State => { return _.defaultsDeep(initialState ?? {}, defaultState); @@ -77,6 +78,7 @@ export const addBrowserToTree = ({tree, suiteName, browserName}: AddBrowserToTre } as BrowserEntity; tree.browsers.stateById[fullId] = { shouldBeShown: true, + checkStatus: UNCHECKED, retryIndex: 0, isHiddenBecauseOfStatus: false };