| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- import { describe, it, expect } from 'vitest'
- import type {
- SoftwareType,
- SoftwareTypeWithAll,
- Platform,
- TabId,
- VersionItem,
- VersionResult,
- InstallOptions,
- InstallStatus,
- InstallResult,
- InstalledInfo,
- AllInstalledInfo,
- InstallHistoryItem,
- PackageManagerResult,
- GitMirrorType,
- NodejsMirrorType,
- GitMirrorConfig,
- NodejsMirrorConfig
- } from '../shared/types'
- describe('shared types', () => {
- describe('SoftwareType', () => {
- it('should accept valid software types', () => {
- const validTypes: SoftwareType[] = ['nodejs', 'pnpm', 'vscode', 'git', 'claudeCode']
- expect(validTypes).toHaveLength(5)
- })
- })
- describe('SoftwareTypeWithAll', () => {
- it('should include all software types plus "all"', () => {
- const validTypes: SoftwareTypeWithAll[] = ['nodejs', 'pnpm', 'vscode', 'git', 'claudeCode', 'all']
- expect(validTypes).toHaveLength(6)
- })
- })
- describe('Platform', () => {
- it('should accept valid platform types', () => {
- const validPlatforms: Platform[] = ['win32', 'darwin', 'linux']
- expect(validPlatforms).toHaveLength(3)
- })
- })
- describe('TabId', () => {
- it('should accept valid tab IDs', () => {
- const validTabs: TabId[] = ['intro', 'nodejs', 'vscode', 'git', 'claudeCode', 'all']
- expect(validTabs).toHaveLength(6)
- })
- })
- describe('VersionItem', () => {
- it('should have correct structure', () => {
- const item: VersionItem = {
- value: '22.12.0',
- label: 'v22.12.0 (LTS)',
- lts: true,
- disabled: false,
- separator: false
- }
- expect(item.value).toBe('22.12.0')
- expect(item.label).toBe('v22.12.0 (LTS)')
- expect(item.lts).toBe(true)
- })
- })
- describe('VersionResult', () => {
- it('should have correct structure', () => {
- const result: VersionResult = {
- versions: [
- { value: '22.12.0', label: 'v22.12.0' }
- ],
- warning: null
- }
- expect(result.versions).toHaveLength(1)
- expect(result.warning).toBeNull()
- })
- })
- describe('InstallOptions', () => {
- it('should have correct structure', () => {
- const options: InstallOptions = {
- version: '22.12.0',
- installPnpm: true,
- installNodejs: true,
- nodejsVersion: '22.12.0',
- nodejsPath: 'C:\\nodejs',
- installVscode: true,
- vscodeVersion: '1.96.0',
- vscodePath: 'C:\\vscode',
- installGit: true,
- gitVersion: '2.47.1',
- gitPath: 'C:\\git',
- installClaudeCode: true,
- customPath: 'C:\\custom'
- }
- expect(options.version).toBe('22.12.0')
- expect(options.installPnpm).toBe(true)
- })
- })
- describe('InstallStatus', () => {
- it('should have correct structure', () => {
- const status: InstallStatus = {
- software: 'nodejs',
- message: 'Installing...',
- progress: 50,
- i18nKey: 'install.installing',
- i18nParams: { software: 'Node.js' }
- }
- expect(status.software).toBe('nodejs')
- expect(status.progress).toBe(50)
- })
- })
- describe('InstallResult', () => {
- it('should have correct structure', () => {
- const result: InstallResult = {
- software: 'nodejs',
- message: 'Installation complete',
- i18nKey: 'install.complete'
- }
- expect(result.software).toBe('nodejs')
- expect(result.message).toBe('Installation complete')
- })
- })
- describe('InstalledInfo', () => {
- it('should have correct structure', () => {
- const info: InstalledInfo = {
- installed: true,
- version: '22.12.0'
- }
- expect(info.installed).toBe(true)
- expect(info.version).toBe('22.12.0')
- })
- })
- describe('AllInstalledInfo', () => {
- it('should have correct structure', () => {
- const info: AllInstalledInfo = {
- nodejs: { installed: true, version: '22.12.0' },
- pnpm: { installed: true, version: '9.0.0' },
- vscode: { installed: true, version: '1.96.0' },
- git: { installed: true, version: '2.47.1' },
- claudeCode: { installed: false, version: null }
- }
- expect(info.nodejs.installed).toBe(true)
- expect(info.claudeCode.installed).toBe(false)
- })
- })
- describe('InstallHistoryItem', () => {
- it('should have correct structure', () => {
- const item: InstallHistoryItem = {
- software: 'nodejs',
- version: '22.12.0',
- options: { installPnpm: true },
- success: true,
- duration: 5000,
- timestamp: Date.now()
- }
- expect(item.software).toBe('nodejs')
- expect(item.success).toBe(true)
- })
- })
- describe('PackageManagerResult', () => {
- it('should have correct structure', () => {
- const result: PackageManagerResult = {
- exists: true,
- manager: 'brew'
- }
- expect(result.exists).toBe(true)
- expect(result.manager).toBe('brew')
- })
- })
- describe('Mirror types', () => {
- it('should accept valid GitMirrorType', () => {
- const mirrors: GitMirrorType[] = ['huaweicloud', 'github']
- expect(mirrors).toHaveLength(2)
- })
- it('should accept valid NodejsMirrorType', () => {
- const mirrors: NodejsMirrorType[] = ['official', 'npmmirror']
- expect(mirrors).toHaveLength(2)
- })
- it('should have correct GitMirrorConfig structure', () => {
- const config: GitMirrorConfig = { mirror: 'huaweicloud' }
- expect(config.mirror).toBe('huaweicloud')
- })
- it('should have correct NodejsMirrorConfig structure', () => {
- const config: NodejsMirrorConfig = { mirror: 'official' }
- expect(config.mirror).toBe('official')
- })
- })
- })
|