-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
283 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`admin/groups form 1`] = ` | ||
[MockFunction] { | ||
"calls": Array [ | ||
Array [ | ||
Object { | ||
"method": "get", | ||
"url": "/admin-api/groups/defaults", | ||
}, | ||
], | ||
Array [ | ||
Object { | ||
"data": Object { | ||
"id": 1, | ||
"name": "测试分组", | ||
"sort": 50, | ||
}, | ||
"loading": true, | ||
"method": "POST", | ||
"url": "/admin-api/groups", | ||
}, | ||
], | ||
], | ||
"results": Array [ | ||
Object { | ||
"type": "return", | ||
"value": Promise { | ||
"reject": [Function], | ||
"resolve": [Function], | ||
}, | ||
}, | ||
Object { | ||
"type": "return", | ||
"value": Promise { | ||
"reject": [Function], | ||
"resolve": [Function], | ||
}, | ||
}, | ||
], | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`admin/groups delete 1`] = ` | ||
[MockFunction] { | ||
"calls": Array [ | ||
Array [ | ||
Object { | ||
"method": "get", | ||
"url": "/admin-api/groups?page=1&limit=20", | ||
}, | ||
], | ||
Array [ | ||
Object { | ||
"dataType": "json", | ||
"loading": true, | ||
"method": "delete", | ||
"url": "/admin-api/groups/1", | ||
}, | ||
], | ||
], | ||
"results": Array [ | ||
Object { | ||
"type": "return", | ||
"value": Promise { | ||
"reject": [Function], | ||
"resolve": [Function], | ||
}, | ||
}, | ||
Object { | ||
"type": "return", | ||
"value": Promise { | ||
"reject": [Function], | ||
"resolve": [Function], | ||
}, | ||
}, | ||
], | ||
} | ||
`; | ||
|
||
exports[`admin/groups index 1`] = ` | ||
[MockFunction] { | ||
"calls": Array [ | ||
Array [ | ||
Object { | ||
"method": "get", | ||
"url": "/admin-api/groups?page=1&limit=20", | ||
}, | ||
], | ||
], | ||
"results": Array [ | ||
Object { | ||
"type": "return", | ||
"value": Promise { | ||
"reject": [Function], | ||
"resolve": [Function], | ||
}, | ||
}, | ||
], | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React from 'react'; | ||
import $ from 'miaoxing'; | ||
import Form from '../../../../pages/admin/groups/new'; | ||
import {app} from '@mxjs/app'; | ||
import {render, screen, fireEvent, waitFor} from '@testing-library/react'; | ||
import {MemoryRouter} from 'react-router'; | ||
import {bootstrap, createPromise, resetUrl, setUrl} from '@mxjs/test'; | ||
|
||
bootstrap(); | ||
|
||
describe('admin/groups', () => { | ||
beforeEach(function () { | ||
setUrl('admin/groups/new'); | ||
app.page = { | ||
collection: 'admin/groups', | ||
index: false, | ||
}; | ||
}); | ||
|
||
afterEach(() => { | ||
resetUrl(); | ||
app.page = {}; | ||
}); | ||
|
||
test('form', async () => { | ||
const promise = createPromise(); | ||
const promise2 = createPromise(); | ||
const promise3 = createPromise(); | ||
|
||
$.http = jest.fn() | ||
// 读取默认数据 | ||
.mockImplementationOnce(() => promise.resolve({ | ||
code: 1, | ||
data: { | ||
id: 1, | ||
sort: 50, | ||
}, | ||
})) | ||
.mockImplementationOnce(() => promise2.resolve({ | ||
code: 1, | ||
data: [], | ||
})) | ||
.mockImplementationOnce(() => promise3.resolve({ | ||
code: 1, | ||
data: [], | ||
})); | ||
|
||
const {getByLabelText} = render(<MemoryRouter> | ||
<Form/> | ||
</MemoryRouter>); | ||
|
||
await Promise.all([promise]); | ||
|
||
// 看到表单加载了数据 | ||
await waitFor(() => expect(getByLabelText('顺序').value).toBe('50')); | ||
expect(getByLabelText('名称').value).toBe(''); | ||
|
||
// 提交表单 | ||
fireEvent.change(getByLabelText('名称'), {target: {value: '测试分组'}}); | ||
fireEvent.click(screen.getByText('提 交')); | ||
|
||
await Promise.all([promise2]); | ||
expect($.http).toMatchSnapshot(); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.