Add [dynamic-yaml] badge (#1623)

* Add dynamic yaml badge

* Forgot package lock

* Switch tests to yaml data source

* Add yaml to the dynamic badge maker options

* Reorder to match documentation examples

* Reordered dynamic types to be alphabetical

* Removed regex as pinend commit makes it unnecessary and fixed url

* Removed unused import

* Add more YAML MIME types

* Removed duplicate tests which don't differ between data types
This commit is contained in:
Jacob Tomlinson
2018-04-08 20:47:28 +01:00
committed by Marcin Mielnicki
parent 47614e5bbc
commit d56b6961da
7 changed files with 337 additions and 147 deletions

View File

@@ -43,6 +43,7 @@ export default class DynamicBadgeMaker extends React.Component {
<option value="" disabled>data type</option>
<option value="json">json</option>
<option value="xml">xml</option>
<option value="yaml">yaml</option>
</select> {}
<input
className="short"

View File

@@ -126,6 +126,9 @@ export default class Usage extends React.PureComponent {
<p>
<code>/badge/dynamic/xml.svg?url=&lt;URL&gt;&amp;label=&lt;LABEL&gt;&amp;query=&lt;<a href="https://www.npmjs.com/package/xpath" target="_BLANK" title="XPath syntax">//data/subdata</a>&gt;&amp;colorB=&lt;COLOR&gt;&amp;prefix=&lt;PREFIX&gt;&amp;suffix=&lt;SUFFIX&gt;</code>
</p>
<p>
<code>/badge/dynamic/yaml.svg?url=&lt;URL&gt;&amp;label=&lt;LABEL&gt;&amp;query=&lt;<a href="https://www.npmjs.com/package/jsonpath" target="_BLANK" title="JSONdata syntax">$.DATA.SUBDATA</a>&gt;&amp;colorB=&lt;COLOR&gt;&amp;prefix=&lt;PREFIX&gt;&amp;suffix=&lt;SUFFIX&gt;</code>
</p>
<hr className="spacing" />

View File

@@ -38,7 +38,7 @@ describe('Badge URL functions', function() {
});
test(dynamicBadgeUrl, () => {
const jsonUrl = 'http://example.com/foo.json';
const dataUrl = 'http://example.com/foo.json';
const query = '$.bar';
const prefix = 'value: ';
@@ -46,35 +46,13 @@ describe('Badge URL functions', function() {
'http://img.example.com',
'json',
'foo',
jsonUrl,
dataUrl,
query,
{ prefix, style: 'plastic' }
).expect([
'http://img.example.com/badge/dynamic/json.svg',
'?label=foo',
`&url=${encodeURIComponent(jsonUrl)}`,
`&query=${encodeURIComponent(query)}`,
`&prefix=${encodeURIComponent(prefix)}`,
'&style=plastic',
].join(''))
});
test(dynamicBadgeUrl, () => {
const xmlUrl = 'http://example.com/foo.xml';
const query = '//bar';
const prefix = 'value: ';
given(
'http://img.example.com',
'xml',
'foo',
xmlUrl,
query,
{ prefix, style: 'plastic' }
).expect([
'http://img.example.com/badge/dynamic/xml.svg',
'?label=foo',
`&url=${encodeURIComponent(xmlUrl)}`,
`&url=${encodeURIComponent(dataUrl)}`,
`&query=${encodeURIComponent(query)}`,
`&prefix=${encodeURIComponent(prefix)}`,
'&style=plastic',