This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: backporting the legacy markdown engine to run alongside the new (…
- Loading branch information
Showing
31 changed files
with
1,376 additions
and
37 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
29 changes: 29 additions & 0 deletions
29
packages/api-explorer/__tests__/block-types/ApiHeader.test.jsx
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,29 @@ | ||
const React = require('react'); | ||
const { shallow } = require('enzyme'); | ||
const ApiHeader = require('../../src/block-types/ApiHeader'); | ||
|
||
const block = { | ||
type: 'api-header', | ||
data: { | ||
title: 'This is header', | ||
type: 'post', | ||
}, | ||
}; | ||
|
||
describe('ApiHeader', () => { | ||
it('Api Header will render text in table header cells', () => { | ||
const apiHeader = shallow(<ApiHeader block={block} />); | ||
expect(apiHeader.find('h1').text()).toBe('This is header'); | ||
}); | ||
|
||
it('should render with the type in a span', () => { | ||
const apiHeader = shallow(<ApiHeader block={block} />); | ||
expect(apiHeader.find(`span.type-${block.data.type}`)).toHaveLength(1); | ||
}); | ||
|
||
it('should create an #id with the slug of the title', () => { | ||
const apiHeader = shallow(<ApiHeader block={block} />); | ||
expect(apiHeader.find(`span#this-is-header`)).toHaveLength(1); | ||
expect(apiHeader.find(`#section-this-is-header`)).toHaveLength(1); | ||
}); | ||
}); |
92 changes: 92 additions & 0 deletions
92
packages/api-explorer/__tests__/block-types/CallOut.test.jsx
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,92 @@ | ||
const React = require('react'); | ||
const { shallow, mount } = require('enzyme'); | ||
const CallOut = require('../../src/block-types/CallOut'); | ||
|
||
test('should render title', () => { | ||
const block = { | ||
data: { | ||
type: 'info', | ||
title: 'Callout', | ||
}, | ||
}; | ||
const callout = mount(<CallOut block={block} />); | ||
expect(callout.find('h3').text()).toBe('Callout'); | ||
}); | ||
|
||
describe('icons', () => { | ||
const icons = { | ||
info: 'info-circle', | ||
warning: 'exclamation-circle', | ||
danger: 'exclamation-triangle', | ||
success: 'check-square', | ||
}; | ||
|
||
it('should render with title', () => { | ||
Object.keys(icons).forEach(type => { | ||
const className = icons[type]; | ||
const block = { | ||
data: { | ||
type, | ||
title: 'Callout', | ||
}, | ||
}; | ||
expect(mount(<CallOut block={block} />).find(`.fa-${className}`)).toHaveLength(1); | ||
}); | ||
}); | ||
|
||
it('should render without title', () => { | ||
Object.keys(icons).forEach(type => { | ||
const className = icons[type]; | ||
const block = { | ||
data: { | ||
type, | ||
}, | ||
}; | ||
expect(mount(<CallOut block={block} />).find(`.noTitleIcon .fa-${className}`)).toHaveLength(1); | ||
}); | ||
}); | ||
}); | ||
|
||
test('should render nothing if no title and icon', () => { | ||
const block = { | ||
data: { | ||
type: '', | ||
}, | ||
}; | ||
const callout = mount(<CallOut block={block} />); | ||
expect(callout.find('span').text()).toBe(''); | ||
}); | ||
|
||
test('should render body', () => { | ||
const block = { | ||
data: { | ||
type: 'info', | ||
body: 'body', | ||
}, | ||
}; | ||
|
||
const callout = shallow(<CallOut block={block} />); | ||
expect( | ||
callout | ||
.render() | ||
.find('.callout-body') | ||
.html() | ||
).toMatchSnapshot(); | ||
}); | ||
|
||
test('should render markdown in body', () => { | ||
const block = { | ||
data: { | ||
type: 'info', | ||
body: '# heading\n`test`', | ||
}, | ||
}; | ||
|
||
const callout = shallow(<CallOut block={block} />); | ||
expect( | ||
callout | ||
.render() | ||
.find('.callout-body') | ||
.html() | ||
).toMatchSnapshot(); | ||
}); |
143 changes: 143 additions & 0 deletions
143
packages/api-explorer/__tests__/block-types/Code.test.jsx
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,143 @@ | ||
const React = require('react'); | ||
const { mount } = require('enzyme'); | ||
const Code = require('../../src/block-types/Code'); | ||
|
||
const block = { | ||
type: 'code', | ||
sidebar: undefined, | ||
data: { | ||
codes: [ | ||
{ | ||
code: 'whjdwhjwejhkwhjk', | ||
language: 'text', | ||
status: 400, | ||
name: 'test', | ||
}, | ||
{ | ||
code: 'var a = 1', | ||
language: 'javascript', | ||
}, | ||
{ | ||
code: 'whjdwhjwejhkwhjk', | ||
language: 'text', | ||
name: 'test', | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
const block3 = { | ||
type: 'code', | ||
sidebar: undefined, | ||
data: { | ||
codes: [ | ||
{ | ||
code: 'whjdwhjwejhkwhjk', | ||
language: 'text', | ||
status: 400, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
const badBlock = { | ||
type: 'code', | ||
sidebar: undefined, | ||
data: { | ||
codes: { | ||
code: { | ||
code: 'whjdwhjwejhkwhjk', | ||
language: 'text', | ||
status: 400, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const block2 = { | ||
type: 'code', | ||
sidebar: undefined, | ||
data: { | ||
codes: [ | ||
{ | ||
code: 'var a = 1', | ||
language: 'javascript', | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
test('Code will render name if provided within em tag if codes has a status', () => { | ||
const codeInput = mount(<Code block={block} />); | ||
expect(codeInput.find('em').text()).toBe('test'); | ||
}); | ||
|
||
test('Code will render status code within em tag', () => { | ||
const codeInput = mount(<Code block={block3} />); | ||
expect(codeInput.find('em').text()).toBe('Bad Request'); | ||
}); | ||
|
||
test('If codes array is not passed as an array expect empty array', () => { | ||
const codeInput = mount(<Code block={badBlock} />); | ||
|
||
expect(codeInput.find('span').text()).toBe(''); | ||
}); | ||
|
||
test('Code will render language if name or status is not provided within a tag if codes has a status', () => { | ||
const codeInput = mount(<Code block={block2} />); | ||
expect(codeInput.find('a').text()).toBe('JavaScript'); | ||
}); | ||
|
||
test('Code will render label if provided within opts', () => { | ||
const codeInput = mount(<Code block={block} opts={{ label: 'label' }} />); | ||
expect(codeInput.find('label').text()).toBe('label'); | ||
}); | ||
|
||
test('Code should switch tabs', () => { | ||
const codeInput = mount(<Code block={block} opts={{}} />); | ||
const anchor = codeInput.find('li a').at(1); | ||
anchor.simulate('click'); | ||
expect(anchor.render().hasClass('active')).toBe(true); | ||
}); | ||
|
||
test('should uppercase known languages', () => { | ||
expect( | ||
mount( | ||
<Code | ||
block={{ | ||
data: { | ||
codes: [ | ||
{ | ||
language: 'http', | ||
code: '', | ||
}, | ||
], | ||
}, | ||
}} | ||
/> | ||
) | ||
.find('li a') | ||
.text() | ||
).toBe('HTTP'); | ||
}); | ||
|
||
test('should pass through unknown languages', () => { | ||
expect( | ||
mount( | ||
<Code | ||
block={{ | ||
data: { | ||
codes: [ | ||
{ | ||
language: 'unknown-language-somehow', | ||
code: '', | ||
}, | ||
], | ||
}, | ||
}} | ||
/> | ||
) | ||
.find('li a') | ||
.text() | ||
).toBe('unknown-language-somehow'); | ||
}); |
Oops, something went wrong.