- {{ heroTitle }}
+ {{ $t('documentation.hero.title') }}
- {{ heroCopy }}
+ {{ $t('documentation.hero.copy') }}
@@ -143,8 +143,6 @@ export default {
data: () => ({
// fallback interface language used by indexDataGetter
interfaceLanguage: Language.swift.key.url,
- heroTitle: 'Developer Documentation',
- heroCopy: 'Browse the latest API reference.',
store: DocumentationTopicStore,
BreakpointName,
}),
From 286db10d12d13af2a97afedaa708ae1ef66a3122 Mon Sep 17 00:00:00 2001
From: VictorPuga <39507381+VictorPuga@users.noreply.github.com>
Date: Sun, 7 Dec 2025 14:33:34 -0600
Subject: [PATCH 7/8] Fixed tests
---
tests/unit/mixins/indexDataFetcher.spec.js | 1 +
tests/unit/stores/IndexStore.spec.js | 1 +
2 files changed, 2 insertions(+)
diff --git a/tests/unit/mixins/indexDataFetcher.spec.js b/tests/unit/mixins/indexDataFetcher.spec.js
index aefb01d7a..29329f3ac 100644
--- a/tests/unit/mixins/indexDataFetcher.spec.js
+++ b/tests/unit/mixins/indexDataFetcher.spec.js
@@ -258,6 +258,7 @@ describe('indexDataFetcher', () => {
errorFetching: false,
errorFetchingDiffs: false,
technologyProps: {},
+ topLevelNodes: [],
});
});
diff --git a/tests/unit/stores/IndexStore.spec.js b/tests/unit/stores/IndexStore.spec.js
index 76f6990cd..a460012e0 100644
--- a/tests/unit/stores/IndexStore.spec.js
+++ b/tests/unit/stores/IndexStore.spec.js
@@ -57,6 +57,7 @@ describe('IndexStore', () => {
errorFetching: false,
errorFetchingDiffs: false,
technologyProps: {},
+ topLevelNodes: [],
};
beforeEach(() => {
From c343200ae1e41db161b6c002865e0ee028324ea2 Mon Sep 17 00:00:00 2001
From: VictorPuga <39507381+VictorPuga@users.noreply.github.com>
Date: Sun, 7 Dec 2025 14:37:54 -0600
Subject: [PATCH 8/8] Added unit tests
---
tests/unit/views/Index.spec.js | 98 ++++++++++++++++++++++++++++++++++
1 file changed, 98 insertions(+)
create mode 100644 tests/unit/views/Index.spec.js
diff --git a/tests/unit/views/Index.spec.js b/tests/unit/views/Index.spec.js
new file mode 100644
index 000000000..a13e3a498
--- /dev/null
+++ b/tests/unit/views/Index.spec.js
@@ -0,0 +1,98 @@
+/**
+ * This source file is part of the Swift.org open source project
+ *
+ * Copyright (c) 2025 Apple Inc. and the Swift project authors
+ * Licensed under Apache License v2.0 with Runtime Library Exception
+ *
+ * See https://swift.org/LICENSE.txt for license information
+ * See https://swift.org/CONTRIBUTORS.txt for Swift project authors
+*/
+
+import { shallowMount } from '@vue/test-utils';
+import Index from '@/views/Index.vue';
+import Navigator from 'docc-render/components/Navigator.vue';
+
+const defaultMocks = {
+ $bridge: {
+ on: jest.fn(),
+ off: jest.fn(),
+ send: jest.fn(),
+ },
+ $route: {},
+};
+
+const messages = {
+ 'documentation.hero.title': 'Developer Documentation',
+ 'documentation.hero.copy': 'Browse the latest API reference.',
+};
+
+const DocumentationLayoutStub = {
+ name: 'DocumentationLayout',
+ props: ['enableNavigator', 'interfaceLanguage', 'references', 'navigatorFixedWidth', 'quickNavNodes'],
+ template: '
',
+};
+
+const baseDataFn = (
+ Index.options && Index.options.data
+ ? Index.options.data.bind(Index)
+ : () => ({})
+);
+const baseData = baseDataFn();
+
+const mountWith = (indexStateOverrides = {}, extraOptions = {}) => shallowMount(Index, {
+ mocks: {
+ ...defaultMocks,
+ $t: key => messages[key] || key,
+ $te: key => Boolean(messages[key]),
+ },
+ stubs: {
+ DocumentationLayout: DocumentationLayoutStub,
+ Navigator: false,
+ QuickNavigationButton: true,
+ TopicTypeIcon: true,
+ RouterLink: {
+ render(h) { return h('a', {}, this.$slots.default); },
+ },
+ ...(extraOptions.stubs || {}),
+ },
+ data: () => ({
+ ...baseData,
+ indexState: {
+ ...(baseData.indexState || {}),
+ flatChildren: [],
+ topLevelNodes: [],
+ references: {},
+ ...indexStateOverrides,
+ },
+ }),
+ computed: {
+ indexNodes: () => [],
+ ...(extraOptions.computed || {}),
+ },
+});
+
+describe('Index view', () => {
+ beforeEach(() => {
+ jest.clearAllMocks();
+ });
+
+ it('renders hero text from translation keys', () => {
+ const wrapper = mountWith();
+ expect(wrapper.find('.hero__title').text()).toBe('Developer Documentation');
+ expect(wrapper.find('.hero__lede').text()).toBe('Browse the latest API reference.');
+ });
+
+ it('passes top-level nodes to navigator only', () => {
+ const topLevelNodes = [{ path: '/documentation/foo', title: 'Foo', type: 'module' }];
+ const wrapper = mountWith({ topLevelNodes });
+ const nav = wrapper.findComponent(Navigator);
+ expect(nav.exists()).toBe(true);
+ expect(nav.props('flatChildren').length).toBe(1);
+ expect(nav.props('flatChildren')[0].path).toBe('/documentation/foo');
+ });
+
+ it('hides sections when lists are empty', () => {
+ const wrapper = mountWith();
+ expect(wrapper.find('section.index-section--grid').exists()).toBe(false);
+ });
+});