Added link test expectations (#3376)
This commit is contained in:
@@ -8,7 +8,8 @@ exports['The badge generator JSON should always produce the same JSON (unless we
|
||||
"label": "cactus",
|
||||
"value": "grown",
|
||||
"message": "grown",
|
||||
"color": null
|
||||
"color": null,
|
||||
"link": ["https://example.com/","https://other.example.com/"]
|
||||
}
|
||||
`
|
||||
|
||||
|
||||
@@ -32,19 +32,22 @@ const factory = superclass =>
|
||||
return this
|
||||
}
|
||||
|
||||
expectBadge({ label, message, logoWidth, labelColor, color }) {
|
||||
expectBadge({ label, message, logoWidth, labelColor, color, link }) {
|
||||
return this.afterJSON(json => {
|
||||
this.constructor._expectField(json, 'label', label)
|
||||
this.constructor._expectField(json, 'message', message)
|
||||
this.constructor._expectField(json, 'logoWidth', logoWidth)
|
||||
this.constructor._expectField(json, 'labelColor', labelColor)
|
||||
this.constructor._expectField(json, 'color', color)
|
||||
this.constructor._expectField(json, 'link', link)
|
||||
})
|
||||
}
|
||||
|
||||
static _expectField(json, name, expected) {
|
||||
if (typeof expected === 'string') {
|
||||
expect(json[name], `${name} mismatch`).to.equal(expected)
|
||||
} else if (Array.isArray(expected)) {
|
||||
expect(json[name], `${name} mismatch`).to.deep.equal(expected)
|
||||
} else if (typeof expected === 'object') {
|
||||
Joi.attempt(json[name], expected, `${name} mismatch:`)
|
||||
}
|
||||
|
||||
@@ -94,7 +94,11 @@ describe('The badge generator', function() {
|
||||
|
||||
describe('JSON', function() {
|
||||
it('should always produce the same JSON (unless we have changed something!)', function() {
|
||||
const json = makeBadge({ text: ['cactus', 'grown'], format: 'json' })
|
||||
const json = makeBadge({
|
||||
text: ['cactus', 'grown'],
|
||||
format: 'json',
|
||||
links: ['https://example.com/', 'https://other.example.com/'],
|
||||
})
|
||||
const jsonWithLFEndings = eol.lf(json)
|
||||
snapshot(jsonWithLFEndings)
|
||||
})
|
||||
|
||||
@@ -5,5 +5,6 @@
|
||||
"message": {{=JSON.stringify(it.text[1])}},{{?it.logoWidth}}
|
||||
"logoWidth": {{=JSON.stringify(it.logoWidth)}},{{?}}{{?it.labelColor}}
|
||||
"labelColor": {{=JSON.stringify(it.labelColor)}},{{?}}
|
||||
"color": {{=JSON.stringify(it.color || null)}}
|
||||
"color": {{=JSON.stringify(it.color || null)}}{{?(it.links[0] && it.links[0].length || it.links[1] && it.links[1].length)}},
|
||||
"link": {{=JSON.stringify(it.links)}}{{?}}
|
||||
}
|
||||
@@ -8,6 +8,9 @@ t.create('semver stability (valid)')
|
||||
.expectBadge({
|
||||
label: 'semver stability',
|
||||
message: isIntegerPercentage,
|
||||
link: [
|
||||
'https://dependabot.com/compatibility-score.html?package-manager=bundler&dependency-name=puma&version-scheme=semver',
|
||||
],
|
||||
})
|
||||
|
||||
t.create('semver stability (invalid error)')
|
||||
|
||||
@@ -8,6 +8,10 @@ t.create('Forks')
|
||||
.expectBadge({
|
||||
label: 'forks',
|
||||
message: isMetric,
|
||||
link: [
|
||||
'https://github.com/badges/shields/fork',
|
||||
'https://github.com/badges/shields/network',
|
||||
],
|
||||
})
|
||||
|
||||
t.create('Forks (repo not found)')
|
||||
|
||||
@@ -8,6 +8,10 @@ t.create('Stars')
|
||||
.expectBadge({
|
||||
label: 'stars',
|
||||
message: Joi.string().regex(/^\w+$/),
|
||||
link: [
|
||||
'https://github.com/badges/shields',
|
||||
'https://github.com/badges/shields/stargazers',
|
||||
],
|
||||
})
|
||||
|
||||
t.create('Stars (repo not found)')
|
||||
|
||||
@@ -10,6 +10,10 @@ t.create('Watchers')
|
||||
message: Joi.number()
|
||||
.integer()
|
||||
.positive(),
|
||||
link: [
|
||||
'https://github.com/badges/shields',
|
||||
'https://github.com/badges/shields/watchers',
|
||||
],
|
||||
})
|
||||
|
||||
t.create('Watchers (repo not found)')
|
||||
|
||||
@@ -13,6 +13,10 @@ t.create('Followers')
|
||||
.expectBadge({
|
||||
label: 'follow @shields_io',
|
||||
message: isMetric,
|
||||
link: [
|
||||
'https://twitter.com/intent/follow?screen_name=shields_io',
|
||||
'https://twitter.com/shields_io/followers',
|
||||
],
|
||||
})
|
||||
|
||||
t.create('Invalid Username Specified')
|
||||
@@ -24,4 +28,11 @@ t.create('Invalid Username Specified')
|
||||
|
||||
t.create('URL')
|
||||
.get('/url/https/shields.io.json')
|
||||
.expectBadge({ label: 'tweet', message: '' })
|
||||
.expectBadge({
|
||||
label: 'tweet',
|
||||
message: '',
|
||||
link: [
|
||||
'https://twitter.com/intent/tweet?text=Wow:&url=https%3A%2F%2Fshields.io',
|
||||
'https://twitter.com/search?q=https%3A%2F%2Fshields.io',
|
||||
],
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user