Skip to content

Commit d17932e

Browse files
authored
Merge pull request #86 from codingapi/dev
Dev
2 parents d6b31ea + f5f31c4 commit d17932e

File tree

24 files changed

+173
-150
lines changed

24 files changed

+173
-150
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
>

admin-ui/src/pages/welcome/__test__/index.test.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Welcome from '../index';
33
import {render} from "@testing-library/react";
44
import store from "@/store/Redux";
55
import {Provider} from "react-redux";
6+
import {Calculate} from "../data";
67

78
// test description for the component
89
describe('Welcome Component', () => {
@@ -23,4 +24,10 @@ describe('Welcome Component', () => {
2324
// log the element text content
2425
console.log(countElement?.textContent);
2526
});
27+
28+
29+
test('method add test', () => {
30+
const sum = Calculate.add(1,1);
31+
expect(sum).toBe(2);
32+
});
2633
});

admin-ui/src/pages/welcome/data.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export class Calculate{
2+
3+
static add = (a: number, b: number) => {
4+
return a + b;
5+
}
6+
7+
static sub = (a: number, b: number) => {
8+
return a - b;
9+
}
10+
11+
static mul = (a: number, b: number) => {
12+
return a * b;
13+
}
14+
15+
static div = (a: number, b: number) => {
16+
return a / b;
17+
}
18+
}

admin-ui/src/pages/welcome/index.tsx

+21-95
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,32 @@
1-
import React, {useCallback, useMemo, useState} from 'react';
1+
import React from 'react';
2+
import logo from '@/assets/logo.svg';
23
import './index.scss';
4+
import {useSelector} from "react-redux";
5+
import {RootState} from "@/store/Redux";
6+
import RoleControl from "@/utils/RoleControl";
37
import Page from "@/components/Layout/Page";
48

5-
import {AgGridReact} from 'ag-grid-react';
6-
import {AllCommunityModule, ModuleRegistry, themeQuartz,} from "ag-grid-community";
7-
import {AG_GRID_LOCALE_CN} from '@ag-grid-community/locale';
8-
9-
const localeText = AG_GRID_LOCALE_CN;
10-
// Register all Community features
11-
ModuleRegistry.registerModules([AllCommunityModule]);
12-
13-
14-
const myTheme = themeQuartz.withParams({
15-
/* Low spacing = very compact */
16-
spacing: 2,
17-
accentColor: "red",
18-
19-
});
209
const Index = () => {
21-
const [rowData, setRowData] = useState();
22-
const [columnDefs, setColumnDefs] = useState([
23-
{
24-
field: "athlete",
25-
minWidth: 170,
26-
headerName: "运动员"
27-
},
28-
{
29-
field: "age",
30-
headerName: "年龄"
31-
},
32-
{
33-
field: "country",
34-
headerName: '国家信息',
35-
headerClass: 'country-header',
36-
children: [
37-
{
38-
field: "country",
39-
headerName: "国家"
40-
},
41-
{field: "name"},
42-
{field: "code"}
43-
]
44-
},
45-
{field: "year", headerName: "年份"},
46-
{field: "date", headerName: "日期"},
47-
{field: "sport", headerName: "运动"},
48-
{field: "gold", headerName: "金牌"},
49-
{field: "silver", headerName: "银牌"},
50-
{field: "bronze", headerName: "铜牌"},
51-
{field: "total", headerName: "总计",editable: false},
52-
]);
53-
const theme = useMemo(() => {
54-
return myTheme;
55-
}, []);
56-
const defaultColDef = useMemo(() => {
57-
return {
58-
editable: true,
59-
filter: true,
60-
};
61-
}, []);
62-
63-
const onGridReady = useCallback((params: any) => {
64-
fetch("https://www.ag-grid.com/example-assets/olympic-winners.json")
65-
.then((resp) => resp.json())
66-
.then((data) => setRowData(data));
67-
}, []);
6810

11+
const counter = useSelector((state: RootState) => state.counter.value);
12+
const username = localStorage.getItem('username');
6913

7014
return (
7115
<Page enablePageContainer={true}>
72-
<div
73-
// define a height because the Data Grid will fill the size of the parent container
74-
style={{height: 500}}
75-
>
76-
<AgGridReact
77-
rowData={rowData}
78-
localeText={localeText}
79-
onRowDataUpdated={(params) => {
80-
console.log("Row Data Updated", params)
81-
}}
82-
onCellValueChanged={(event) => {
83-
console.log(`New Cell Value:`, event);
84-
// 当金牌,银牌,铜牌的值发生变化时,更新总计
85-
86-
//@ts-ignore
87-
if (['gold', 'silver', 'bronze'].includes(event.colDef.field)) {
88-
const gold = event.data.gold;
89-
const silver = event.data.silver;
90-
const bronze = event.data.bronze;
91-
const total = gold + silver + bronze;
92-
event.data.total = total;
93-
event.api.refreshCells({columns: ['total']});
94-
}
95-
}}
96-
97-
columnDefs={columnDefs}
98-
theme={theme}
99-
pagination={true}
100-
defaultColDef={defaultColDef}
101-
onGridReady={onGridReady}
102-
103-
/>
16+
<div className="App">
17+
<header className="App-header">
18+
<img src={logo} className="App-logo" alt="logo"/>
19+
<p>
20+
hi {username} , Redux counter: {counter}, Roles: {RoleControl.roles().map(item => (
21+
<label
22+
key={item}
23+
style={{
24+
margin: '0 5px',
25+
padding: '5px',
26+
}}>{item}</label>
27+
))}
28+
</p>
29+
</header>
10430
</div>
10531
</Page>
10632
);

example/example-application/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.49</version>
8+
<version>3.3.51</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-domain/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.49</version>
8+
<version>3.3.51</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-infra-flow/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.49</version>
8+
<version>3.3.51</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-infra-flow/src/main/java/com/codingapi/example/query/FlowRecordQueryImpl.java

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ public class FlowRecordQueryImpl implements FlowRecordQuery {
1818
private final FlowRecordEntityRepository flowRecordEntityRepository;
1919
private final UserRepository userRepository;
2020

21+
22+
@Override
23+
public FlowRecord getFlowRecordById(long id) {
24+
return FlowRecordConvertor.convert(flowRecordEntityRepository.getFlowRecordEntityById(id),userRepository);
25+
}
26+
2127
@Override
2228
public Page<FlowRecord> findAll(PageRequest pageRequest) {
2329
Page<FlowRecordEntity> page = flowRecordEntityRepository.findAllFlowRecords(pageRequest);

example/example-infra-jpa/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.49</version>
8+
<version>3.3.51</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-server/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.49</version>
8+
<version>3.3.51</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</parent>
1818

1919
<artifactId>springboot-example</artifactId>
20-
<version>3.3.49</version>
20+
<version>3.3.51</version>
2121

2222
<name>springboot-example</name>
2323
<description>springboot-example project for Spring Boot</description>

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<groupId>com.codingapi.springboot</groupId>
1717
<artifactId>springboot-parent</artifactId>
18-
<version>3.3.49</version>
18+
<version>3.3.51</version>
1919

2020
<url>https://github.com/codingapi/springboot-framewrok</url>
2121
<name>springboot-parent</name>

springboot-starter-data-authorization/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.codingapi.springboot</groupId>
88
<artifactId>springboot-parent</artifactId>
9-
<version>3.3.49</version>
9+
<version>3.3.51</version>
1010
</parent>
1111

1212
<artifactId>springboot-starter-data-authorization</artifactId>

0 commit comments

Comments
 (0)