style: apply prettier formatting
Apply consistent formatting across all files (line endings, spacing) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { ErpAuthService } from '../../src/main/services/erp/erp-auth';
|
||||
import type { ErpConfig } from '../../src/main/types/erp.types';
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { ErpAuthService } from '../../src/main/services/erp/erp-auth'
|
||||
import type { ErpConfig } from '../../src/main/types/erp.types'
|
||||
|
||||
describe('ERP Authentication Service (Unit)', () => {
|
||||
describe('Session Management', () => {
|
||||
@@ -8,52 +8,52 @@ describe('ERP Authentication Service (Unit)', () => {
|
||||
const config: ErpConfig = {
|
||||
url: 'https://test.example.com',
|
||||
username: 'testuser',
|
||||
password: 'testpass',
|
||||
};
|
||||
password: 'testpass'
|
||||
}
|
||||
|
||||
const service = new ErpAuthService(config);
|
||||
const service = new ErpAuthService(config)
|
||||
|
||||
expect(service).toBeDefined();
|
||||
expect(service.isActive()).toBe(false);
|
||||
});
|
||||
expect(service).toBeDefined()
|
||||
expect(service.isActive()).toBe(false)
|
||||
})
|
||||
|
||||
it('should throw error when getting session before login', () => {
|
||||
const config: ErpConfig = {
|
||||
url: 'https://test.example.com',
|
||||
username: 'testuser',
|
||||
password: 'testpass',
|
||||
};
|
||||
password: 'testpass'
|
||||
}
|
||||
|
||||
const service = new ErpAuthService(config);
|
||||
const service = new ErpAuthService(config)
|
||||
|
||||
expect(() => service.getSession()).toThrow('Not logged in. Call login() first.');
|
||||
});
|
||||
expect(() => service.getSession()).toThrow('Not logged in. Call login() first.')
|
||||
})
|
||||
|
||||
it('should report inactive status before login', () => {
|
||||
const config: ErpConfig = {
|
||||
url: 'https://test.example.com',
|
||||
username: 'testuser',
|
||||
password: 'testpass',
|
||||
};
|
||||
password: 'testpass'
|
||||
}
|
||||
|
||||
const service = new ErpAuthService(config);
|
||||
const service = new ErpAuthService(config)
|
||||
|
||||
expect(service.isActive()).toBe(false);
|
||||
});
|
||||
});
|
||||
expect(service.isActive()).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Close Method', () => {
|
||||
it('should handle close when no session exists', async () => {
|
||||
const config: ErpConfig = {
|
||||
url: 'https://test.example.com',
|
||||
username: 'testuser',
|
||||
password: 'testpass',
|
||||
};
|
||||
password: 'testpass'
|
||||
}
|
||||
|
||||
const service = new ErpAuthService(config);
|
||||
const service = new ErpAuthService(config)
|
||||
|
||||
// Should not throw when closing without session
|
||||
await expect(service.close()).resolves.toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
await expect(service.close()).resolves.toBeUndefined()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,59 +1,59 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { ExcelParser } from '../../src/main/services/excel/excel-parser';
|
||||
import type { DiscreteMaterialPlan } from '../../src/main/types/excel.types';
|
||||
import path from 'path';
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { ExcelParser } from '../../src/main/services/excel/excel-parser'
|
||||
import type { DiscreteMaterialPlan } from '../../src/main/types/excel.types'
|
||||
import path from 'path'
|
||||
|
||||
describe('Excel Parser', () => {
|
||||
it('should parse Excel file and extract material plans', async () => {
|
||||
const parser = new ExcelParser();
|
||||
const filePath = path.resolve(__dirname, '../fixtures/test-export.xlsx');
|
||||
const parser = new ExcelParser()
|
||||
const filePath = path.resolve(__dirname, '../fixtures/test-export.xlsx')
|
||||
|
||||
const plans = await parser.parse(filePath);
|
||||
const plans = await parser.parse(filePath)
|
||||
|
||||
expect(Array.isArray(plans)).toBe(true);
|
||||
expect(plans.length).toBeGreaterThan(0);
|
||||
expect(Array.isArray(plans)).toBe(true)
|
||||
expect(plans.length).toBeGreaterThan(0)
|
||||
|
||||
const firstPlan = plans[0];
|
||||
expect(firstPlan).toHaveProperty('orderNumber');
|
||||
expect(firstPlan).toHaveProperty('materialCode');
|
||||
});
|
||||
const firstPlan = plans[0]
|
||||
expect(firstPlan).toHaveProperty('orderNumber')
|
||||
expect(firstPlan).toHaveProperty('materialCode')
|
||||
})
|
||||
|
||||
it('should parse all material fields correctly', async () => {
|
||||
const parser = new ExcelParser();
|
||||
const filePath = path.resolve(__dirname, '../fixtures/test-export.xlsx');
|
||||
const parser = new ExcelParser()
|
||||
const filePath = path.resolve(__dirname, '../fixtures/test-export.xlsx')
|
||||
|
||||
const plans = await parser.parse(filePath);
|
||||
const plans = await parser.parse(filePath)
|
||||
|
||||
expect(plans.length).toBe(3);
|
||||
expect(plans.length).toBe(3)
|
||||
|
||||
// Check first material
|
||||
expect(plans[0].orderNumber).toBe('SC202501001');
|
||||
expect(plans[0].materialCode).toBe('M001');
|
||||
expect(plans[0].materialName).toBe('钢材A');
|
||||
expect(plans[0].specification).toBe('规格1');
|
||||
expect(plans[0].model).toBe('型号1');
|
||||
expect(plans[0].drawingNumber).toBe('图号1');
|
||||
expect(plans[0].material).toBe('材质1');
|
||||
expect(plans[0].quantity).toBe(50);
|
||||
expect(plans[0].unit).toBe('kg');
|
||||
expect(plans[0].requiredDate).toBe('2025-02-10');
|
||||
expect(plans[0].warehouse).toBe('仓库1');
|
||||
expect(plans[0].unitUsage).toBe(0.5);
|
||||
expect(plans[0].cumulativeOutboundQty).toBe(0);
|
||||
expect(plans[0].orderNumber).toBe('SC202501001')
|
||||
expect(plans[0].materialCode).toBe('M001')
|
||||
expect(plans[0].materialName).toBe('钢材A')
|
||||
expect(plans[0].specification).toBe('规格1')
|
||||
expect(plans[0].model).toBe('型号1')
|
||||
expect(plans[0].drawingNumber).toBe('图号1')
|
||||
expect(plans[0].material).toBe('材质1')
|
||||
expect(plans[0].quantity).toBe(50)
|
||||
expect(plans[0].unit).toBe('kg')
|
||||
expect(plans[0].requiredDate).toBe('2025-02-10')
|
||||
expect(plans[0].warehouse).toBe('仓库1')
|
||||
expect(plans[0].unitUsage).toBe(0.5)
|
||||
expect(plans[0].cumulativeOutboundQty).toBe(0)
|
||||
|
||||
// Check third material (with some empty fields)
|
||||
expect(plans[2].materialCode).toBe('M003');
|
||||
expect(plans[2].materialName).toBe('配件C');
|
||||
expect(plans[2].quantity).toBe(200);
|
||||
});
|
||||
expect(plans[2].materialCode).toBe('M003')
|
||||
expect(plans[2].materialName).toBe('配件C')
|
||||
expect(plans[2].quantity).toBe(200)
|
||||
})
|
||||
|
||||
it('should handle empty orders gracefully', async () => {
|
||||
const parser = new ExcelParser();
|
||||
const filePath = path.resolve(__dirname, '../fixtures/test-empty-orders.xlsx');
|
||||
const parser = new ExcelParser()
|
||||
const filePath = path.resolve(__dirname, '../fixtures/test-empty-orders.xlsx')
|
||||
|
||||
const plans = await parser.parse(filePath);
|
||||
const plans = await parser.parse(filePath)
|
||||
|
||||
expect(plans).toBeDefined();
|
||||
expect(plans.length).toBe(0);
|
||||
});
|
||||
});
|
||||
expect(plans).toBeDefined()
|
||||
expect(plans.length).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,87 +1,87 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { ExtractorService } from '../../src/main/services/erp/extractor';
|
||||
import { ErpAuthService } from '../../src/main/services/erp/erp-auth';
|
||||
import type { ErpConfig } from '../../src/main/types/erp.types';
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { ExtractorService } from '../../src/main/services/erp/extractor'
|
||||
import { ErpAuthService } from '../../src/main/services/erp/erp-auth'
|
||||
import type { ErpConfig } from '../../src/main/types/erp.types'
|
||||
|
||||
describe('Extractor Service (Unit)', () => {
|
||||
let authService: ErpAuthService;
|
||||
let extractor: ExtractorService;
|
||||
let authService: ErpAuthService
|
||||
let extractor: ExtractorService
|
||||
const mockConfig: ErpConfig = {
|
||||
url: 'https://test.erp.com',
|
||||
username: 'test_user',
|
||||
password: 'test_pass',
|
||||
};
|
||||
password: 'test_pass'
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
authService = new ErpAuthService(mockConfig);
|
||||
extractor = new ExtractorService(authService, './test-downloads');
|
||||
});
|
||||
authService = new ErpAuthService(mockConfig)
|
||||
extractor = new ExtractorService(authService, './test-downloads')
|
||||
})
|
||||
|
||||
describe('Batch Creation', () => {
|
||||
it('should create single batch for small order list', () => {
|
||||
// This tests the createBatches method indirectly through extract
|
||||
// We'll need to add a public method or test through the class
|
||||
const orders = ['ORDER1', 'ORDER2', 'ORDER3'];
|
||||
const batchSize = 10;
|
||||
const orders = ['ORDER1', 'ORDER2', 'ORDER3']
|
||||
const batchSize = 10
|
||||
|
||||
// Expected: 1 batch with 3 orders
|
||||
const expectedBatches = 1;
|
||||
expect(Math.ceil(orders.length / batchSize)).toBe(expectedBatches);
|
||||
});
|
||||
const expectedBatches = 1
|
||||
expect(Math.ceil(orders.length / batchSize)).toBe(expectedBatches)
|
||||
})
|
||||
|
||||
it('should create multiple batches for large order list', () => {
|
||||
const orders = Array.from({ length: 250 }, (_, i) => `ORDER${i}`);
|
||||
const batchSize = 100;
|
||||
const orders = Array.from({ length: 250 }, (_, i) => `ORDER${i}`)
|
||||
const batchSize = 100
|
||||
|
||||
// Expected: 3 batches (100, 100, 50)
|
||||
const expectedBatches = 3;
|
||||
expect(Math.ceil(orders.length / batchSize)).toBe(expectedBatches);
|
||||
});
|
||||
const expectedBatches = 3
|
||||
expect(Math.ceil(orders.length / batchSize)).toBe(expectedBatches)
|
||||
})
|
||||
|
||||
it('should handle exact batch size', () => {
|
||||
const orders = Array.from({ length: 200 }, (_, i) => `ORDER${i}`);
|
||||
const batchSize = 100;
|
||||
const orders = Array.from({ length: 200 }, (_, i) => `ORDER${i}`)
|
||||
const batchSize = 100
|
||||
|
||||
// Expected: 2 batches exactly
|
||||
const expectedBatches = 2;
|
||||
expect(Math.ceil(orders.length / batchSize)).toBe(expectedBatches);
|
||||
});
|
||||
const expectedBatches = 2
|
||||
expect(Math.ceil(orders.length / batchSize)).toBe(expectedBatches)
|
||||
})
|
||||
|
||||
it('should handle empty order list', () => {
|
||||
const orders: string[] = [];
|
||||
const batchSize = 100;
|
||||
const orders: string[] = []
|
||||
const batchSize = 100
|
||||
|
||||
// Expected: 0 batches
|
||||
const expectedBatches = 0;
|
||||
expect(Math.ceil(orders.length / batchSize)).toBe(expectedBatches);
|
||||
});
|
||||
});
|
||||
const expectedBatches = 0
|
||||
expect(Math.ceil(orders.length / batchSize)).toBe(expectedBatches)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Service Initialization', () => {
|
||||
it('should create service instance', () => {
|
||||
expect(extractor).toBeDefined();
|
||||
expect(extractor).toBeInstanceOf(ExtractorService);
|
||||
});
|
||||
expect(extractor).toBeDefined()
|
||||
expect(extractor).toBeInstanceOf(ExtractorService)
|
||||
})
|
||||
|
||||
it('should use default download directory', () => {
|
||||
const defaultExtractor = new ExtractorService(authService);
|
||||
expect(defaultExtractor).toBeDefined();
|
||||
});
|
||||
const defaultExtractor = new ExtractorService(authService)
|
||||
expect(defaultExtractor).toBeDefined()
|
||||
})
|
||||
|
||||
it('should use custom download directory', () => {
|
||||
const customExtractor = new ExtractorService(authService, './custom-downloads');
|
||||
expect(customExtractor).toBeDefined();
|
||||
});
|
||||
});
|
||||
const customExtractor = new ExtractorService(authService, './custom-downloads')
|
||||
expect(customExtractor).toBeDefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Error Handling', () => {
|
||||
it('should handle extraction with no auth session', async () => {
|
||||
const result = await extractor.extract({
|
||||
orderNumbers: ['ORDER1'],
|
||||
});
|
||||
orderNumbers: ['ORDER1']
|
||||
})
|
||||
|
||||
expect(result.errors.length).toBeGreaterThan(0);
|
||||
expect(result.downloadedFiles).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
expect(result.errors.length).toBeGreaterThan(0)
|
||||
expect(result.downloadedFiles).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { ERP_LOCATORS } from '../../src/main/services/erp/locators';
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { ERP_LOCATORS } from '../../src/main/services/erp/locators'
|
||||
|
||||
describe('ERP Locators', () => {
|
||||
it('should have login page locators defined', () => {
|
||||
expect(ERP_LOCATORS.login.usernameInput).toBeDefined();
|
||||
expect(ERP_LOCATORS.login.passwordInput).toBeDefined();
|
||||
expect(ERP_LOCATORS.login.submitButton).toBeDefined();
|
||||
});
|
||||
expect(ERP_LOCATORS.login.usernameInput).toBeDefined()
|
||||
expect(ERP_LOCATORS.login.passwordInput).toBeDefined()
|
||||
expect(ERP_LOCATORS.login.submitButton).toBeDefined()
|
||||
})
|
||||
|
||||
it('should have main frame locator', () => {
|
||||
expect(ERP_LOCATORS.main.mainIframe).toBeDefined();
|
||||
});
|
||||
expect(ERP_LOCATORS.main.mainIframe).toBeDefined()
|
||||
})
|
||||
|
||||
it('should have extractor page locators', () => {
|
||||
expect(ERP_LOCATORS.extractor.orderNumberInputRole).toBeDefined();
|
||||
expect(ERP_LOCATORS.extractor.queryButton).toBeDefined();
|
||||
expect(ERP_LOCATORS.extractor.exportButton).toBeDefined();
|
||||
expect(ERP_LOCATORS.extractor.confirmButton).toBeDefined();
|
||||
});
|
||||
expect(ERP_LOCATORS.extractor.orderNumberInputRole).toBeDefined()
|
||||
expect(ERP_LOCATORS.extractor.queryButton).toBeDefined()
|
||||
expect(ERP_LOCATORS.extractor.exportButton).toBeDefined()
|
||||
expect(ERP_LOCATORS.extractor.confirmButton).toBeDefined()
|
||||
})
|
||||
|
||||
it('should have cleaner page locators', () => {
|
||||
expect(ERP_LOCATORS.cleaner.orderNumberInput).toBeDefined();
|
||||
expect(ERP_LOCATORS.cleaner.materialGrid).toBeDefined();
|
||||
expect(ERP_LOCATORS.cleaner.saveButton).toBeDefined();
|
||||
});
|
||||
});
|
||||
expect(ERP_LOCATORS.cleaner.orderNumberInput).toBeDefined()
|
||||
expect(ERP_LOCATORS.cleaner.materialGrid).toBeDefined()
|
||||
expect(ERP_LOCATORS.cleaner.saveButton).toBeDefined()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user