-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
12 changed files
with
151 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
]; | ||
|
||
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`; | ||
}); | ||
}; |