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
5 changes: 5 additions & 0 deletions packages/shared/lib/api/sqle/service/SqlManage/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
exportSqlManageRemediationV1ExportScopeEnum,
GetSqlManageListV2FilterSourceEnum,
GetSqlManageListV2FilterAuditLevelEnum,
GetSqlManageListV2FilterErrorPriorityEnum,
GetSqlManageListV2FilterStatusEnum,
GetSqlManageListV2FilterPriorityEnum,
GetSqlManageListV2SortOrderEnum
Expand Down Expand Up @@ -205,6 +206,8 @@ export interface IGetSqlManageListV2Params {

filter_audit_level?: GetSqlManageListV2FilterAuditLevelEnum;

filter_error_priority?: GetSqlManageListV2FilterErrorPriorityEnum;

filter_last_audit_start_time_from?: string;

filter_last_audit_start_time_to?: string;
Expand Down Expand Up @@ -255,6 +258,8 @@ export interface IGetSqlManageStatisticsV2Params {

filter_audit_level?: GetSqlManageListV2FilterAuditLevelEnum;

filter_error_priority?: GetSqlManageListV2FilterErrorPriorityEnum;

filter_last_audit_start_time_from?: string;

filter_last_audit_start_time_to?: string;
Expand Down
6 changes: 6 additions & 0 deletions packages/shared/lib/api/sqle/service/SqlManage/index.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ export enum GetSqlManageListV2FilterAuditLevelEnum {
error = 'error'
}

export enum GetSqlManageListV2FilterErrorPriorityEnum {
P0 = 'P0',

P1 = 'P1'
}

export enum GetSqlManageListV2FilterStatusEnum {
unhandled = 'unhandled',

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { mockUseCurrentUser } from '@actiontech/shared/lib/testUtil/mockHook/moc
import { mockUseProjectBusinessTips } from '@actiontech/shared/lib/testUtil/mockHook/mockUseProjectBusinessTips';
import { useDispatch, useSelector } from 'react-redux';
import { driverMeta } from '../../../../hooks/useDatabaseType/index.test.data';
import { createSpySuccessResponse } from '@actiontech/shared/lib/testUtil/mockApi';
import {
createSpySuccessResponse,
createSpyFailResponse
} from '@actiontech/shared/lib/testUtil/mockApi';
import { sqlManageListData } from '../../../../testUtils/mockApi/sqlManage/data';
import {
getAllBySelector,
Expand All @@ -24,6 +27,7 @@ import { mockUseAuditPlanTypes } from '../../../../testUtils/mockRequest';
import { resetRuleTipsCacheForTests } from '../../../../hooks/useRuleTips';
import {
GetSqlManageListV2FilterPriorityEnum,
GetSqlManageListV2FilterErrorPriorityEnum,
exportSqlManageV1FilterPriorityEnum,
exportSqlManageRemediationV1ExportScopeEnum
} from '@actiontech/shared/lib/api/sqle/service/SqlManage/index.enum';
Expand Down Expand Up @@ -916,4 +920,119 @@ describe('page/SqlManagement/SQLEEIndex', () => {
payload: rowWithFirstAudit
});
});

const selectAuditLevelFilter = async (optionLabel: string) => {
fireEvent.click(screen.getByText('筛选'));
expect(screen.getByText('最低审核等级')).toBeInTheDocument();
const auditLevelFilterItem = screen
.getByText('最低审核等级')
.closest('.actiontech-table-filter-container-item');
const auditSelect =
auditLevelFilterItem?.querySelector('.ant-select') ??
screen.getByText('最低审核等级').closest('.ant-select');
expect(auditSelect).toBeTruthy();
fireEvent.mouseDown(auditSelect!.querySelector('.ant-select-selector')!);
await act(async () => jest.advanceTimersByTime(300));
const option = Array.from(
getAllBySelector('.ant-select-item-option-content')
).find((el) => el.textContent === optionLabel);
expect(option).toBeTruthy();
await act(async () => {
fireEvent.click(option!);
await act(async () => jest.advanceTimersByTime(3000));
});
await act(async () => jest.advanceTimersByTime(3000));
};

it('should send same filter_error_priority P0 on list and statistics', async () => {
const request = sqlManage.getSqlManageList();
const statisticsRequest = sqlManage.getSqlManageStatistics();
superRender(<SQLEEIndex />);
await act(async () => jest.advanceTimersByTime(3000));
await selectAuditLevelFilter('错误(P0)');
expect(request).toHaveBeenLastCalledWith(
expect.objectContaining({
filter_audit_level: 'error',
filter_error_priority: GetSqlManageListV2FilterErrorPriorityEnum.P0
})
);
expect(statisticsRequest).toHaveBeenLastCalledWith(
expect.objectContaining({
filter_audit_level: 'error',
filter_error_priority: GetSqlManageListV2FilterErrorPriorityEnum.P0
})
);
const statsParams = statisticsRequest.mock.calls.at(-1)?.[0] ?? {};
expect(statsParams).not.toHaveProperty('page_index');
expect(statsParams).not.toHaveProperty('page_size');
});

it('should send same filter_error_priority P1 on list and statistics', async () => {
const request = sqlManage.getSqlManageList();
const statisticsRequest = sqlManage.getSqlManageStatistics();
superRender(<SQLEEIndex />);
await act(async () => jest.advanceTimersByTime(3000));
await selectAuditLevelFilter('错误(P1)');
expect(request).toHaveBeenLastCalledWith(
expect.objectContaining({
filter_audit_level: 'error',
filter_error_priority: GetSqlManageListV2FilterErrorPriorityEnum.P1
})
);
expect(statisticsRequest).toHaveBeenLastCalledWith(
expect.objectContaining({
filter_audit_level: 'error',
filter_error_priority: GetSqlManageListV2FilterErrorPriorityEnum.P1
})
);
});

it('should omit filter_error_priority when audit level has no P0/P1', async () => {
const request = sqlManage.getSqlManageList();
const statisticsRequest = sqlManage.getSqlManageStatistics();
superRender(<SQLEEIndex />);
await act(async () => jest.advanceTimersByTime(3000));
await selectAuditLevelFilter('告警');
expect(request).toHaveBeenLastCalledWith(
expect.objectContaining({
filter_audit_level: 'warn'
})
);
expect(request.mock.calls.at(-1)?.[0]).not.toHaveProperty(
'filter_error_priority'
);
expect(statisticsRequest).toHaveBeenLastCalledWith(
expect.objectContaining({
filter_audit_level: 'warn'
})
);
expect(statisticsRequest.mock.calls.at(-1)?.[0]).not.toHaveProperty(
'filter_error_priority'
);
});

it('should keep previous SQL total when statistics fails', async () => {
const statisticsRequest = sqlManage.getSqlManageStatistics();
statisticsRequest
.mockImplementationOnce(() =>
createSpySuccessResponse({
sql_manage_total_num: 42,
sql_manage_bad_num: 10,
sql_manage_optimized_num: 5
})
)
.mockImplementation(() =>
createSpyFailResponse({
sql_manage_total_num: 0,
sql_manage_bad_num: 0,
sql_manage_optimized_num: 0
})
);
const { baseElement } = superRender(<SQLEEIndex />);
await act(async () => jest.advanceTimersByTime(3000));
expect(baseElement.querySelector('.num.total')).toHaveTextContent('42');
fireEvent.click(screen.getByText('已解决'));
await act(async () => jest.advanceTimersByTime(3000));
expect(baseElement.querySelector('.num.total')).toHaveTextContent('42');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@
: undefined,
filter_parse_failed: isParseFailedRuleSelected ? true : undefined,
extra_filters: buildExtraFiltersForRequest(tableFilterInfo)
}) as IGetSqlManageListV2Params & { filter_error_priority?: string };
}) as IGetSqlManageListV2Params;

return params;
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down Expand Up @@ -860,19 +860,11 @@
filter_schema_name: listParams.filter_schema_name,
filter_parse_failed: listParams.filter_parse_failed,
extra_filters: listParams.extra_filters,
// S3 §8.4:导出复用列表筛选(含 error priority);swagger 未再生前交叉扩展
...((
listParams as IGetSqlManageListV2Params & {
filter_error_priority?: string;
}
).filter_error_priority
// 导出 swagger 尚未声明 filter_error_priority;列表类型已含该字段,仅向导出参透传
...(listParams.filter_error_priority
? {
filter_error_priority: (
listParams as IGetSqlManageListV2Params & {
filter_error_priority?: string;
}
).filter_error_priority
filter_error_priority: listParams.filter_error_priority
}

Check warning on line 867 in packages/sqle/src/page/SqlManagement/component/SQLEEIndex/index.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
: {})
} as Parameters<typeof SqlManage.exportSqlManageRemediationV1>[0],
{ responseType: 'blob' }
Expand Down
Loading