From 9294cd3199ba172c507ca4f7eac5ede5a2d69097 Mon Sep 17 00:00:00 2001 From: R2m1liA <15258427350@163.com> Date: Mon, 27 Oct 2025 13:50:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4nuxt=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将nuxt测试路径调整到组件旁 --- app/models/mappers/productMapper.test.ts | 49 ++++++++++++++++++++++++ {tests/unit => app}/utils/file.test.ts | 2 +- vitest.config.ts | 22 ++--------- 3 files changed, 53 insertions(+), 20 deletions(-) create mode 100644 app/models/mappers/productMapper.test.ts rename {tests/unit => app}/utils/file.test.ts (97%) diff --git a/app/models/mappers/productMapper.test.ts b/app/models/mappers/productMapper.test.ts new file mode 100644 index 0000000..ce5b498 --- /dev/null +++ b/app/models/mappers/productMapper.test.ts @@ -0,0 +1,49 @@ +import { describe, it, expect } from 'vitest'; + +describe('toProductSpecView', () => { + it('should map translations.key an value corrently', () => { + const raw: ProductSpec = { + id: 1, + value: '100W', + translations: [ + { + id: 1, + key: 'Power', + }, + ], + }; + + const expected: ProductSpecView = { + id: 1, + key: 'Power', + value: '100W', + }; + + expect(toProductSpecView(raw)).toEqual(expected); + }); + + it('should handle missing translations gracefully', () => { + const raw: ProductSpec = { id: 2, value: '220V', translations: [] }; + const view = toProductSpecView(raw); + expect(view.key).toBe(''); + }); +}); + +describe('toProductSpecGroupView', () => { + it('should map translations.name and specs correctly', () => { + const raw: ProductSpecGroup = { + id: 1, + translations: [{ id: 1, name: 'Electrical' }], + specs: [ + { id: 1, value: '100W', translations: [{ id: 1, key: 'Power' }] }, + { id: 2, value: '220V', translations: [{ id: 2, key: 'Voltage' }] }, + ], + }; + const view: ProductSpecGroupView = toProductSpecGroupView(raw); + + expect(view.name).toBe('Electrical'); + expect(view.specs).toHaveLength(2); + expect(view.specs[0].key).toBe('Power'); + expect(view.specs[1].value).toBe('220V'); + }); +}); diff --git a/tests/unit/utils/file.test.ts b/app/utils/file.test.ts similarity index 97% rename from tests/unit/utils/file.test.ts rename to app/utils/file.test.ts index b4d0fca..5325b72 100644 --- a/tests/unit/utils/file.test.ts +++ b/app/utils/file.test.ts @@ -2,7 +2,7 @@ import { formatFileSize, getFileExtension, formatFileExtension, -} from '../../../app/utils/file'; +} from '@/utils/file'; import { expect, test, describe } from 'vitest'; /** diff --git a/vitest.config.ts b/vitest.config.ts index 537f354..b519c1f 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,23 +1,7 @@ -import { defineConfig } from 'vitest/config'; -import { defineVitestProject } from '@nuxt/test-utils/config'; +import { defineVitestConfig } from '@nuxt/test-utils/config'; -export default defineConfig({ +export default defineVitestConfig({ test: { - projects: [ - { - test: { - name: 'unit', - include: ['tests/{e2e,unit}/**/*.{test,spec}.ts'], - environment: 'node', - }, - }, - await defineVitestProject({ - test: { - name: 'nuxt', - include: ['tests/nuxt/**/*.{test,spec}.ts'], - environment: 'nuxt', - }, - }), - ], + environment: 'nuxt', }, });