refactor(erp-auth): implement precise login result detection with three outcomes
- Add waitForLoginResult() method using Promise.race to detect: - Success: .nc-workbench-icon element visible - Failure: '名称或密码错误' error text visible - Force login: click confirm button and re-detect - Extract timeout constants (PAGE_LOAD_TIMEOUT, LOGIN_RESULT_TIMEOUT, FORCE_LOGIN_TIMEOUT) - Improve error handling with clear error messages - Add unit tests for class structure verification - Fix test setup for Electron app mock Fixes: ERP login success/failure detection was ambiguous
This commit is contained in:
@@ -1,7 +1,17 @@
|
||||
import { beforeAll, afterAll } from 'vitest'
|
||||
import { beforeAll, afterAll, vi } from 'vitest'
|
||||
import dotenv from 'dotenv'
|
||||
import path from 'path'
|
||||
|
||||
// Mock electron app module for unit tests
|
||||
vi.mock('electron', () => ({
|
||||
app: {
|
||||
isPackaged: false,
|
||||
isReady: vi.fn().mockReturnValue(false),
|
||||
getPath: vi.fn().mockReturnValue(path.join(process.cwd(), 'logs')),
|
||||
on: vi.fn()
|
||||
}
|
||||
}))
|
||||
|
||||
// Load environment variables from project root
|
||||
dotenv.config({ path: path.resolve(process.cwd(), '.env') })
|
||||
|
||||
|
||||
@@ -56,4 +56,38 @@ describe('ERP Authentication Service (Unit)', () => {
|
||||
await expect(service.close()).resolves.toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Class Structure', () => {
|
||||
let service: ErpAuthService
|
||||
|
||||
beforeEach(() => {
|
||||
const config: ErpConfig = {
|
||||
url: 'https://test.example.com',
|
||||
username: 'testuser',
|
||||
password: 'testpass'
|
||||
}
|
||||
service = new ErpAuthService(config)
|
||||
})
|
||||
|
||||
it('should have login method that returns a Promise', () => {
|
||||
expect(service.login).toBeDefined()
|
||||
expect(typeof service.login).toBe('function')
|
||||
expect(service.login()).toBeInstanceOf(Promise)
|
||||
})
|
||||
|
||||
it('should have close method', () => {
|
||||
expect(service.close).toBeDefined()
|
||||
expect(typeof service.close).toBe('function')
|
||||
})
|
||||
|
||||
it('should have getSession method', () => {
|
||||
expect(service.getSession).toBeDefined()
|
||||
expect(typeof service.getSession).toBe('function')
|
||||
})
|
||||
|
||||
it('should have isActive method', () => {
|
||||
expect(service.isActive).toBeDefined()
|
||||
expect(typeof service.isActive).toBe('function')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user