-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compile-contact-summary] introduce standardised layout
- Loading branch information
Showing
10 changed files
with
132 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
test/data/compile-contact-summary/includes/contact-summary.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
'original'; | ||
__include_inline__('lib.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
'included'; |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
'a javascript string'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const assert = require('chai').assert; | ||
const compileContactSummary = require('../../src/lib/compile-contact-summary'); | ||
|
||
const BASE_DIR = 'data/compile-contact-summary'; | ||
|
||
describe('compile-contact-summary', function() { | ||
|
||
it('should throw an error if no recognised file layout is found', function() { | ||
try { | ||
|
||
// when | ||
compileContactSummary(`${BASE_DIR}/empty`); | ||
|
||
assert.fail('Expected error to be thrown.'); | ||
|
||
} catch(e) { | ||
// expected :¬) | ||
} | ||
}); | ||
|
||
describe('with contact-summary.js', function() { | ||
|
||
it('should include a simple file verbatim', function() { | ||
// when | ||
const compiled = compileContactSummary(`${BASE_DIR}/verbatim`); | ||
|
||
// then | ||
assert.equal(compiled, '\'a javascript string\';'); | ||
}); | ||
|
||
it('should include other source file referenced with __include_inline__()', function() { | ||
// when | ||
const compiled = compileContactSummary(`${BASE_DIR}/includes`); | ||
|
||
// then | ||
assert.equal(compiled, '\'original\';\'included\';'); | ||
}); | ||
|
||
}); | ||
|
||
describe('with template', function() { | ||
|
||
it('should include the user-supplied code with template header and footer', function() { | ||
// when | ||
const compiled = compileContactSummary(`${BASE_DIR}/templated`); | ||
|
||
// then | ||
assert.equal(compiled, 'var context,fields,cards;function isReportValid(e){return e&&!(e.errors&&e.errors.length)}var result={cards:[],fields:fields.filter(function(e){if((e.appliesToType===contact.type||\'!\'===e.appliesToType.charAt(0)&&e.appliesToType.slice(1)!==contact.type)&&(!e.appliesIf||e.appliesIf()))return delete e.appliesToType,delete e.appliesIf,!0})};return cards.forEach(function(e){var t,l;switch(e.appliesToType){case\'report\':for(t=0;t<reports.length;++t)isReportValid(l=reports[t])&&e.appliesIf(l)&&(result.cards.push({label:e.label,fields:e.fields(l)}),e.modifyContext&&e.modifyContext(context));break;default:if(contact.type!==e.appliesToType)return;e.appliesIf()&&(result.cards.push({label:e.label,fields:e.fields()}),e.modifyContext&&e.modifyContext(context))}}),result.context=context,result;'); | ||
}); | ||
}); | ||
|
||
}); |