Skip to content
This repository has been archived by the owner on Mar 14, 2022. It is now read-only.

Commit

Permalink
Require demo titles in origami.json. (#510)
Browse files Browse the repository at this point in the history
* Require demo titles in origami.json.

Inline with the Origami spec and registry expectations.

* Require non-blank string demo titles

* word
  • Loading branch information
notlee authored and JakeChampion committed Feb 20, 2018
1 parent e599280 commit 5d555dc
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/tasks/verify-origami-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ function origamiJson(config) {
if (hasExpanded) {
result.push('The expanded property has been deprecated. Use the "hidden" property when a demo should not appear in the Registry.');
}

const hasInvalidTitle = componentDemos.some(function (demo) {
return !(demo.title && typeof demo.title === 'string' && demo.title.trim().length > 0);
});
if (hasInvalidTitle) {
result.push('All demos require a title property which is non-empty and of type "string".');
}
}

if (result.length > 0) {
Expand Down
1 change: 1 addition & 0 deletions test/unit/fixtures/o-test/origami.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"demos": [
{
"title": "Test module",
"name": "pa11y",
"template": "demos/src/pa11y.mustache",
"description": "Pa11y test"
Expand Down
69 changes: 68 additions & 1 deletion test/unit/tasks/verify-origami-json.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,10 @@ describe('verify-origami-json', function () {
it('should fail when an expanded property is found for a demo', function () {
const origamiJSON = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'origami.json'), 'utf-8'));
origamiJSON.demos = [{
title: 'Expanded property in use.',
expanded: false
}, {
title: 'Expanded property in use.',
expanded: true
}];
fs.writeFileSync('origami.json', JSON.stringify(origamiJSON), 'utf8');
Expand All @@ -369,6 +371,71 @@ describe('verify-origami-json', function () {
);
});
});
});

describe('demo title', function() {
const origamiJSON = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'origami.json'), 'utf-8'));
origamiJSON.origamiType = 'module';
const expectedError = 'Failed linting:\n\n' +
'All demos require a title property which is non-empty and of type "string".\n\n' +
'The origami.json file does not conform to the specification at http://origami.ft.com/docs/syntax/origamijson/';

it('should fail when a demo does not have a title property', function () {
origamiJSON.demos = [{
name: 'a name but no user friendly title for this demo'
}];
fs.writeFileSync('origami.json', JSON.stringify(origamiJSON), 'utf8');
return verifyOrigamiJson().task()
.then(function () {
proclaim.notOk(true, `origami.json validated when one of its demos is not a non-empty string`);
},
function (verifiedOrigamiJson) {
proclaim.equal(verifiedOrigamiJson.message, expectedError);
});
});

it('should fail when a demo has a empty title', function () {
origamiJSON.demos = [{
name: 'an unhelpful empty title for this demo',
title: ''
}];
fs.writeFileSync('origami.json', JSON.stringify(origamiJSON), 'utf8');
return verifyOrigamiJson().task()
.then(function () {
proclaim.notOk(true, `origami.json validated when one of its demos is not a non-empty string`);
},
function (verifiedOrigamiJson) {
proclaim.equal(verifiedOrigamiJson.message, expectedError);
});
});

it('should fail when a demo has a blank title', function () {
origamiJSON.demos = [{
name: 'an unhelpful blank title for this demo',
title: ' '
}];
fs.writeFileSync('origami.json', JSON.stringify(origamiJSON), 'utf8');
return verifyOrigamiJson().task()
.then(function () {
proclaim.notOk(true, `origami.json validated when one of its demos is not a non-empty string`);
},
function (verifiedOrigamiJson) {
proclaim.equal(verifiedOrigamiJson.message, expectedError);
});
});

it('should fail when a demo has a non-string title', function () {
origamiJSON.demos = [{
title: ['array here']
}];
fs.writeFileSync('origami.json', JSON.stringify(origamiJSON), 'utf8');
return verifyOrigamiJson().task()
.then(function () {
proclaim.notOk(true, `origami.json validated but one of its demos is not a non-empty string`);
},function (verifiedOrigamiJson) {
proclaim.equal(verifiedOrigamiJson.message, expectedError);
});
});

});
});
});

0 comments on commit 5d555dc

Please sign in to comment.