diff --git a/src/lang/locales/de-DE.json b/src/lang/locales/de-DE.json index da64bc744..f5b21a79c 100644 --- a/src/lang/locales/de-DE.json +++ b/src/lang/locales/de-DE.json @@ -183,7 +183,8 @@ "error": { "unknown": "Es ist ein unbekannter Fehler aufgetreten.", "image": "Laden des Bildes fehlgeschlagen", - "not-found": "Die von dir gesuchte Seite wurde nicht gefunden." + "not-found": "Die von dir gesuchte Seite wurde nicht gefunden.", + "back-to-documentation": "Zurück zur Dokumentation" }, "color-scheme": { "select": "Bevorzugtes Farbschema auswählen", diff --git a/src/lang/locales/en-US.json b/src/lang/locales/en-US.json index d60c1500f..b25d24a10 100644 --- a/src/lang/locales/en-US.json +++ b/src/lang/locales/en-US.json @@ -184,7 +184,8 @@ "error": { "unknown": "An unknown error occurred.", "image": "Image failed to load", - "not-found": "The page you're looking for can't be found." + "not-found": "The page you're looking for can't be found.", + "back-to-documentation": "Back to Documentation" }, "color-scheme": { "select": "Select a color scheme preference", diff --git a/src/lang/locales/es-419.json b/src/lang/locales/es-419.json index dc083cbd3..ed5a49269 100644 --- a/src/lang/locales/es-419.json +++ b/src/lang/locales/es-419.json @@ -183,7 +183,8 @@ "error": { "unknown": "Ocurrió un error desconocido.", "image": "Error al cargar la imagen", - "not-found": "No se encuentra la página que buscas." + "not-found": "No se encuentra la página que buscas.", + "back-to-documentation": "Volver a la documentación" }, "color-scheme": { "select": "Selecciona el esquema de colores que prefieras", diff --git a/src/lang/locales/fr-FR.json b/src/lang/locales/fr-FR.json index ed3fec789..8cd05283b 100644 --- a/src/lang/locales/fr-FR.json +++ b/src/lang/locales/fr-FR.json @@ -183,7 +183,8 @@ "error": { "unknown": "Une erreur inconnue est survenue.", "image": "Échec du chargement de l'image", - "not-found": "La page que vous recherchez est introuvable." + "not-found": "La page que vous recherchez est introuvable.", + "back-to-documentation": "Retour à la documentation" }, "color-scheme": { "select": "Sélectionnez une préférence de palette de couleurs", diff --git a/src/lang/locales/it-IT.json b/src/lang/locales/it-IT.json index f85f12ca5..41f15fc3a 100644 --- a/src/lang/locales/it-IT.json +++ b/src/lang/locales/it-IT.json @@ -183,7 +183,8 @@ "error": { "unknown": "Si è verificato un errore sconosciuto.", "image": "Impossibile caricare l'immagine", - "not-found": "La pagina richiesta non è stata trovata." + "not-found": "La pagina richiesta non è stata trovata.", + "back-to-documentation": "Torna alla documentazione" }, "color-scheme": { "select": "Seleziona una preferenza per lo schema colore", diff --git a/src/lang/locales/ja-JP.json b/src/lang/locales/ja-JP.json index ee4d0e67f..ab854b69e 100644 --- a/src/lang/locales/ja-JP.json +++ b/src/lang/locales/ja-JP.json @@ -180,7 +180,8 @@ "error": { "unknown": "原因不明のエラーが起きました。", "image": "イメージを読み込めませんでした", - "not-found": "探しているページが見つかりません。" + "not-found": "探しているページが見つかりません。", + "back-to-documentation": "ドキュメントに戻る" }, "color-scheme": { "select": "カラースキーム環境設定を選択", diff --git a/src/lang/locales/ko-KR.json b/src/lang/locales/ko-KR.json index 0a1521b1e..756fab688 100644 --- a/src/lang/locales/ko-KR.json +++ b/src/lang/locales/ko-KR.json @@ -180,7 +180,8 @@ "error": { "unknown": "알 수 없는 오류가 발생했습니다.", "image": "이미지를 로드하는 데 실패함", - "not-found": "해당 페이지를 찾을 수 없습니다." + "not-found": "해당 페이지를 찾을 수 없습니다.", + "back-to-documentation": "문서로 돌아가기" }, "color-scheme": { "select": "색상 모드 환경설정 선택", diff --git a/src/lang/locales/pt-BR.json b/src/lang/locales/pt-BR.json index cad5e98bf..624dcd216 100644 --- a/src/lang/locales/pt-BR.json +++ b/src/lang/locales/pt-BR.json @@ -183,7 +183,8 @@ "error": { "unknown": "Ocorreu um erro desconhecido.", "image": "Falha ao carregar a imagem", - "not-found": "Não é possível encontrar a página que você procura." + "not-found": "Não é possível encontrar a página que você procura.", + "back-to-documentation": "Voltar para a documentação" }, "color-scheme": { "select": "Selecione uma preferência de esquema de cores", diff --git a/src/lang/locales/zh-CN.json b/src/lang/locales/zh-CN.json index 933964a65..ac98c2c8b 100644 --- a/src/lang/locales/zh-CN.json +++ b/src/lang/locales/zh-CN.json @@ -180,7 +180,8 @@ "error": { "unknown": "出现未知错误。", "image": "图像无法载入", - "not-found": "找不到你所查找的页面。" + "not-found": "找不到你所查找的页面。", + "back-to-documentation": "返回文档" }, "color-scheme": { "select": "选择首选颜色方案", diff --git a/src/views/NotFound.vue b/src/views/NotFound.vue index 4081b32fa..082ccfc95 100644 --- a/src/views/NotFound.vue +++ b/src/views/NotFound.vue @@ -10,6 +10,11 @@ @@ -17,13 +22,41 @@ + + diff --git a/tests/unit/views/NotFound.spec.js b/tests/unit/views/NotFound.spec.js index 5fcbb93a8..fb93ac689 100644 --- a/tests/unit/views/NotFound.spec.js +++ b/tests/unit/views/NotFound.spec.js @@ -10,11 +10,21 @@ import NotFound from 'docc-render/views/NotFound.vue'; import { shallowMount } from '@vue/test-utils'; +import Language from 'docc-render/constants/Language'; +import { fetchData } from 'docc-render/utils/data'; +import { flushPromises } from '../../../test-utils'; -const { GenericError } = NotFound.components; +jest.mock('docc-render/utils/data'); + +const { GenericError, Reference } = NotFound.components; describe('NotFound', () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + it('renders a `GenericError` with a custom message', () => { + fetchData.mockResolvedValue({ interfaceLanguages: {} }); const wrapper = shallowMount(NotFound); const error = wrapper.findComponent(GenericError); expect(error.exists()).toBe(true); @@ -22,6 +32,7 @@ describe('NotFound', () => { }); it('exposes a default slot', () => { + fetchData.mockResolvedValue({ interfaceLanguages: {} }); const wrapper = shallowMount(NotFound, { slots: { default: '
Default Content
', @@ -29,4 +40,47 @@ describe('NotFound', () => { }); expect(wrapper.findComponent('.default').text()).toBe('Default Content'); }); + + it('renders the back link when a module is found', async () => { + fetchData.mockResolvedValue({ + interfaceLanguages: { + [Language.swift.key.url]: [{ type: 'module', path: '/documentation/swift' }], + }, + }); + const wrapper = shallowMount(NotFound); + await flushPromises(); + const backLink = wrapper.findComponent(Reference); + expect(backLink.exists()).toBe(true); + expect(backLink.props('url')).toBe('/documentation/swift'); + }); + + it('does not render the back link when no module is found', async () => { + fetchData.mockResolvedValue({ + interfaceLanguages: { [Language.swift.key.url]: [] }, + }); + const wrapper = shallowMount(NotFound); + await flushPromises(); + expect(wrapper.findComponent(Reference).exists()).toBe(false); + }); + + it('does not render the back link when index fetch fails', async () => { + fetchData.mockRejectedValue(new Error('Fetch failed')); + const wrapper = shallowMount(NotFound); + await flushPromises(); + expect(wrapper.findComponent(Reference).exists()).toBe(false); + }); + + it('uses the first module found across interface languages', async () => { + fetchData.mockResolvedValue({ + interfaceLanguages: { + [Language.objectiveC.key.url]: [{ type: 'something-else' }], + [Language.swift.key.url]: [{ type: 'module', path: '/documentation/swift' }], + }, + }); + const wrapper = shallowMount(NotFound); + await flushPromises(); + const backLink = wrapper.findComponent(Reference); + expect(backLink.exists()).toBe(true); + expect(backLink.props('url')).toBe('/documentation/swift'); + }); });