Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Get tests working
Browse files Browse the repository at this point in the history
  • Loading branch information
Dom Harrington committed Aug 29, 2018
1 parent 31fc30b commit b3434f3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
26 changes: 12 additions & 14 deletions packages/api-explorer/__tests__/lib/generate-code-snippet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,32 @@ const operation = {
const values = { path: { id: 123 } };

test('should generate a HTML snippet for each lang', () => {
const { snippet } = shallow(generateCodeSnippet(oas, operation, {}, 'node'));
const { snippet } = generateCodeSnippet(oas, operation, {}, 'node');

expect(snippet.hasClass('cm-s-tomorrow-night')).toEqual(true);
expect(shallow(snippet).hasClass('cm-s-tomorrow-night')).toEqual(true);
});

test('should pass through values to code snippet', () => {
const { snippet } = shallow(generateCodeSnippet(oas, operation, values, 'node'));
const { snippet } = generateCodeSnippet(oas, operation, values, 'node');

expect(snippet.text()).toEqual(expect.stringMatching('http://example.com/path/123'));
expect(shallow(snippet).text()).toEqual(expect.stringMatching('http://example.com/path/123'));
});

test('should not contain proxy url', () => {
const { snippet } = shallow(
generateCodeSnippet(
Object.assign({}, oas, { [extensions.PROXY_ENABLED]: true }),
operation,
values,
'node',
),
const { snippet } = generateCodeSnippet(
Object.assign({}, oas, { [extensions.PROXY_ENABLED]: true }),
operation,
values,
'node',
);

expect(snippet.text()).toEqual(expect.stringMatching('http://example.com/path/123'));
expect(shallow(snippet).text()).toEqual(expect.stringMatching('http://example.com/path/123'));
});

test('javascript should not contain `withCredentials`', () => {
const { snippet } = shallow(generateCodeSnippet(oas, operation, {}, 'javascript'));
const { snippet } = generateCodeSnippet(oas, operation, {}, 'javascript');

expect(snippet.text()).not.toMatch(/withCredentials/);
expect(shallow(snippet).text()).not.toMatch(/withCredentials/);
});

test('should return with unhighlighted code', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/api-explorer/src/ResponseBody.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function Authorized({ result }) {
!isJson && (
<pre className="tomorrow-night">
<div className="cm-s-tomorrow-night codemirror-highlight">
{syntaxHighlighter(JSON.stringify(result.responseBody), 'javascript')}
{syntaxHighlighter(result.responseBody, result.type)}
</div>
</pre>
)}
Expand Down
5 changes: 4 additions & 1 deletion packages/api-explorer/src/block-types/Code.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ class BlockCode extends React.Component {
// eslint-disable-next-line react/no-array-index-key
<pre key={i} style={{ display: i === this.state.activeTab ? 'block' : 'none' }}>
<code>
{syntaxHighlighter(code.code, code.language, { dark, tokenizeVariables: true })}
{syntaxHighlighter(code.code, code.language, {
dark,
tokenizeVariables: true,
})}
</code>
</pre>
}
Expand Down
5 changes: 3 additions & 2 deletions packages/api-explorer/src/form-components/ArrayField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ function createArrayField(oas) {
const explorerEnabled = oas[extensions.EXPLORER_ENABLED];

function ArrayField(props) {
let uiSchema;
if (!explorerEnabled) {
// https://github.com/mozilla-services/react-jsonschema-form#addable-option
props.uiSchema = Object.assign(props.uiSchema, { 'ui:options': { addable: false } });
uiSchema = Object.assign(props.uiSchema, { 'ui:options': { addable: false } });
}

return <BaseArrayField {...props} />;
return <BaseArrayField {...props} uiSchema={uiSchema || props.uiSchema} />;
}

ArrayField.propTypes = {
Expand Down
8 changes: 5 additions & 3 deletions packages/syntax-highlighter/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ test('should work for html', () => {
});

test('should work for php without opening tag', () => {
expect(syntaxHighlighter('echo "Hello World";', 'php')).toContain('cm-keyword');
expect(shallow(syntaxHighlighter('echo "Hello World";', 'php')).html()).toContain('cm-keyword');
});

test('should work for kotlin', () => {
expect(syntaxHighlighter('println("$index: $element")', 'kotlin')).toContain('cm-variable');
expect(shallow(syntaxHighlighter('println("$index: $element")', 'kotlin')).html()).toContain(
'cm-variable',
);
});

test('should work for go', () => {
expect(syntaxHighlighter('func main() {}', 'go')).toContain('cm-variable');
expect(shallow(syntaxHighlighter('func main() {}', 'go')).html()).toContain('cm-variable');
});

0 comments on commit b3434f3

Please sign in to comment.