1
0
mirror of https://github.com/badges/shields.git synced 2025-11-19 19:42:14 +03:00
Files
shields/services/w3c/w3c-validation.tester.js
seetd 54bcedc0f4 Add [W3C] Markup Validation Service Badge (#3833) (#4148)
* Add W3C Markup Validation Service Badge (#3833)

* Move helper functions into different file and added unit tests

* Remove unnecessary comments from spec file

* pr changes move code into transform method and validation of messages

* use joi.string().regex instead of custom validator

* Simplify the fetch, handle methods. Make Joi validation for string

* Remove empty parameter from tests and label from render method

* encodeUri on the doc and schema properties send to API

* Documentation and remove unnecessary Object.keys call

* Use regular expressions to make tests less brittle

* made service less for message and color more generic and less brittle

* Throw standard NoFound exception for invalid URL. Use w3c endpoint

* use sazerac for w3c-validation-helper.spec.js

* Replace documentation API url and API documentation url

* Switch back to https://validator.nu endpoint. Remove html4 assertions

* Increase strictness of NotFound checks
2019-10-21 18:40:14 -05:00

101 lines
2.7 KiB
JavaScript

'use strict'
const Joi = require('@hapi/joi')
const t = (module.exports = require('../tester').createServiceTester())
const isErrorOnly = Joi.string().regex(/^[0-9]+ errors?$/)
const isWarningOnly = Joi.string().regex(/^[0-9]+ warnings?$/)
const isErrorAndWarning = Joi.string().regex(
/^[0-9]+ errors?, [0-9]+ warnings?$/
)
const isW3CMessage = Joi.alternatives().try(
'validated',
isErrorOnly,
isWarningOnly,
isErrorAndWarning
)
const isW3CColors = Joi.alternatives().try('brightgreen', 'red', 'yellow')
t.create(
'W3C Validation page conforms to standards with no preset and parser with brightgreen badge'
)
.get(
'/default.json?targetUrl=https://hsivonen.com/test/moz/messages-types/no-message.html'
)
.expectBadge({
label: 'w3c',
message: isW3CMessage,
color: isW3CColors,
})
t.create(
'W3C Validation page conforms to standards with no HTML4 preset and HTML parser with brightgreen badge'
)
.get(
'/html.json?targetUrl=https://hsivonen.com/test/moz/messages-types/no-message.html&preset=HTML,%20SVG%201.1,%20MathML%203.0'
)
.expectBadge({
label: 'w3c',
message: isW3CMessage,
color: isW3CColors,
})
t.create('W3C Validation target url not found error')
.get(
'/default.json?targetUrl=http://hsivonen.com/test/moz/messages-types/404.html'
)
.expectBadge({
label: 'w3c',
message: 'target url not found',
})
t.create('W3C Validation target url host not found error')
.get('/default.json?targetUrl=https://adfasdfasdfasdfadfadfadfasdfadf.com')
.expectBadge({
label: 'w3c',
message: 'target url not found',
})
t.create('W3C Validation page has 1 validation error with red badge')
.get(
'/default.json?targetUrl=http://hsivonen.com/test/moz/messages-types/warning.html'
)
.expectBadge({
label: 'w3c',
message: isW3CMessage,
color: isW3CColors,
})
t.create(
'W3C Validation page has 3 validation error using HTML 4.01 Frameset preset with red badge'
)
.get(
'/html.json?targetUrl=http://hsivonen.com/test/moz/messages-types/warning.html&preset=HTML 4.01 Frameset, URL / XHTML 1.0 Frameset, URL'
)
.expectBadge({
label: 'w3c',
message: isW3CMessage,
color: isW3CColors,
})
t.create('W3C Validation page has 1 validation warning with yellow badge')
.get(
'/default.json?targetUrl=http://hsivonen.com/test/moz/messages-types/info.svg'
)
.expectBadge({
label: 'w3c',
message: isW3CMessage,
color: isW3CColors,
})
t.create('W3C Validation page has multiple of validation errors with red badge')
.get(
'/default.json?targetUrl=http://hsivonen.com/test/moz/messages-types/range-error.html'
)
.expectBadge({
label: 'w3c',
message: isW3CMessage,
color: isW3CColors,
})