UNPKG

gatsby-plugin-next-seo

Version:
305 lines (282 loc) 14.3 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _schemaTools = require("@cypress/schema-tools"); var _react = require("@testing-library/react"); var _jestMockConsole = _interopRequireDefault(require("jest-mock-console")); var _react2 = _interopRequireDefault(require("react")); var _reactHelmetAsync = require("react-helmet-async"); var _ = require("../.."); var _schema = _interopRequireDefault(require("../../../e2e/schema")); var render = function render(ui) { return (0, _react.render)(ui, { wrapper: _reactHelmetAsync.HelmetProvider }); }; var restoreConsole; beforeAll(function () { restoreConsole = (0, _jestMockConsole["default"])('error'); }); afterAll(function () { restoreConsole(); }); test('ArticleJsonLd', function () { var _document$querySelect, _document$querySelect2; render( /*#__PURE__*/_react2["default"].createElement(_.ArticleJsonLd, { url: "https://example.com/article", headline: "Article headline", images: ['https://example.com/photos/1x1/photo.jpg', 'https://example.com/photos/4x3/photo.jpg', 'https://example.com/photos/16x9/photo.jpg'], datePublished: "2015-02-05T08:00:00+08:00", dateModified: "2015-02-05T09:00:00+08:00", authorName: "Jane Blogs", publisherName: "Ifiok Jr.", publisherLogo: "https://www.example.com/photos/logo.jpg", description: "This is a mighty good description of this article." })); var jsonLD = JSON.parse((_document$querySelect = (_document$querySelect2 = document.querySelector('script')) === null || _document$querySelect2 === void 0 ? void 0 : _document$querySelect2.innerHTML) !== null && _document$querySelect !== void 0 ? _document$querySelect : '{}'); (0, _schemaTools.assertSchema)(_schema["default"])('Article', '1.0.0')(jsonLD); expect(document.documentElement).toMatchSnapshot(); }); test('NewsArticleJsonLd', function () { var _document$querySelect3, _document$querySelect4; render( /*#__PURE__*/_react2["default"].createElement(_.NewsArticleJsonLd, { url: "https://example.com/newsarticle", title: "News Article headline", images: ['https://example.com/photos/1x1/photo.jpg', 'https://example.com/photos/4x3/photo.jpg', 'https://example.com/photos/16x9/photo.jpg'], section: "politics", keywords: "prayuth, taksin, thai", dateCreated: "2015-02-05T08:00:00+08:00", datePublished: "2015-02-05T08:00:00+08:00", dateModified: "2015-02-05T09:00:00+08:00", authorName: "Jane Blogs", publisherName: "Ifiok Jr.", publisherLogo: "https://www.example.com/photos/logo.jpg", description: "This is a mighty good description of this news article.", body: "This is article body of news article" })); var jsonLD = JSON.parse((_document$querySelect3 = (_document$querySelect4 = document.querySelector('script')) === null || _document$querySelect4 === void 0 ? void 0 : _document$querySelect4.innerHTML) !== null && _document$querySelect3 !== void 0 ? _document$querySelect3 : '{}'); (0, _schemaTools.assertSchema)(_schema["default"])('NewsArticle', '1.0.0')(jsonLD); expect(document.documentElement).toMatchSnapshot(); }); test('BlogPostJsonLd', function () { var _document$querySelect5, _document$querySelect6; render( /*#__PURE__*/_react2["default"].createElement(_.BlogPostJsonLd, { url: "https://example.com/blog", headline: "Blog headline", images: ['https://example.com/photos/1x1/photo.jpg', 'https://example.com/photos/4x3/photo.jpg', 'https://example.com/photos/16x9/photo.jpg'], datePublished: "2015-02-05T08:00:00+08:00", dateModified: "2015-02-05T09:00:00+08:00", authorName: "Jane Blogs", description: "This is a mighty good description of this blog.", publisherName: "Ifiok Jr.", publisherLogo: "https://www.example.com/photos/logo.jpg" })); var jsonLD = JSON.parse((_document$querySelect5 = (_document$querySelect6 = document.querySelector('script')) === null || _document$querySelect6 === void 0 ? void 0 : _document$querySelect6.innerHTML) !== null && _document$querySelect5 !== void 0 ? _document$querySelect5 : '{}'); (0, _schemaTools.assertSchema)(_schema["default"])('BlogPosting', '1.0.0')(jsonLD); expect(document.documentElement).toMatchSnapshot(); }); test('BlogJsonLd', function () { var _document$querySelect7, _document$querySelect8; render( /*#__PURE__*/_react2["default"].createElement(_.BlogJsonLd, { url: "https://example.com/blog", headline: "Blog headline", images: ['https://example.com/photos/1x1/photo.jpg', 'https://example.com/photos/4x3/photo.jpg', 'https://example.com/photos/16x9/photo.jpg'], posts: [{ headline: 'Post 1' }, { headline: 'Post 2' }], datePublished: "2015-02-05T08:00:00+08:00", dateModified: "2015-02-05T09:00:00+08:00", authorName: "Jane Blogs", description: "This is a mighty good description of this blog." })); var jsonLD = JSON.parse((_document$querySelect7 = (_document$querySelect8 = document.querySelector('script')) === null || _document$querySelect8 === void 0 ? void 0 : _document$querySelect8.innerHTML) !== null && _document$querySelect7 !== void 0 ? _document$querySelect7 : '{}'); (0, _schemaTools.assertSchema)(_schema["default"])('Blog', '1.0.0')(jsonLD); expect(document.documentElement).toMatchSnapshot(); }); test('BreadcrumbJsonLd', function () { var _document$querySelect9, _document$querySelect10; render( /*#__PURE__*/_react2["default"].createElement(_.BreadcrumbJsonLd, { itemListElements: [{ position: 1, name: 'Books', item: 'https://example.com/books' }, { position: 2, name: 'Authors', item: 'https://example.com/books/authors' }, { position: 3, name: 'Ann Leckie', item: 'https://example.com/books/authors/annleckie' }, { position: 4, name: 'Ancillary Justice', item: 'https://example.com/books/authors/annleckie/ancillaryjustice' }] })); var jsonLD = JSON.parse((_document$querySelect9 = (_document$querySelect10 = document.querySelector('script')) === null || _document$querySelect10 === void 0 ? void 0 : _document$querySelect10.innerHTML) !== null && _document$querySelect9 !== void 0 ? _document$querySelect9 : '{}'); (0, _schemaTools.assertSchema)(_schema["default"])('Breadcrumb', '1.0.0')(jsonLD); expect(document.documentElement).toMatchSnapshot(); }); test('BookJsonLd', function () { var _document$querySelect11, _document$querySelect12; render( /*#__PURE__*/_react2["default"].createElement(_.BookJsonLd, { author: { name: 'Tolu B.' }, url: "https://example.com/tolub", name: "Rock your world - the final chapter", workExample: [{ bookFormat: 'AudiobookFormat', isbn: '123123123', potentialAction: { expectsAcceptanceOf: { '@type': 'Offer', price: '6.99', priceCurrency: 'USD', eligibleRegion: { '@type': 'Country', name: 'US' }, availability: 'http://schema.org/InStock' }, target: { '@type': 'EntryPoint', urlTemplate: 'http://www.barnesandnoble.com/store/info/offer/0316769487?purchase=true', actionPlatform: ['http://schema.org/DesktopWebPlatform', 'http://schema.org/IOSPlatform', 'http://schema.org/AndroidPlatform'] } } }] })); JSON.parse((_document$querySelect11 = (_document$querySelect12 = document.querySelector('script')) === null || _document$querySelect12 === void 0 ? void 0 : _document$querySelect12.innerHTML) !== null && _document$querySelect11 !== void 0 ? _document$querySelect11 : ''); expect(document.documentElement).toMatchSnapshot(); }); test('CourseJsonLd', function () { var _document$querySelect13, _document$querySelect14; render( /*#__PURE__*/_react2["default"].createElement(_.CourseJsonLd, { name: "Course Name", providerName: "Course Provider", providerUrl: "https//www.example.com/provider", description: "Course description goes right here" })); var jsonLD = JSON.parse((_document$querySelect13 = (_document$querySelect14 = document.querySelector('script')) === null || _document$querySelect14 === void 0 ? void 0 : _document$querySelect14.innerHTML) !== null && _document$querySelect13 !== void 0 ? _document$querySelect13 : '{}'); (0, _schemaTools.assertSchema)(_schema["default"])('Course', '1.0.0')(jsonLD); expect(document.documentElement).toMatchSnapshot(); }); test('SpeakableJsonLd', function () { var _document$querySelect15, _document$querySelect16; render( /*#__PURE__*/_react2["default"].createElement(_.SpeakableJsonLd, { cssSelector: ['#abc', '#root'] })); JSON.parse((_document$querySelect15 = (_document$querySelect16 = document.querySelector('script')) === null || _document$querySelect16 === void 0 ? void 0 : _document$querySelect16.innerHTML) !== null && _document$querySelect15 !== void 0 ? _document$querySelect15 : ''); expect(document.documentElement).toMatchSnapshot(); expect(function () { return render( /*#__PURE__*/_react2["default"].createElement(_.SpeakableJsonLd, { cssSelector: ['#abc', '#root'], xpath: ['/asdf/a'] })); }).toThrowError(); }); test('LocalBusinessJsonLd', function () { var _document$querySelect17, _document$querySelect18; render( /*#__PURE__*/_react2["default"].createElement(_.LocalBusinessJsonLd, { type: "Store", id: "http://davesdeptstore.example.com", name: "Dave's Department Store", description: "Dave's latest department store in San Jose, now open", url: "http://www.example.com/store-locator/sl/San-Jose-Westgate-Store/1427", telephone: "+14088717984", address: { streetAddress: '1600 Saratoga Ave', addressLocality: 'San Jose', addressRegion: 'CA', postalCode: '95129', addressCountry: 'US' }, geo: { latitude: '37.293058', longitude: '-121.988331' }, images: ['https://example.com/photos/1x1/photo.jpg', 'https://example.com/photos/4x3/photo.jpg', 'https://example.com/photos/16x9/photo.jpg'] })); var jsonLD = JSON.parse((_document$querySelect17 = (_document$querySelect18 = document.querySelector('script')) === null || _document$querySelect18 === void 0 ? void 0 : _document$querySelect18.innerHTML) !== null && _document$querySelect17 !== void 0 ? _document$querySelect17 : '{}'); (0, _schemaTools.assertSchema)(_schema["default"])('Local Business', '1.0.0')(jsonLD); expect(document.documentElement).toMatchSnapshot(); }); test('LogoJsonLd', function () { var _document$querySelect19, _document$querySelect20; render( /*#__PURE__*/_react2["default"].createElement(_.LogoJsonLd, { logo: "http://www.your-site.com/images/logo.jpg", url: "http://www.your-site.com" })); var jsonLD = JSON.parse((_document$querySelect19 = (_document$querySelect20 = document.querySelector('script')) === null || _document$querySelect20 === void 0 ? void 0 : _document$querySelect20.innerHTML) !== null && _document$querySelect19 !== void 0 ? _document$querySelect19 : '{}'); (0, _schemaTools.assertSchema)(_schema["default"])('Logo', '1.0.0')(jsonLD); expect(document.documentElement).toMatchSnapshot(); }); test('ProductJsonLd', function () { var _document$querySelect21, _document$querySelect22; render( /*#__PURE__*/_react2["default"].createElement(_.ProductJsonLd, { productName: "Executive Anvil", images: ['https://example.com/photos/1x1/photo.jpg', 'https://example.com/photos/4x3/photo.jpg', 'https://example.com/photos/16x9/photo.jpg'], description: "Sleeker than ACME's Classic Anvil, the Executive Anvil is perfect for the business traveler looking for something to drop from a height.", brand: "ACME", reviews: [{ author: 'Jim', datePublished: '2017-01-06T03:37:40Z', reviewBody: 'This is my favorite product yet! Thanks Nate for the example products and reviews.', name: 'So awesome!!!', reviewRating: { bestRating: '5', ratingValue: '5', worstRating: '1' } }], aggregateRating: { ratingValue: '4.4', reviewCount: 89 }, offers: { price: '119.99', priceCurrency: 'USD', priceValidUntil: '2020-11-05', itemCondition: 'UsedCondition', availability: 'InStock', url: 'https://www.example.com/executive-anvil', seller: { name: 'Executive Objects' } }, mpn: "925872" })); var jsonLD = JSON.parse((_document$querySelect21 = (_document$querySelect22 = document.querySelector('script')) === null || _document$querySelect22 === void 0 ? void 0 : _document$querySelect22.innerHTML) !== null && _document$querySelect21 !== void 0 ? _document$querySelect21 : '{}'); (0, _schemaTools.assertSchema)(_schema["default"])('Product', '1.0.0')(jsonLD); expect(document.documentElement).toMatchSnapshot(); }); test('FAQJsonLd', function () { var _document$querySelect23, _document$querySelect24; render( /*#__PURE__*/_react2["default"].createElement(_.FAQJsonLd, { questions: [{ question: 'What?', answer: 'Stand' }, { question: 'How?', answer: 'Effort' }, { question: 'Why?', answer: 'Peace' }] })); JSON.parse((_document$querySelect23 = (_document$querySelect24 = document.querySelector('script')) === null || _document$querySelect24 === void 0 ? void 0 : _document$querySelect24.innerHTML) !== null && _document$querySelect23 !== void 0 ? _document$querySelect23 : ''); expect(document.documentElement).toMatchSnapshot(); }); test('SitelinksSearchBoxJsonLd', function () { var _document$querySelect25, _document$querySelect26; render( /*#__PURE__*/_react2["default"].createElement(_.SitelinksSearchBoxJsonLd, { url: "https://example.com/", searchHandlerQueryStringUrl: "https://example.com/?q=" })); var jsonLD = JSON.parse((_document$querySelect25 = (_document$querySelect26 = document.querySelector('script')) === null || _document$querySelect26 === void 0 ? void 0 : _document$querySelect26.innerHTML) !== null && _document$querySelect25 !== void 0 ? _document$querySelect25 : '{}'); (0, _schemaTools.assertSchema)(_schema["default"])('SitelinksSearchBox', '1.0.0')(jsonLD); expect(document.documentElement).toMatchSnapshot(); });