Skip to content

Commit

Permalink
[test]: Update unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
zzyangh committed Jan 23, 2025
1 parent b51e3f5 commit abd5a8d
Show file tree
Hide file tree
Showing 11 changed files with 7,945 additions and 483 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ exports[`SqlAnalyze/ManagementConfAnalyze filter sql execution plan cost 1`] = `
style="margin-right: 8px;"
>
<h3>
SQL执行计划 Cost趋势
SQL执行计划代价趋势
</h3>
</div>
<div
Expand Down Expand Up @@ -312,7 +312,7 @@ exports[`SqlAnalyze/ManagementConfAnalyze filter sql execution plan cost 1`] = `
class="chart-box"
>
<div
data-custom-params="{"data":[{"y":1.2,"x":"2025-01-06 17:22:53","info":[{"id":"1","select_id":"1","table":"test_table","partitions":"a,b,c","type":"const","possible_keys":"a,b,c","key":"key_name","key_len":"231","ref":"abc","rows":"100","filtered":"100","select_type":"SIMPLE"}]},{"y":3.2,"x":"2025-01-07 17:32:53","info":[{"id":"2","select_id":"1","table":"test_table","partitions":"a,b,c","type":"const","possible_keys":"a,b,c","key":"key_name","key_len":"231","ref":"abc","rows":"100","filtered":"100","select_type":"SIMPLE"}]},{"y":2.2,"x":"2025-01-07 17:42:53","info":[{"id":"3","select_id":"1","table":"test_table","partitions":"a,b,c","type":"const","possible_keys":"a,b,c","key":"key_name","key_len":"231","ref":"abc","rows":"100","filtered":"100","select_type":"SIMPLE"}]},{"y":5.2,"x":"2025-01-07 17:52:53","info":[{"id":"4","select_id":"1","table":"test_table","partitions":"a,b,c","type":"const","possible_keys":"a,b,c","key":"key_name","key_len":"231","ref":"abc","rows":"100","filtered":"100","select_type":"SIMPLE"}]},{"x":"2025-01-09 12:00:00"}],"xField":"x","yField":"y","xAxis":{"nice":true},"point":{"style":{"fill":"#FFFFFF","stroke":"#4583ff"}},"slider":{"start":0,"end":1},"appendPadding":20,"annotations":[{"type":"text","content":5.2,"position":["2025-01-07 17:52:53",5.2],"style":{"textAlign":"center","fill":"#FFFFFF"},"offsetY":-16,"background":{"padding":4,"style":{"radius":4,"fill":"#4583ff"}}},{"position":["2025-01-07 17:52:53",5.2],"type":"dataMarker","text":{"content":"","style":{"textAlign":"left"}},"point":{"style":{"fill":"#FFFFFF","stroke":"#4583ff"}},"autoAdjust":false},{"type":"text","content":1.2,"position":["2025-01-06 17:22:53",1.2],"style":{"textAlign":"center","fill":"#FFFFFF"},"offsetY":-16,"background":{"padding":4,"style":{"radius":4,"fill":"#4583ff"}}},{"position":["2025-01-06 17:22:53",1.2],"type":"dataMarker","text":{"content":"","style":{"textAlign":"left"}},"point":{"style":{"fill":"#FFFFFF","stroke":"#4583ff"}},"autoAdjust":false}],"tooltip":{"fields":["created_time","cost","id"],"enterable":true,"follow":true},"theme":"light"}"
data-custom-params="{"data":[{"y":1.2,"x":"2025-01-06 17:22:53","info":[{"id":"1","select_id":"1","table":"test_table","partitions":"a,b,c","type":"const","possible_keys":"a,b,c","key":"key_name","key_len":"231","ref":"abc","rows":"100","filtered":"100","select_type":"SIMPLE"}]},{"y":3.2,"x":"2025-01-07 17:32:53","info":[{"id":"2","select_id":"1","table":"test_table","partitions":"a,b,c","type":"const","possible_keys":"a,b,c","key":"key_name","key_len":"231","ref":"abc","rows":"100","filtered":"100","select_type":"SIMPLE"}]},{"y":2.2,"x":"2025-01-07 17:42:53","info":[{"id":"3","select_id":"1","table":"test_table","partitions":"a,b,c","type":"const","possible_keys":"a,b,c","key":"key_name","key_len":"231","ref":"abc","rows":"100","filtered":"100","select_type":"SIMPLE"}]},{"y":5.2,"x":"2025-01-07 17:52:53","info":[{"id":"4","select_id":"1","table":"test_table","partitions":"a,b,c","type":"const","possible_keys":"a,b,c","key":"key_name","key_len":"231","ref":"abc","rows":"100","filtered":"100","select_type":"SIMPLE"}]},{"x":"2025-01-09 12:00:00"}],"xField":"x","yField":"y","xAxis":{"nice":true},"point":{"style":{"fill":"#FFFFFF","stroke":"#4583ff"},"size":4},"slider":{"start":0,"end":1},"appendPadding":20,"annotations":[{"type":"text","content":5.2,"position":["2025-01-07 17:52:53",5.2],"style":{"textAlign":"center","fill":"#FFFFFF"},"offsetY":-16,"background":{"padding":4,"style":{"radius":4,"fill":"#4583ff"}}},{"type":"text","content":1.2,"position":["2025-01-06 17:22:53",1.2],"style":{"textAlign":"center","fill":"#FFFFFF"},"offsetY":-16,"background":{"padding":4,"style":{"radius":4,"fill":"#4583ff"}}}],"tooltip":{"fields":["created_time","cost","id"],"enterable":true,"follow":true},"theme":"light"}"
/>
</div>
</div>
Expand All @@ -336,13 +336,25 @@ exports[`SqlAnalyze/ManagementConfAnalyze filter sql execution plan cost 1`] = `
</div>
<div
class="ant-space-item"
style="margin-right: 8px;"
>
<span
class="ant-typography ant-typography-secondary css-dev-only-do-not-override-txh9fw"
>
2025-01-09 12:00:00
</span>
</div>
<div
class="ant-space-item"
>
<span
class="ant-typography ant-typography-secondary css-dev-only-do-not-override-txh9fw"
>
代价
3
</span>
</div>
</div>
</div>
<div
Expand Down Expand Up @@ -6478,7 +6490,7 @@ exports[`SqlAnalyze/ManagementConfAnalyze should get analyze data from origin 1`
style="margin-right: 8px;"
>
<h3>
SQL执行计划 Cost趋势
SQL执行计划代价趋势
</h3>
</div>
<div
Expand Down Expand Up @@ -6605,32 +6617,8 @@ exports[`SqlAnalyze/ManagementConfAnalyze should get analyze data from origin 1`
<div
class="ant-spin-nested-loading css-dev-only-do-not-override-txh9fw"
>
<div>
<div
aria-busy="true"
aria-live="polite"
class="ant-spin ant-spin-spinning css-dev-only-do-not-override-txh9fw"
>
<span
class="ant-spin-dot ant-spin-dot-spin"
>
<i
class="ant-spin-dot-item"
/>
<i
class="ant-spin-dot-item"
/>
<i
class="ant-spin-dot-item"
/>
<i
class="ant-spin-dot-item"
/>
</span>
</div>
</div>
<div
class="ant-spin-container ant-spin-blur"
class="ant-spin-container"
>
<div
class="chart-wrapper css-1hgbe7b"
Expand Down Expand Up @@ -6724,13 +6712,11 @@ exports[`SqlAnalyze/ManagementConfAnalyze should get analyze data from origin 1`
</div>
<div
class="ant-space-item"
>
<span
class="ant-typography ant-typography-secondary css-dev-only-do-not-override-txh9fw"
>
2025-01-09 12:00:00
</span>
</div>
style="margin-right: 8px;"
/>
<div
class="ant-space-item"
/>
</div>
</div>
<div
Expand Down
18 changes: 14 additions & 4 deletions packages/sqle/src/page/SqlAnalyze/ManagementConf/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ describe('SqlAnalyze/ManagementConfAnalyze', () => {
instance_audit_plan,
'getAuditPlanSqlAnalysisDataV1'
);
spy.mockImplementation(() => resolveThreeSecond(AuditPlanSqlAnalyzeData));
spy.mockImplementation(() =>
resolveThreeSecond({
...AuditPlanSqlAnalyzeData,
sql_explain: {
...AuditPlanSqlAnalyzeData.sql_explain,
cost: 3
}
})
);
return spy;
};

Expand Down Expand Up @@ -90,14 +98,15 @@ describe('SqlAnalyze/ManagementConfAnalyze', () => {
await act(async () => jest.advanceTimersByTime(3000));
expect(container).toMatchSnapshot();

expect(screen.getByText('SQL执行计划 Cost趋势')).toBeInTheDocument();
expect(screen.getByText('SQL执行计划代价趋势')).toBeInTheDocument();
expect(getSqlManageSqlAnalysisChartSpy).toHaveBeenCalledTimes(1);
expect(getSqlManageSqlAnalysisChartSpy).toHaveBeenNthCalledWith(1, {
sql_manage_id: '2',
project_name: projectName,
metric_name: 'explain_cost',
start_time: translateTimeForRequest(currentTime.subtract(24, 'hour')),
end_time: translateTimeForRequest(currentTime)
end_time: translateTimeForRequest(currentTime),
latest_point_enabled: true
});

fireEvent.click(screen.getByText('7天'));
Expand All @@ -108,7 +117,8 @@ describe('SqlAnalyze/ManagementConfAnalyze', () => {
project_name: projectName,
metric_name: 'explain_cost',
start_time: translateTimeForRequest(currentTime.subtract(7, 'day')),
end_time: translateTimeForRequest(currentTime)
end_time: translateTimeForRequest(currentTime),
latest_point_enabled: false
});
});

Expand Down
Loading

0 comments on commit abd5a8d

Please sign in to comment.