Files
shields/services/validate-example.spec.js
Paul Melnikow 84a5be3946 Declare static examples using namedParams (#2308)
This continues the work from #2279, by allowing example badges to be specified using `namedParams`. Using an object makes it possible for us to display these in form fields down the line. (#701)

I've called this the "preferred" way, and labeled the other ways deprecated. I've also added some doc to the `examples` property in BaseService. Then I realized we had some doc in the tutorial, though I think it's fine to have a short version in the tutorial, and the gory detail in BaseService.

I've also added a `pattern` keyword, and made `urlPattern` an alias.

Closes #2050.
2018-11-17 09:47:25 -05:00

46 lines
1.2 KiB
JavaScript

'use strict'
const { expect } = require('chai')
const validateExample = require('./validate-example')
describe('validateExample function', function() {
it('passes valid examples', function() {
const validExamples = [
{ staticExample: {}, pattern: 'dt/:package', exampleUrl: 'dt/mypackage' },
{
staticExample: {},
pattern: 'dt/:package',
namedParams: { package: 'mypackage' },
},
{ previewUrl: 'dt/mypackage' },
]
validExamples.forEach(example => {
expect(() =>
validateExample(example, 0, { route: {}, name: 'mockService' })
).not.to.throw(Error)
})
})
it('rejects invalid examples', function() {
const invalidExamples = [
{},
{ staticExample: {} },
{
staticExample: {},
pattern: 'dt/:package',
namedParams: { package: 'mypackage' },
exampleUrl: 'dt/mypackage',
},
{ staticExample: {}, pattern: 'dt/:package' },
{ staticExample: {}, pattern: 'dt/:package', previewUrl: 'dt/mypackage' },
]
invalidExamples.forEach(example => {
expect(() =>
validateExample(example, 0, { route: {}, name: 'mockService' })
).to.throw(Error)
})
})
})