Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test](sqle/RuleTemplateList): add unit tests #186

Merged
merged 2 commits into from
Feb 4, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,229 @@ exports[`sqle/components/ReportDrawer render snap when has data 1`] = `
</div>
</body>
`;

exports[`sqle/components/ReportDrawer render snap when showSourceFile is true 1`] = `
<body>
<div />
<div>
<div
class="ant-drawer ant-drawer-right css-dev-only-do-not-override-txh9fw ant-drawer-open"
tabindex="-1"
>
<div
class="ant-drawer-mask"
/>
<div
aria-hidden="true"
data-sentinel="start"
style="width: 0px; height: 0px; overflow: hidden; outline: none; position: absolute;"
tabindex="0"
/>
<div
class="ant-drawer-content-wrapper"
style="width: 720px;"
>
<div
aria-modal="true"
class="ant-drawer-content basic-drawer-wrapper drawer-wrapper-no-padding css-1q29jje"
role="dialog"
>
<div
class="ant-drawer-wrapper-body"
>
<div
class="ant-drawer-header"
>
<div
class="ant-drawer-header-title"
>
<div
class="ant-drawer-title"
>
this is a title
</div>
</div>
</div>
<div
class="ant-drawer-body"
>
<div
class="closed-icon-custom"
>
<span
aria-label="close"
class="anticon anticon-close"
role="img"
>
<svg
aria-hidden="true"
data-icon="close"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8 295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512 196.9 824.9A7.95 7.95 0 00203 838h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1 216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z"
/>
</svg>
</span>
</div>
<div
class="audit-report-wrapper css-14msg9y"
>
<section
class="wrapper-item"
>
<h3
class="ant-typography css-dev-only-do-not-override-txh9fw"
>
审核结果
</h3>
<div
class="wrapper-cont"
>
<div
class="result-item css-30pox0"
>
<div
class="css-1avyf41"
>
<span
class="icon-wrapper"
/>
<span
class="text-wrapper"
>
message
</span>
</div>
<div
class="annotation-wrapper"
>
annotation
<a
class="ant-typography css-dev-only-do-not-override-txh9fw"
href="/sqle/rule/knowledge/rule a/mysql"
rel="noopener noreferrer"
target="_blank"
>
查看更多
</a>
</div>
</div>
</div>
</section>
<section
class="wrapper-item"
>
<div
class="title-wrap"
>
<h3
class="ant-typography css-dev-only-do-not-override-txh9fw"
>
SQL语句
</h3>
<div
class="ant-space css-dev-only-do-not-override-txh9fw ant-space-horizontal ant-space-align-center"
>
<div
class="ant-space-item"
style="margin-right: 8px;"
>
<span
class="ant-tag ant-tag-default basic-tag-wrapper basic-default-tag-wrapper css-f4phf8 css-dev-only-do-not-override-txh9fw"
>
<span
class="custom-icon css-u3jcp4"
role="img"
>
<svg
fill="none"
height="18"
viewBox="0 0 18 18"
width="18"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M15 16.5H3C2.80109 16.5 2.61032 16.421 2.46967 16.2803C2.32902 16.1397 2.25 15.9489 2.25 15.75V2.25C2.25 2.05109 2.32902 1.86032 2.46967 1.71967C2.61032 1.57902 2.80109 1.5 3 1.5H15C15.1989 1.5 15.3897 1.57902 15.5303 1.71967C15.671 1.86032 15.75 2.05109 15.75 2.25V15.75C15.75 15.9489 15.671 16.1397 15.5303 16.2803C15.3897 16.421 15.1989 16.5 15 16.5ZM6 5.25V6.75H12V5.25H6ZM6 8.25V9.75H12V8.25H6ZM6 11.25V12.75H9.75V11.25H6Z"
fill="#4583FF"
/>
</svg>
</span>
<span>
<span
class="sql-source-title"
>
所在文件
</span>
file_source
</span>
</span>
</div>
<div
class="ant-space-item"
>
<span
class="ant-tag ant-tag-default basic-tag-wrapper basic-default-tag-wrapper css-f4phf8 css-dev-only-do-not-override-txh9fw"
>
<span
class="custom-icon css-u3jcp4"
role="img"
>
<svg
height="18"
id="mx_n_1705397970752"
version="1.1"
viewBox="0 0 1024 1024"
width="18"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M512 938.666667c-53.333333 0-384-257.258667-384-469.333334S299.925333 85.333333 512 85.333333s384 171.925333 384 384-330.666667 469.333333-384 469.333334z m0-352c64.8 0 117.333333-52.533333 117.333333-117.333334s-52.533333-117.333333-117.333333-117.333333-117.333333 52.533333-117.333333 117.333333 52.533333 117.333333 117.333333 117.333334z"
fill="#4583FF"
/>
</svg>
</span>
<span>
<span
class="sql-source-title"
>
所在行
</span>
3
</span>
</span>
</div>
</div>
</div>
<div
class="wrapper-cont"
>
<input
class="custom-monaco-editor css-baixa9"
height="90%"
language="sql"
options="{\\"readOnly\\":true,\\"automaticLayout\\":true,\\"minimap\\":{\\"enabled\\":false},\\"fontFamily\\":\\"SF Mono\\",\\"fontSize\\":14,\\"fontWeight\\":\\"400\\",\\"lineNumbersMinChars\\":2,\\"suggestFontSize\\":14}"
value="select 1"
width="100%"
/>
</div>
</section>
</div>
</div>
</div>
</div>
</div>
<div
aria-hidden="true"
data-sentinel="end"
style="width: 0px; height: 0px; overflow: hidden; outline: none; position: absolute;"
tabindex="0"
/>
</div>
</div>
</body>
`;
26 changes: 26 additions & 0 deletions packages/sqle/src/components/ReportDrawer/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,32 @@ describe('sqle/components/ReportDrawer', () => {
data: {
sql: 'select 1',
sqlSourceFile: 'file_source',
sqlStartLine: 3,
auditResult: [
{
rule_name: 'rule a',
message: 'message',
level: 'level',
annotation: 'annotation',
db_type: 'mysql'
}
]
},
onClose: jest.fn()
});
expect(baseElement).toMatchSnapshot();
});

it('render snap when showSourceFile is true', () => {
const { baseElement } = customRender({
open: true,
title: 'this is a title',
showAnnotation: true,
showSourceFile: true,
data: {
sql: 'select 1',
sqlSourceFile: 'file_source',
sqlStartLine: 3,
auditResult: [
{
rule_name: 'rule a',
Expand Down
17 changes: 12 additions & 5 deletions packages/sqle/src/components/RuleList/RuleList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import BasicEmpty from '@actiontech/shared/lib/components/BasicEmpty';
import RuleDetailModal from './RuleDetailModal';
import { useBoolean } from 'ahooks';
import { isEqual } from 'lodash';

const scrollStepRange = 30;

Expand Down Expand Up @@ -203,10 +204,16 @@
}
};

const rulesRef = useRef<IRuleResV1[]>();

useEffect(() => {
stepRef.current = 0;
setScrollData([]);
onScroll();
// fix Warning: Maximum update depth exceeded
if (!isEqual(rulesRef.current, rules)) {
rulesRef.current = rules;
stepRef.current = 0;
setScrollData([]);
onScroll();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [rules]);

Expand Down Expand Up @@ -237,10 +244,10 @@
}
scrollableTarget="rule-list-wrapper-id"
>
{scrollData?.map((v) => {
{scrollData?.map((v, index) => {
return (
<RuleItemStyleWrapper
key={v.rule_name}
key={v.rule_name || index}

Check warning on line 250 in packages/sqle/src/components/RuleList/RuleList.tsx

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
style={{
cursor:
isAction || enableCheckDetail ? 'pointer' : 'default'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const CustomRuleList: React.FC = () => {
(res) =>
res.data.data?.map((v) => ({
...v,
rule_name: v.rule_id,
level: v.level as RuleResV1LevelEnum | undefined
})) ?? []
)
Expand Down
Loading
Loading