shared-types.test.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import { describe, it, expect } from 'vitest'
  2. import type {
  3. SoftwareType,
  4. SoftwareTypeWithAll,
  5. Platform,
  6. TabId,
  7. VersionItem,
  8. VersionResult,
  9. InstallOptions,
  10. InstallStatus,
  11. InstallResult,
  12. InstalledInfo,
  13. AllInstalledInfo,
  14. InstallHistoryItem,
  15. PackageManagerResult,
  16. GitMirrorType,
  17. NodejsMirrorType,
  18. GitMirrorConfig,
  19. NodejsMirrorConfig
  20. } from '../shared/types'
  21. describe('shared types', () => {
  22. describe('SoftwareType', () => {
  23. it('should accept valid software types', () => {
  24. const validTypes: SoftwareType[] = ['nodejs', 'pnpm', 'vscode', 'git', 'claudeCode']
  25. expect(validTypes).toHaveLength(5)
  26. })
  27. })
  28. describe('SoftwareTypeWithAll', () => {
  29. it('should include all software types plus "all"', () => {
  30. const validTypes: SoftwareTypeWithAll[] = ['nodejs', 'pnpm', 'vscode', 'git', 'claudeCode', 'all']
  31. expect(validTypes).toHaveLength(6)
  32. })
  33. })
  34. describe('Platform', () => {
  35. it('should accept valid platform types', () => {
  36. const validPlatforms: Platform[] = ['win32', 'darwin', 'linux']
  37. expect(validPlatforms).toHaveLength(3)
  38. })
  39. })
  40. describe('TabId', () => {
  41. it('should accept valid tab IDs', () => {
  42. const validTabs: TabId[] = ['intro', 'nodejs', 'vscode', 'git', 'claudeCode', 'all']
  43. expect(validTabs).toHaveLength(6)
  44. })
  45. })
  46. describe('VersionItem', () => {
  47. it('should have correct structure', () => {
  48. const item: VersionItem = {
  49. value: '22.12.0',
  50. label: 'v22.12.0 (LTS)',
  51. lts: true,
  52. disabled: false,
  53. separator: false
  54. }
  55. expect(item.value).toBe('22.12.0')
  56. expect(item.label).toBe('v22.12.0 (LTS)')
  57. expect(item.lts).toBe(true)
  58. })
  59. })
  60. describe('VersionResult', () => {
  61. it('should have correct structure', () => {
  62. const result: VersionResult = {
  63. versions: [
  64. { value: '22.12.0', label: 'v22.12.0' }
  65. ],
  66. warning: null
  67. }
  68. expect(result.versions).toHaveLength(1)
  69. expect(result.warning).toBeNull()
  70. })
  71. })
  72. describe('InstallOptions', () => {
  73. it('should have correct structure', () => {
  74. const options: InstallOptions = {
  75. version: '22.12.0',
  76. installPnpm: true,
  77. installNodejs: true,
  78. nodejsVersion: '22.12.0',
  79. nodejsPath: 'C:\\nodejs',
  80. installVscode: true,
  81. vscodeVersion: '1.96.0',
  82. vscodePath: 'C:\\vscode',
  83. installGit: true,
  84. gitVersion: '2.47.1',
  85. gitPath: 'C:\\git',
  86. installClaudeCode: true,
  87. customPath: 'C:\\custom'
  88. }
  89. expect(options.version).toBe('22.12.0')
  90. expect(options.installPnpm).toBe(true)
  91. })
  92. })
  93. describe('InstallStatus', () => {
  94. it('should have correct structure', () => {
  95. const status: InstallStatus = {
  96. software: 'nodejs',
  97. message: 'Installing...',
  98. progress: 50,
  99. i18nKey: 'install.installing',
  100. i18nParams: { software: 'Node.js' }
  101. }
  102. expect(status.software).toBe('nodejs')
  103. expect(status.progress).toBe(50)
  104. })
  105. })
  106. describe('InstallResult', () => {
  107. it('should have correct structure', () => {
  108. const result: InstallResult = {
  109. software: 'nodejs',
  110. message: 'Installation complete',
  111. i18nKey: 'install.complete'
  112. }
  113. expect(result.software).toBe('nodejs')
  114. expect(result.message).toBe('Installation complete')
  115. })
  116. })
  117. describe('InstalledInfo', () => {
  118. it('should have correct structure', () => {
  119. const info: InstalledInfo = {
  120. installed: true,
  121. version: '22.12.0'
  122. }
  123. expect(info.installed).toBe(true)
  124. expect(info.version).toBe('22.12.0')
  125. })
  126. })
  127. describe('AllInstalledInfo', () => {
  128. it('should have correct structure', () => {
  129. const info: AllInstalledInfo = {
  130. nodejs: { installed: true, version: '22.12.0' },
  131. pnpm: { installed: true, version: '9.0.0' },
  132. vscode: { installed: true, version: '1.96.0' },
  133. git: { installed: true, version: '2.47.1' },
  134. claudeCode: { installed: false, version: null }
  135. }
  136. expect(info.nodejs.installed).toBe(true)
  137. expect(info.claudeCode.installed).toBe(false)
  138. })
  139. })
  140. describe('InstallHistoryItem', () => {
  141. it('should have correct structure', () => {
  142. const item: InstallHistoryItem = {
  143. software: 'nodejs',
  144. version: '22.12.0',
  145. options: { installPnpm: true },
  146. success: true,
  147. duration: 5000,
  148. timestamp: Date.now()
  149. }
  150. expect(item.software).toBe('nodejs')
  151. expect(item.success).toBe(true)
  152. })
  153. })
  154. describe('PackageManagerResult', () => {
  155. it('should have correct structure', () => {
  156. const result: PackageManagerResult = {
  157. exists: true,
  158. manager: 'brew'
  159. }
  160. expect(result.exists).toBe(true)
  161. expect(result.manager).toBe('brew')
  162. })
  163. })
  164. describe('Mirror types', () => {
  165. it('should accept valid GitMirrorType', () => {
  166. const mirrors: GitMirrorType[] = ['huaweicloud', 'github']
  167. expect(mirrors).toHaveLength(2)
  168. })
  169. it('should accept valid NodejsMirrorType', () => {
  170. const mirrors: NodejsMirrorType[] = ['official', 'npmmirror']
  171. expect(mirrors).toHaveLength(2)
  172. })
  173. it('should have correct GitMirrorConfig structure', () => {
  174. const config: GitMirrorConfig = { mirror: 'huaweicloud' }
  175. expect(config.mirror).toBe('huaweicloud')
  176. })
  177. it('should have correct NodejsMirrorConfig structure', () => {
  178. const config: NodejsMirrorConfig = { mirror: 'official' }
  179. expect(config.mirror).toBe('official')
  180. })
  181. })
  182. })