mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-05 23:50:08 +00:00
[backport core/1.34] Fix desktop menu docs links regression (#7501)
Backport of #7181 to `core/1.34` Automatically created by backport workflow. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-7501-backport-core-1-34-Fix-desktop-menu-docs-links-regression-2ca6d73d365081bc8785ecc142e9c729) by [Unito](https://www.unito.io) Co-authored-by: Benjamin Lu <benjaminlu1107@gmail.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { computed } from 'vue'
|
||||
|
||||
import { electronAPI, isElectron } from '@/utils/envUtil'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { i18n } from '@/i18n'
|
||||
|
||||
/**
|
||||
* Composable for building docs.comfy.org URLs with automatic locale and platform detection
|
||||
@@ -23,7 +23,7 @@ import { useI18n } from 'vue-i18n'
|
||||
* ```
|
||||
*/
|
||||
export function useExternalLink() {
|
||||
const { locale } = useI18n()
|
||||
const locale = computed(() => String(i18n.global.locale.value))
|
||||
|
||||
const isChinese = computed(() => {
|
||||
return locale.value === 'zh' || locale.value === 'zh-TW'
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { ref } from 'vue'
|
||||
|
||||
import { useExternalLink } from '@/composables/useExternalLink'
|
||||
|
||||
// Mock the environment utilities
|
||||
vi.mock('@/utils/envUtil', () => ({
|
||||
@@ -9,22 +6,27 @@ vi.mock('@/utils/envUtil', () => ({
|
||||
electronAPI: vi.fn()
|
||||
}))
|
||||
|
||||
// Mock vue-i18n
|
||||
const mockLocale = ref('en')
|
||||
vi.mock('vue-i18n', () => ({
|
||||
useI18n: vi.fn(() => ({
|
||||
locale: mockLocale
|
||||
}))
|
||||
// Provide a minimal i18n instance for the composable
|
||||
const i18n = vi.hoisted(() => ({
|
||||
global: {
|
||||
locale: {
|
||||
value: 'en'
|
||||
}
|
||||
}
|
||||
}))
|
||||
vi.mock('@/i18n', () => ({
|
||||
i18n
|
||||
}))
|
||||
|
||||
// Import after mocking to get the mocked versions
|
||||
import { useExternalLink } from '@/composables/useExternalLink'
|
||||
import { electronAPI, isElectron } from '@/utils/envUtil'
|
||||
|
||||
describe('useExternalLink', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
// Reset to default state
|
||||
mockLocale.value = 'en'
|
||||
i18n.global.locale.value = 'en'
|
||||
vi.mocked(isElectron).mockReturnValue(false)
|
||||
})
|
||||
|
||||
@@ -53,7 +55,7 @@ describe('useExternalLink', () => {
|
||||
|
||||
describe('buildDocsUrl', () => {
|
||||
it('should build basic docs URL without locale', () => {
|
||||
mockLocale.value = 'en'
|
||||
i18n.global.locale.value = 'en'
|
||||
const { buildDocsUrl } = useExternalLink()
|
||||
|
||||
const url = buildDocsUrl('/changelog')
|
||||
@@ -61,7 +63,7 @@ describe('useExternalLink', () => {
|
||||
})
|
||||
|
||||
it('should build docs URL with Chinese (zh) locale when requested', () => {
|
||||
mockLocale.value = 'zh'
|
||||
i18n.global.locale.value = 'zh'
|
||||
const { buildDocsUrl } = useExternalLink()
|
||||
|
||||
const url = buildDocsUrl('/changelog', { includeLocale: true })
|
||||
@@ -69,7 +71,7 @@ describe('useExternalLink', () => {
|
||||
})
|
||||
|
||||
it('should build docs URL with Chinese (zh-TW) locale when requested', () => {
|
||||
mockLocale.value = 'zh-TW'
|
||||
i18n.global.locale.value = 'zh-TW'
|
||||
const { buildDocsUrl } = useExternalLink()
|
||||
|
||||
const url = buildDocsUrl('/changelog', { includeLocale: true })
|
||||
@@ -77,7 +79,7 @@ describe('useExternalLink', () => {
|
||||
})
|
||||
|
||||
it('should not include locale for English when requested', () => {
|
||||
mockLocale.value = 'en'
|
||||
i18n.global.locale.value = 'en'
|
||||
const { buildDocsUrl } = useExternalLink()
|
||||
|
||||
const url = buildDocsUrl('/changelog', { includeLocale: true })
|
||||
@@ -92,7 +94,7 @@ describe('useExternalLink', () => {
|
||||
})
|
||||
|
||||
it('should add platform suffix when requested', () => {
|
||||
mockLocale.value = 'en'
|
||||
i18n.global.locale.value = 'en'
|
||||
vi.mocked(isElectron).mockReturnValue(true)
|
||||
vi.mocked(electronAPI).mockReturnValue({
|
||||
getPlatform: () => 'darwin'
|
||||
@@ -104,7 +106,7 @@ describe('useExternalLink', () => {
|
||||
})
|
||||
|
||||
it('should add platform suffix with trailing slash', () => {
|
||||
mockLocale.value = 'en'
|
||||
i18n.global.locale.value = 'en'
|
||||
vi.mocked(isElectron).mockReturnValue(true)
|
||||
vi.mocked(electronAPI).mockReturnValue({
|
||||
getPlatform: () => 'win32'
|
||||
@@ -116,7 +118,7 @@ describe('useExternalLink', () => {
|
||||
})
|
||||
|
||||
it('should combine locale and platform', () => {
|
||||
mockLocale.value = 'zh'
|
||||
i18n.global.locale.value = 'zh'
|
||||
vi.mocked(isElectron).mockReturnValue(true)
|
||||
vi.mocked(electronAPI).mockReturnValue({
|
||||
getPlatform: () => 'darwin'
|
||||
@@ -133,7 +135,7 @@ describe('useExternalLink', () => {
|
||||
})
|
||||
|
||||
it('should not add platform when not desktop', () => {
|
||||
mockLocale.value = 'en'
|
||||
i18n.global.locale.value = 'en'
|
||||
vi.mocked(isElectron).mockReturnValue(false)
|
||||
|
||||
const { buildDocsUrl } = useExternalLink()
|
||||
|
||||
Reference in New Issue
Block a user