feat: add getProjectDisplayName utility
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
import { formatVersion, formatFileSize, formatDateTime } from '../utils';
|
||||
import { formatVersion, formatFileSize, formatDateTime, getProjectDisplayName } from '../utils';
|
||||
|
||||
// Mock fs module
|
||||
const fs = require('fs');
|
||||
jest.mock('fs', () => ({
|
||||
...jest.requireActual('fs'),
|
||||
readFileSync: jest.fn(),
|
||||
}));
|
||||
|
||||
describe('formatVersion', () => {
|
||||
test('应该将下划线替换为点号', () => {
|
||||
@@ -63,3 +70,39 @@ describe('formatDateTime', () => {
|
||||
expect(formatDateTime(date)).toBe('2024-01-05 09:05');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getProjectDisplayName', () => {
|
||||
const originalAliases = {
|
||||
'FT': '外放构建',
|
||||
'FT_DEV': '开发构建',
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
// Mock the aliases file
|
||||
fs.readFileSync.mockReturnValue(JSON.stringify(originalAliases));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should return display name for aliased project', () => {
|
||||
expect(getProjectDisplayName('FT')).toBe('外放构建');
|
||||
});
|
||||
|
||||
it('should return directory name when no alias exists', () => {
|
||||
expect(getProjectDisplayName('UNKNOWN')).toBe('UNKNOWN');
|
||||
});
|
||||
|
||||
it('should return directory name when aliases file is empty', () => {
|
||||
fs.readFileSync.mockReturnValue('{}');
|
||||
expect(getProjectDisplayName('FT')).toBe('FT');
|
||||
});
|
||||
|
||||
it('should return directory name when aliases file cannot be read', () => {
|
||||
fs.readFileSync.mockImplementation(() => {
|
||||
throw new Error('File not found');
|
||||
});
|
||||
expect(getProjectDisplayName('FT')).toBe('FT');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user