Skip to content

Commit a3c3a48

Browse files
authored
Ensure articles with the name "Tutorials" render with the right component (#726)
Resolves: rdar://113289632
1 parent d4b7889 commit a3c3a48

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

src/setup-utils/SwiftDocCRenderRouter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { baseUrl } from 'docc-render/utils/theme-settings';
1919
import { addPrefixedRoutes } from 'docc-render/utils/route-utils';
2020
import { notFoundRouteName } from 'docc-render/constants/router';
2121

22-
const defaultRoutes = [...addPrefixedRoutes(routes, [notFoundRouteName]), ...routes];
22+
const defaultRoutes = [...routes, ...addPrefixedRoutes(routes, [notFoundRouteName])];
2323

2424
export default function createRouterInstance(routerConfig = {}) {
2525
const router = new Router({

tests/unit/setup-utils/SwiftDocCRenderRouter.spec.js

+89
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,93 @@ describe('SwiftDocCRenderRouter', () => {
105105
window.dispatchEvent(new Event('unload'));
106106
expect(saveScrollOnReload).toHaveBeenCalledTimes(1);
107107
});
108+
109+
describe('route resolving', () => {
110+
let router;
111+
112+
beforeAll(() => {
113+
jest.resetModules();
114+
jest.unmock('vue-router');
115+
// eslint-disable-next-line global-require
116+
router = require('docc-render/setup-utils/SwiftDocCRenderRouter').default();
117+
});
118+
119+
const resolve = path => router.resolve(path).route;
120+
121+
it('resolves paths to the "tutorials-overview" route', () => {
122+
const route = 'tutorials-overview';
123+
124+
expect(resolve('/tutorials/foo').name).toBe(route);
125+
expect(resolve('/tutorials/bar').name).toBe(route);
126+
127+
expect(resolve('/tutorials/foo/bar').name).not.toBe(route);
128+
129+
expect(resolve('/tutorials/documentation').name).toBe(route);
130+
});
131+
132+
it('resolves paths to the "tutorials-overview-locale" route', () => {
133+
const route = 'tutorials-overview-locale';
134+
135+
expect(resolve('/en-US/tutorials/foobar').name).toBe(route);
136+
expect(resolve('/ja-JP/tutorials/foobarbaz').params).toEqual({
137+
id: 'foobarbaz',
138+
locale: 'ja-JP',
139+
});
140+
expect(resolve('/zh-CN/tutorials/foo/bar').name).not.toBe(route);
141+
});
142+
143+
it('resolves paths to the "topic" route', () => {
144+
const route = 'topic';
145+
expect(resolve('/tutorials/foo/bar').name).toBe(route);
146+
expect(resolve('/tutorials/foobar/baz').name).toBe(route);
147+
expect(resolve('/tutorials/documentation/foo').name).toBe(route);
148+
});
149+
150+
it('resolves paths to the "topic-locale" route', () => {
151+
const route = 'topic-locale';
152+
153+
expect(resolve('/en-US/tutorials/foo/bar').name).toBe(route);
154+
expect(resolve('/ja-JP/tutorials/foo/bar').params).toEqual({
155+
id: 'foo',
156+
locale: 'ja-JP',
157+
pathMatch: 'bar',
158+
});
159+
expect(resolve('/zh-CN/tutorials/foo/bar/baz').params).toEqual({
160+
id: 'foo',
161+
locale: 'zh-CN',
162+
pathMatch: 'bar/baz',
163+
});
164+
});
165+
166+
it('resolves paths to the "documentation-topic" route', () => {
167+
const route = 'documentation-topic';
168+
169+
expect(resolve('/documentation/foo').name).toBe(route);
170+
expect(resolve('/documentation/bar').name).toBe(route);
171+
expect(resolve('/documentation/foobar').params.pathMatch).toBe('foobar');
172+
173+
expect(resolve('/documentation/tutorials').name).toBe(route);
174+
expect(resolve('/documentation/tutorials').params.pathMatch).toBe('tutorials');
175+
});
176+
177+
it('resolves paths to the "documentation-topic-locale" route', () => {
178+
const route = 'documentation-topic-locale';
179+
180+
expect(resolve('/en-US/documentation/foo').name).toBe(route);
181+
expect(resolve('/en-US/documentation/foo').params).toEqual({
182+
locale: 'en-US',
183+
pathMatch: 'foo',
184+
});
185+
expect(resolve('/ja-JP/documentation/bar').name).toBe(route);
186+
expect(resolve('/ja-JP/documentation/bar').params).toEqual({
187+
locale: 'ja-JP',
188+
pathMatch: 'bar',
189+
});
190+
expect(resolve('/zh-CN/documentation/baz').name).toBe(route);
191+
expect(resolve('/zh-CN/documentation/baz/qux').params).toEqual({
192+
locale: 'zh-CN',
193+
pathMatch: 'baz/qux',
194+
});
195+
});
196+
});
108197
});

0 commit comments

Comments
 (0)