Skip to content

Commit

Permalink
Add split tab unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Zach Badgett committed Apr 25, 2019
1 parent dc3a94e commit 372a1fe
Show file tree
Hide file tree
Showing 6 changed files with 488 additions and 9 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ website/
scripts
packages/docusaurus-1.x/lib/core/metadata.js
packages/docusaurus-1.x/lib/core/MetadataBlog.js
packages/docusaurus-1.x/lib/core/__tests__/split-tab.test.js
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"devDependencies": {
"babel-core": "^7.0.0-0",
"babel-eslint": "8",
"enzyme": "^3.9.0",
"enzyme-adapter-react-16": "^1.12.1",
"eslint": "4.x",
"eslint-config-airbnb": "17.1.0",
"eslint-config-prettier": "^2.9.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"_comment": "This file is auto-generated by write-translations.js",
"localized-strings": {
},
"pages-strings": {
"Help Translate|recruit community translators for your project": "Help Us Translate",
"Edit this Doc|recruitment message asking to edit the doc source": "Edit",
"Translate this Doc|recruitment message asking to translate the docs": "Translate"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/* List of projects/orgs using your project for the users page */

const siteConfig = {
title: 'Docusaurus',
tagline: 'Easy to Maintain Open Source Documentation Websites',
url: 'https://docusaurus.io',
baseUrl: '/',
organizationName: 'facebook',
projectName: 'Docusaurus',
cname: 'docusaurus.io',
noIndex: false,
editUrl: 'https://github.com/facebook/docusaurus/edit/master/docs/',
headerLinks: [],
headerIcon: 'img/docusaurus.svg',
footerIcon: 'img/docusaurus_monochrome.svg',
favicon: 'img/docusaurus.ico',
algolia: {
apiKey: '3eb9507824b8be89e7a199ecaa1a9d2c',
indexName: 'docusaurus',
algoliaOptions: {
facetFilters: ['language:LANGUAGE', 'version:VERSION'],
},
},
colors: {
primaryColor: '#2E8555',
secondaryColor: '#205C3B',
},
translationRecruitingLink: 'https://crowdin.com/project/docusaurus',
copyright: `Copyright © ${new Date().getFullYear()} Facebook Inc.`,
usePrism: ['jsx'],
highlight: {
theme: 'atom-one-dark',
},
scripts: [
'https://buttons.github.io/buttons.js',
'https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js',
'/js/code-blocks-buttons.js',
],
gaTrackingId: 'UA-44373548-31',
facebookAppId: '199138890728411',
facebookComments: true,
twitter: 'true',
twitterUsername: 'docusaurus',
ogImage: 'img/docusaurus.png',
twitterImage: 'img/docusaurus.png',
onPageNav: 'separate',
cleanUrl: true,
scrollToTop: true,
scrollToTopOptions: {
zIndex: 100,
},
enableUpdateTime: true,
enableUpdateBy: true,
docsSideNavCollapsible: true,
};

module.exports = siteConfig;
93 changes: 93 additions & 0 deletions packages/docusaurus-1.x/lib/core/__tests__/split-tab.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @jest-environment jsdom
*/
process.cwd = () => `${__dirname}/__fixtures__/website`;

const React = require('react');
const {configure, mount} = require('enzyme');
const Adapter = require('enzyme-adapter-react-16');
const Doc = require('../Doc.js');

configure({adapter: new Adapter()});

describe('when code tabs are used correctly', () => {
let props;
let mountedDoc;
const docPage = () => {
if (!mountedDoc) {
mountedDoc = mount(<Doc {...props} />);
}
return mountedDoc;
};
beforeEach(() => {
props = {
content: `
<!--DOCUSAURUS_CODE_TABS-->
<!--JavaScript-->
\`\`\`js
console.log('Hello, world!');
\`\`\`
<!--Python-->
\`\`\`py
print('Hello, world!')
\`\`\`
<!--C-->
\`\`\`C
#include <stdio.h>
int main() {
printf("Hello World!");
return 0;
}
\`\`\`
<!--Pascal-->
\`\`\`Pascal
program HelloWorld;
begin
WriteLn('Hello, world!');
end.
\`\`\`
<!--END_DOCUSAURUS_CODE_TABS-->
`,
metadata: {},
config: {},
};
mountedDoc = undefined;
});
it('renders tabs correctly', () => {
const node = docPage().getDOMNode();
const firstTab = node.querySelector('[data-tab$="-content-2"]').textContent;
expect('JavaScript').toEqual(firstTab);
const secondTab = node.querySelector('[data-tab$="-content-3"]')
.textContent;
expect('Python').toEqual(secondTab);
const thirdTab = node.querySelector('[data-tab$="-content-4"]').textContent;
expect('C').toEqual(thirdTab);
const fourthTab = node.querySelector('[data-tab$="-content-5"]')
.textContent;
expect('Pascal').toEqual(fourthTab);
});
it('renders content correctly', () => {
const node = docPage().getDOMNode();
const firstContent = node.querySelector('[id$="-content-7"]').textContent;
expect("console.log('Hello, world!');\n").toEqual(firstContent);
const secondContent = node.querySelector('[id$="-content-8"]').textContent;
expect("print('Hello, world!')\n").toEqual(secondContent);
const thirdContent = node.querySelector('[id$="-content-9"]').textContent;
expect(
'#include <stdio.h>int main() { printf("Hello World!"); return 0;}\n',
).toEqual(thirdContent);
const fourthContent = node.querySelector('[id$="-content-10"]').textContent;
expect("program HelloWorld;begin WriteLn('Hello, world!');end.\n").toEqual(
fourthContent,
);
});
});
Loading

0 comments on commit 372a1fe

Please sign in to comment.