-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOP-5078: Fix duplicate "docs" prefix in BreadcrumbList #1285
Changes from all commits
f9ffef3
254a2e4
1455883
e44e86a
024f561
d210e72
a8b73b9
10d17d0
4e57795
3414e58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ export const useSiteMetadata = () => { | |
parserUser | ||
patchId | ||
pathPrefix | ||
project | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trying to figure out why this was added in this PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When checking for usage of It's completely out of scope for this PR, but added it as a bonus since it was a small change. Happy to create a separate PR for it if you'd prefer! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep it in! Thank you for the explanation! |
||
reposDatabase | ||
siteUrl | ||
snootyBranch | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react'; | ||
import * as Gatsby from 'gatsby'; | ||
import { render } from '@testing-library/react'; | ||
import useSnootyMetadata from '../../src/utils/use-snooty-metadata'; | ||
import BreadcrumbSchema from '../../src/components/StructuredData/BreadcrumbSchema'; | ||
import { mockWithPrefix } from '../utils/mock-with-prefix'; | ||
import mockParents from './data/Breadcrumbs.test.json'; | ||
|
||
jest.mock(`../../src/utils/use-snooty-metadata`, () => jest.fn()); | ||
|
||
const mockIntermediateCrumbs = [ | ||
{ | ||
title: 'MongoDB Atlas', | ||
path: 'https://www.mongodb.com/docs/atlas', | ||
seungpark marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
]; | ||
|
||
const useStaticQuery = jest.spyOn(Gatsby, 'useStaticQuery'); | ||
useStaticQuery.mockImplementation(() => ({ | ||
site: { | ||
siteMetadata: { | ||
siteUrl: 'https://www.mongodb.com/', | ||
}, | ||
}, | ||
allBreadcrumb: { | ||
nodes: [ | ||
{ | ||
project: 'realm', | ||
breadcrumbs: mockIntermediateCrumbs, | ||
propertyUrl: 'https://www.mongodb.com/docs/atlas/device-sdks/', | ||
}, | ||
], | ||
}, | ||
})); | ||
|
||
describe('BreadcrumbSchema', () => { | ||
beforeAll(() => { | ||
useSnootyMetadata.mockImplementation(() => ({ | ||
parentPaths: mockParents, | ||
})); | ||
mockWithPrefix('/docs/atlas/device-sdks'); | ||
}); | ||
|
||
it('returns correct structured data with parents and intermediate breadcrumbs', () => { | ||
const { asFragment } = render(<BreadcrumbSchema slug={'sdk/cpp/app-services/call-a-function'} />); | ||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`BreadcrumbSchema returns correct structured data with parents and intermediate breadcrumbs 1`] = ` | ||
<DocumentFragment> | ||
<script | ||
class="structured_data" | ||
type="application/ld+json" | ||
> | ||
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Docs Home","item":"https://www.mongodb.com/docs/"},{"@type":"ListItem","position":2,"name":"MongoDB Atlas","item":"https://www.mongodb.com/docs/atlas/"},{"@type":"ListItem","position":3,"item":"https://www.mongodb.com/docs/atlas/device-sdks/"},{"@type":"ListItem","position":4,"name":"Atlas Device SDK for C++","item":"https://www.mongodb.com/docs/atlas/device-sdks/sdk/cpp/"},{"@type":"ListItem","position":5,"name":"Application Services - C++ SDK","item":"https://www.mongodb.com/docs/atlas/device-sdks/sdk/cpp/application-services/"}]} | ||
</script> | ||
</DocumentFragment> | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as Gatsby from 'gatsby'; | ||
|
||
const withPrefix = jest.spyOn(Gatsby, 'withPrefix'); | ||
|
||
export const mockWithPrefix = (prefix) => { | ||
withPrefix.mockImplementation((path) => { | ||
let normalizedPrefix = prefix; | ||
let normalizedPath = path; | ||
|
||
if (!normalizedPrefix.startsWith('/')) { | ||
normalizedPrefix = `/${normalizedPrefix}`; | ||
} | ||
|
||
if (normalizedPrefix.endsWith('/')) { | ||
normalizedPrefix = normalizedPath.slice(0, -1); | ||
} | ||
|
||
if (normalizedPath.startsWith('/')) { | ||
normalizedPath = normalizedPath.slice(1); | ||
} | ||
|
||
return `${normalizedPrefix}/${normalizedPath}`; | ||
}); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
guessing this change is not from this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's one of the bonus changes mentioned above. Figured I'd just lump it in this PR since it's small and I was planning on making a commit for it anyways, but happy to make it separate if needed!