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

Commit

Permalink
Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Dom Harrington committed Jun 29, 2018
1 parent 04f1e63 commit a587ff0
Show file tree
Hide file tree
Showing 19 changed files with 170 additions and 87 deletions.
14 changes: 2 additions & 12 deletions packages/api-explorer/__tests__/GlossaryItem.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,12 @@ const { GlossaryItem } = require('../src/GlossaryItem');
test('should output a glossary item if the term exists', () => {
const term = 'acme';
const definition = 'This is a definition';
const glossaryItem = shallow(
<GlossaryItem
term={term}
terms={[{ term, definition }]}
/>,
);
const glossaryItem = shallow(<GlossaryItem term={term} terms={[{ term, definition }]} />);

expect(glossaryItem.find('.glossary-item.highlight').text()).toBe(term);
expect(glossaryItem.find('.tooltip-content-body').text()).toBe(`- ${term} - ${definition}`);
});

test('should output nothing if the term does not exist', () => {
expect(shallow(
<GlossaryItem
term="something"
terms={[]}
/>,
).html()).toBe(null);
expect(shallow(<GlossaryItem term="something" terms={[]} />).html()).toBe(null);
});
28 changes: 24 additions & 4 deletions packages/api-explorer/__tests__/Variable.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ describe('single variable', () => {
});

test('should render default if value not set', () => {
const variable = shallow(<Variable {...props} user={{}} defaults={[ { name: 'apiKey', default: 'default' }]} />);
const variable = shallow(
<Variable {...props} user={{}} defaults={[{ name: 'apiKey', default: 'default' }]} />,
);

expect(variable.text()).toBe('default');
});
Expand All @@ -29,7 +31,9 @@ describe('single variable', () => {
});

test('should render auth dropdown if default and oauth enabled', () => {
const variable = shallow(<Variable {...props} user={{}} defaults={[ { name: 'apiKey', default: 'default' }]} oauth />);
const variable = shallow(
<Variable {...props} user={{}} defaults={[{ name: 'apiKey', default: 'default' }]} oauth />,
);
variable.find('.variable-underline').simulate('click');

expect(variable.find('#loginDropdown').length).toBe(1);
Expand Down Expand Up @@ -80,14 +84,30 @@ describe('multiple variables', () => {
const variable = shallow(
<Variable
{...props}
user={{ keys: [{ name: 'project1', apiKey: '123' }, { name: 'project2', apiKey: '456' }, { name: 'project3'}]}}
user={{
keys: [
{ name: 'project1', apiKey: '123' },
{ name: 'project2', apiKey: '456' },
{ name: 'project3' },
],
}}
selected="project1"
changeSelected={changeSelected}
/>,
);

variable.find('.variable-underline').simulate('click');
variable.find('ul li').at(1).simulate('click', { target: { innerText: variable.find('ul li').at(1).text() } });
variable
.find('ul li')
.at(1)
.simulate('click', {
target: {
innerText: variable
.find('ul li')
.at(1)
.text(),
},
});
});

test('should render auth dropdown if default and oauth enabled');
Expand Down
46 changes: 34 additions & 12 deletions packages/api-explorer/__tests__/lib/markdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,64 +19,86 @@ test('should strip out inputs', () => {
});

test('tables', () => {
expect(shallow(markdown(`
expect(
shallow(
markdown(`
| Tables | Are | Cool |
| ------------- |:-------------:| -----:|
| col 3 is | right-aligned | $1600 |
| col 2 is | centered | $12 |
| zebra stripes | are neat | $1 |
`)).html()).toMatchSnapshot();
`),
).html(),
).toMatchSnapshot();
});

test('headings', () => {
expect(shallow(markdown(`
expect(
shallow(
markdown(`
# h1
## h2
### h3
#### h4
##### h5
###### h6
# heading with some more CONTENT
`)).html()).toMatchSnapshot();
`),
).html(),
).toMatchSnapshot();
});

test('anchors', () => {
expect(shallow(markdown(`
expect(
shallow(
markdown(`
[link](http://example.com)
[xss](javascript:alert)
[doc](doc:slug)
[ref](ref:slug)
[blog](blog:slug)
[page](page:slug)
`)).html()).toMatchSnapshot();
`),
).html(),
).toMatchSnapshot();
});

test('emojis', () => {
expect(shallow(markdown(`
expect(
shallow(
markdown(`
:joy:
:fa-lock:
:unknown-emoji:
`)).html()).toMatchSnapshot();
`),
).html(),
).toMatchSnapshot();
});

test('code samples', () => {
expect(shallow(markdown(`
expect(
shallow(
markdown(`
\`\`\`javascript
var a = 1;
\`\`\`
\`\`\`
code-without-language
\`\`\`
`)).html()).toMatchSnapshot();
})
`),
).html(),
).toMatchSnapshot();
});

test('should render nothing if nothing passed in', () => {
expect(markdown('')).toBe(null);
});

test('`correctnewlines` option', () => {
expect(shallow(markdown('test\ntest\ntest', { correctnewlines: true })).html()).toBe('<p>test\ntest\ntest</p>');
expect(shallow(markdown('test\ntest\ntest', { correctnewlines: true })).html()).toBe(
'<p>test\ntest\ntest</p>',
);
expect(shallow(markdown('test\ntest\ntest', { correctnewlines: false })).html()).toBe(
'<p>test<br/>\ntest<br/>\ntest</p>',
);
Expand Down
25 changes: 19 additions & 6 deletions packages/api-explorer/__tests__/lib/markdown/gemoji-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ it('should output an image node for a known emoji', () => {
],
};

expect(remark().use(parser).data('settings', { position: false }).parse(markdown)).toEqual(ast);
expect(
remark()
.use(parser)
.data('settings', { position: false })
.parse(markdown),
).toEqual(ast);
});

it('should output an <i> for a font awesome icon', () => {
Expand Down Expand Up @@ -59,7 +64,12 @@ it('should output an <i> for a font awesome icon', () => {
],
};

expect(remark().use(parser).data('settings', { position: false }).parse(markdown)).toEqual(ast);
expect(
remark()
.use(parser)
.data('settings', { position: false })
.parse(markdown),
).toEqual(ast);
});

it('should output nothing for unknown emojis', () => {
Expand All @@ -70,12 +80,15 @@ it('should output nothing for unknown emojis', () => {
children: [
{
type: 'paragraph',
children: [
{ type: 'text', value: markdown },
],
children: [{ type: 'text', value: markdown }],
},
],
};

expect(remark().use(parser).data('settings', { position: false }).parse(markdown)).toEqual(ast);
expect(
remark()
.use(parser)
.data('settings', { position: false })
.parse(markdown),
).toEqual(ast);
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ it('should output a variable node', () => {
],
};

expect(remark().use(parser).data('settings', { position: false }).parse(markdown)).toEqual(ast);
expect(
remark()
.use(parser)
.data('settings', { position: false })
.parse(markdown),
).toEqual(ast);
});

it('should output a glossary node', () => {
Expand All @@ -52,7 +57,12 @@ it('should output a glossary node', () => {
],
};

expect(remark().use(parser).data('settings', { position: false }).parse(markdown)).toEqual(ast);
expect(
remark()
.use(parser)
.data('settings', { position: false })
.parse(markdown),
).toEqual(ast);
});

it('should allow whitespace in glossary names', () => {
Expand All @@ -79,7 +89,12 @@ it('should allow whitespace in glossary names', () => {
],
};

expect(remark().use(parser).data('settings', { position: false }).parse(markdown)).toEqual(ast);
expect(
remark()
.use(parser)
.data('settings', { position: false })
.parse(markdown),
).toEqual(ast);
});

it('should allow escape variables to remain', () => {
Expand All @@ -98,5 +113,10 @@ it('should allow escape variables to remain', () => {
],
};

expect(remark().use(parser).data('settings', { position: false }).parse(markdown)).toEqual(ast);
expect(
remark()
.use(parser)
.data('settings', { position: false })
.parse(markdown),
).toEqual(ast);
});
14 changes: 8 additions & 6 deletions packages/api-explorer/src/GlossaryItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ function GlossaryItem({ term, terms }) {

GlossaryItem.propTypes = {
term: PropTypes.string.isRequired,
terms: PropTypes.arrayOf(PropTypes.shape({
term: PropTypes.string.isRequired,
definition: PropTypes.string.isRequired
})).isRequired,
terms: PropTypes.arrayOf(
PropTypes.shape({
term: PropTypes.string.isRequired,
definition: PropTypes.string.isRequired,
}),
).isRequired,
};

module.exports = (props) => (
module.exports = props => (
<GlossaryTermsContext.Consumer>
{(terms) => <GlossaryItem {...props} terms={terms} />}
{terms => <GlossaryItem {...props} terms={terms} />}
</GlossaryTermsContext.Consumer>
);

Expand Down
17 changes: 12 additions & 5 deletions packages/api-explorer/src/Variable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Variable extends React.Component {
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
<li
className={classNames({ active: this.props.selected === key.name })}
onClick={(event) => this.props.changeSelected(event.target.innerText)}
onClick={event => this.props.changeSelected(event.target.innerText)}
key={key.name}
>
{key.name}
Expand Down Expand Up @@ -138,14 +138,21 @@ Variable.defaultProps = {
oauth: false,
};

module.exports = (props) => (
module.exports = props => (
<VariablesContext.Consumer>
{({ user, defaults }) => (
<OauthContext.Consumer>
{(oauth) => (
{oauth => (
<SelectedAppContext.Consumer>
{({selected, changeSelected}) => (
<Variable {...props} user={user} defaults={defaults} oauth={oauth} selected={selected} changeSelected={changeSelected} />
{({ selected, changeSelected }) => (
<Variable
{...props}
user={user}
defaults={defaults}
oauth={oauth}
selected={selected}
changeSelected={changeSelected}
/>
)}
</SelectedAppContext.Consumer>
)}
Expand Down
4 changes: 1 addition & 3 deletions packages/api-explorer/src/block-types/CallOut.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ const CallOut = ({ block, flags }) => {
</span>
)}
{block.data &&
block.data.body && (
<div className="callout-body">{markdown(block.data.body, flags)}</div>
)}
block.data.body && <div className="callout-body">{markdown(block.data.body, flags)}</div>}
</div>
);
};
Expand Down
4 changes: 1 addition & 3 deletions packages/api-explorer/src/block-types/Image.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ const ImageBlock = ({ block, flags }) => {
<img src={image.image[0]} alt={image.caption} />
</a>
</figure>
{image.caption && (
<figcaption>{markdown(image.caption, flags)}</figcaption>
)}
{image.caption && <figcaption>{markdown(image.caption, flags)}</figcaption>}
</div>
)}
</div>
Expand Down
7 changes: 3 additions & 4 deletions packages/api-explorer/src/block-types/Parameters.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ const Parameters = ({ block, flags }) => {

for (let c = 0; c < columns; c += 1) {
tdCells.push(
<div
className="td"
key={c}
>{markdown(block.data.data[`${r}-${c}`] || '', flags)}</div>,
<div className="td" key={c}>
{markdown(block.data.data[`${r}-${c}`] || '', flags)}
</div>,
);
}
return tdCells;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function DescriptionField(props) {
}
return (
<div id={id} className="field-description">
{typeof description === 'string'? markdown(description) : description}
{typeof description === 'string' ? markdown(description) : description}
</div>
);
}
Expand Down
Loading

0 comments on commit a587ff0

Please sign in to comment.