|
@@ -55,41 +55,43 @@ const createMockResponse = (status: number, data?: any) => ({
|
|
|
// Mock API client
|
|
// Mock API client
|
|
|
vi.mock('../../src/api/salaryClient', () => {
|
|
vi.mock('../../src/api/salaryClient', () => {
|
|
|
const mockSalaryClient = {
|
|
const mockSalaryClient = {
|
|
|
- $get: vi.fn(() => Promise.resolve(createMockResponse(200, {
|
|
|
|
|
- data: [
|
|
|
|
|
- {
|
|
|
|
|
- id: 1,
|
|
|
|
|
- provinceId: 110000,
|
|
|
|
|
- cityId: 110100,
|
|
|
|
|
- districtId: null,
|
|
|
|
|
- basicSalary: 5000.00,
|
|
|
|
|
- allowance: 1000.00,
|
|
|
|
|
- insurance: 500.00,
|
|
|
|
|
- housingFund: 800.00,
|
|
|
|
|
- totalSalary: 4700.00,
|
|
|
|
|
- updateTime: '2024-01-01T00:00:00Z',
|
|
|
|
|
- province: { id: 110000, name: '北京市' },
|
|
|
|
|
- city: { id: 110100, name: '北京市辖区' },
|
|
|
|
|
- district: null
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- id: 2,
|
|
|
|
|
- provinceId: 310000,
|
|
|
|
|
- cityId: 310100,
|
|
|
|
|
- districtId: 310101,
|
|
|
|
|
- basicSalary: 6000.00,
|
|
|
|
|
- allowance: 1200.00,
|
|
|
|
|
- insurance: 600.00,
|
|
|
|
|
- housingFund: 900.00,
|
|
|
|
|
- totalSalary: 5700.00,
|
|
|
|
|
- updateTime: '2024-01-02T00:00:00Z',
|
|
|
|
|
- province: { id: 310000, name: '上海市' },
|
|
|
|
|
- city: { id: 310100, name: '上海市辖区' },
|
|
|
|
|
- district: { id: 310101, name: '黄浦区' }
|
|
|
|
|
- }
|
|
|
|
|
- ],
|
|
|
|
|
- total: 2
|
|
|
|
|
- }))),
|
|
|
|
|
|
|
+ list: {
|
|
|
|
|
+ $get: vi.fn(() => Promise.resolve(createMockResponse(200, {
|
|
|
|
|
+ data: [
|
|
|
|
|
+ {
|
|
|
|
|
+ id: 1,
|
|
|
|
|
+ provinceId: 110000,
|
|
|
|
|
+ cityId: 110100,
|
|
|
|
|
+ districtId: null,
|
|
|
|
|
+ basicSalary: 5000.00,
|
|
|
|
|
+ allowance: 1000.00,
|
|
|
|
|
+ insurance: 500.00,
|
|
|
|
|
+ housingFund: 800.00,
|
|
|
|
|
+ totalSalary: 4700.00,
|
|
|
|
|
+ updateTime: '2024-01-01T00:00:00Z',
|
|
|
|
|
+ province: { id: 110000, name: '北京市' },
|
|
|
|
|
+ city: { id: 110100, name: '北京市辖区' },
|
|
|
|
|
+ district: null
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ id: 2,
|
|
|
|
|
+ provinceId: 310000,
|
|
|
|
|
+ cityId: 310100,
|
|
|
|
|
+ districtId: 310101,
|
|
|
|
|
+ basicSalary: 6000.00,
|
|
|
|
|
+ allowance: 1200.00,
|
|
|
|
|
+ insurance: 600.00,
|
|
|
|
|
+ housingFund: 900.00,
|
|
|
|
|
+ totalSalary: 5700.00,
|
|
|
|
|
+ updateTime: '2024-01-02T00:00:00Z',
|
|
|
|
|
+ province: { id: 310000, name: '上海市' },
|
|
|
|
|
+ city: { id: 310100, name: '上海市辖区' },
|
|
|
|
|
+ district: { id: 310101, name: '黄浦区' }
|
|
|
|
|
+ }
|
|
|
|
|
+ ],
|
|
|
|
|
+ total: 2
|
|
|
|
|
+ })))
|
|
|
|
|
+ },
|
|
|
create: {
|
|
create: {
|
|
|
$post: vi.fn(() => Promise.resolve(createMockResponse(200, {
|
|
$post: vi.fn(() => Promise.resolve(createMockResponse(200, {
|
|
|
id: 3,
|
|
id: 3,
|
|
@@ -254,7 +256,7 @@ describe('薪资管理集成测试', () => {
|
|
|
// 验证API调用
|
|
// 验证API调用
|
|
|
await waitFor(() => {
|
|
await waitFor(() => {
|
|
|
const mockClient = salaryClientManager.get();
|
|
const mockClient = salaryClientManager.get();
|
|
|
- expect(mockClient.$get).toHaveBeenCalledWith({
|
|
|
|
|
|
|
+ expect(mockClient.list.$get).toHaveBeenCalledWith({
|
|
|
query: {
|
|
query: {
|
|
|
skip: 0,
|
|
skip: 0,
|
|
|
take: 10,
|
|
take: 10,
|
|
@@ -354,7 +356,7 @@ describe('薪资管理集成测试', () => {
|
|
|
it('应该处理API错误', async () => {
|
|
it('应该处理API错误', async () => {
|
|
|
// Mock API错误
|
|
// Mock API错误
|
|
|
const mockClient = salaryClientManager.get();
|
|
const mockClient = salaryClientManager.get();
|
|
|
- mockClient.$get.mockRejectedValueOnce(new Error('获取薪资列表失败'));
|
|
|
|
|
|
|
+ (mockClient.list.$get as any).mockRejectedValueOnce(new Error('获取薪资列表失败'));
|
|
|
|
|
|
|
|
renderComponent();
|
|
renderComponent();
|
|
|
|
|
|