Skip to content

Commit 853f296

Browse files
committed
add matcher
1 parent d262b99 commit 853f296

File tree

4 files changed

+72
-33
lines changed

4 files changed

+72
-33
lines changed

admin-ui/src/jest.setup.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import '@testing-library/jest-dom';
2+
import {TextEncoder} from 'util';
23

3-
4-
// src/jest.setup.ts
5-
import '@testing-library/jest-dom';
4+
// 添加全局对象
5+
global.TextEncoder = TextEncoder;
66

77
// Mock window.matchMedia
88
Object.defineProperty(window, 'matchMedia', {
@@ -21,9 +21,14 @@ Object.defineProperty(window, 'matchMedia', {
2121

2222
// Mock ResizeObserver
2323
global.ResizeObserver = class ResizeObserver {
24-
observe() {}
25-
unobserve() {}
26-
disconnect() {}
24+
observe() {
25+
}
26+
27+
unobserve() {
28+
}
29+
30+
disconnect() {
31+
}
2732
};
2833

2934
// Suppress findDOMNode warnings in test output
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,63 @@
11
import React from 'react';
2-
import {render} from "@testing-library/react";
3-
import axios from 'axios';
2+
import {act, fireEvent, render, screen, waitFor} from "@testing-library/react";
43
import FlowPage from "@/pages/flow/work";
54

65
jest.mock('axios');
7-
const mockedAxios = axios as jest.Mocked<typeof axios>;
86

97
// test description for the component
108
describe('Welcome Component', () => {
11-
test('renders with default initial value', () => {
12-
13-
mockedAxios.get.mockImplementation((url) => {
14-
if (url === '/api/users/123') {
15-
return Promise.resolve({
16-
data: { name: 'John Doe', email: '[email protected]' }
17-
});
18-
}
19-
if (url === '/api/users/123/posts') {
20-
return Promise.resolve({
21-
data: [{ id: 1, title: 'Post 1' }]
22-
});
23-
}
24-
if (url === '/api/users/123/followers') {
25-
return Promise.resolve({
26-
data: [{ id: 1, name: 'Follower 1' }]
27-
});
28-
}
29-
return Promise.reject(new Error('Not found'));
30-
});
9+
10+
test('renders with default initial value', async () => {
3111

3212
// render the component
33-
const {getByTestId} =render(
34-
<FlowPage/>
13+
render(
14+
<FlowPage/>
3515
);
3616

37-
const flowTable = getByTestId("flow-table");
17+
const flowTable = screen.getByTestId("flow-table");
3818
expect(flowTable).toBeInTheDocument();
19+
20+
const flowAddBtn = screen.getByTestId("flow-add-btn");
21+
expect(flowAddBtn).toBeInTheDocument();
22+
23+
24+
await act(async () => {
25+
fireEvent.click(flowAddBtn);
26+
});
27+
28+
await waitFor(() => {
29+
const flowEditor = screen.getByTestId("flow-editor");
30+
expect(flowEditor).toBeInTheDocument();
31+
});
32+
33+
const inputTitle = screen.getByLabelText('标题');
34+
const inputCode = screen.getByLabelText('编码');
35+
const inputDescription = screen.getByLabelText('描述');
36+
const inputPostponedMax = screen.getByLabelText('最大延期次数');
37+
const inputSkipIfSameApprover = screen.getByLabelText('是否跳过相同审批人');
38+
const submitButton = screen.getByTestId('flow-editor-submit');
39+
expect(submitButton).toBeInTheDocument();
40+
41+
42+
await act(async () => {
43+
fireEvent.change(inputTitle, {target: {value: 'test'}});
44+
expect(inputTitle).toHaveValue('test');
45+
fireEvent.change(inputCode, {target: {value: 'test'}});
46+
expect(inputCode).toHaveValue('test');
47+
fireEvent.change(inputDescription, {target: {value: 'test'}});
48+
expect(inputDescription).toHaveValue('test');
49+
fireEvent.change(inputPostponedMax, {target: {value: '1'}});
50+
expect(inputPostponedMax).toHaveValue('1');
51+
fireEvent.change(inputSkipIfSameApprover, {target: {value: 'true'}});
52+
expect(inputSkipIfSameApprover).toHaveValue('true');
53+
fireEvent.click(submitButton);
54+
});
55+
56+
await waitFor(() => {
57+
// todo 不敢展示,却必须得展示才能正常
58+
const submitButton = screen.getByTestId('flow-editor-submit');
59+
expect(submitButton).toBeInTheDocument();
60+
});
61+
3962
});
4063
});

admin-ui/src/pages/flow/work/index.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ const FlowPage = () => {
178178
toolBarRender={() => {
179179
return [
180180
<Button
181+
data-testid={"flow-add-btn"}
181182
type={"primary"}
182183
onClick={() => {
183184
form.resetFields();
@@ -197,13 +198,19 @@ const FlowPage = () => {
197198
/>
198199

199200
<ModalForm
201+
data-testid={"flow-editor"}
200202
title="编辑流程"
201203
form={form}
202204
open={editorVisible}
203205
modalProps={{
204206
destroyOnClose: true,
205207
onClose: () => setEditorVisible(false),
206-
onCancel: () => setEditorVisible(false)
208+
onCancel: () => setEditorVisible(false),
209+
}}
210+
submitter={{
211+
submitButtonProps:{
212+
"data-testid":"flow-editor-submit",
213+
},
207214
}}
208215
onFinish={handlerSave}
209216
>

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/matcher/OperatorMatcher.java

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import lombok.Getter;
66
import org.springframework.util.StringUtils;
77

8+
import java.util.ArrayList;
89
import java.util.Arrays;
910
import java.util.List;
1011
import java.util.stream.Collectors;
@@ -114,6 +115,9 @@ public static OperatorMatcher creatorOperatorMatcher() {
114115
*/
115116
public List<Long> matcher(FlowSession flowSession) {
116117
List<Object> values = (List<Object>) runtime.invokeMethod("run", flowSession);
118+
if (values == null) {
119+
return new ArrayList<>();
120+
}
117121
return values.stream().map(item -> {
118122
if (item instanceof Number) {
119123
return ((Number) item).longValue();

0 commit comments

Comments
 (0)