Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎨 Added additional parameters to subscribe_form and input_email helpe…
…rs (#9820) closes #9134 - Added form_id, input_id, and button_id parameters to subscribe_form helper - Added id parameter to input_email helper - Added test coverage to input_email helper - Added quotes to id attributes for consistency - Added subscribe_form helper tests - Updated express to v4 in helper tests
- Loading branch information
Showing
7 changed files
with
157 additions
and
9 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
var should = require('should'), | ||
// Stuff we are testing | ||
input_email = require('../../../../server/apps/subscribers/lib/helpers/input_email'); | ||
|
||
describe('{{input_email}} helper', function () { | ||
it('has input_email helper', function () { | ||
should.exist(input_email); | ||
}); | ||
|
||
it('returns the correct input when no custom options are specified', function () { | ||
var markup = '<input class="subscribe-email" type="email" name="email" />', | ||
rendered = input_email(); | ||
should.exist(rendered); | ||
|
||
String(rendered).should.equal(markup); | ||
}); | ||
|
||
it('returns the correct input when a custom class is specified', function () { | ||
var markup = '<input class="test-class" type="email" name="email" />', | ||
options = { | ||
hash: { | ||
class: 'test-class' | ||
} | ||
}, | ||
rendered = input_email(options); | ||
|
||
should.exist(rendered); | ||
|
||
String(rendered).should.equal(markup); | ||
}); | ||
|
||
it('returns the correct input when an autofocus is specified', function () { | ||
var markup = '<input class="subscribe-email" type="email" name="email" autofocus="autofocus" />', | ||
options = { | ||
hash: { | ||
autofocus: true | ||
} | ||
}, | ||
rendered = input_email(options); | ||
|
||
should.exist(rendered); | ||
|
||
String(rendered).should.equal(markup); | ||
}); | ||
|
||
it('returns the correct input when a placeholder is specified', function () { | ||
var markup = '<input class="subscribe-email" type="email" name="email" placeholder="Test" />', | ||
options = { | ||
hash: { | ||
placeholder: 'Test' | ||
} | ||
}, | ||
rendered = input_email(options); | ||
|
||
should.exist(rendered); | ||
|
||
String(rendered).should.equal(markup); | ||
}); | ||
|
||
it('returns the correct input when a value is specified', function () { | ||
var markup = '<input class="subscribe-email" type="email" name="email" value="Test value" />', | ||
options = { | ||
hash: { | ||
value: 'Test value' | ||
} | ||
}, | ||
rendered = input_email(options); | ||
|
||
should.exist(rendered); | ||
|
||
String(rendered).should.equal(markup); | ||
}); | ||
|
||
it('returns the correct input when an id is specified', function () { | ||
var markup = '<input class="subscribe-email" type="email" name="email" id="test-id" />', | ||
options = { | ||
hash: { | ||
id: 'test-id' | ||
} | ||
}, | ||
rendered = input_email(options); | ||
|
||
should.exist(rendered); | ||
|
||
String(rendered).should.equal(markup); | ||
}); | ||
}); |
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,56 @@ | ||
var should = require('should'), | ||
hbs = require('../../../../server/services/themes/engine'), | ||
configUtils = require('../../../utils/configUtils'), | ||
// Stuff we are testing | ||
subscribe_form = require('../../../../server/apps/subscribers/lib/helpers/subscribe_form'); | ||
|
||
describe('{{subscribe_form}} helper', function () { | ||
before(function (done) { | ||
hbs.express4({partialsDir: [configUtils.config.get('paths').helperTemplates]}); | ||
hbs.cachePartials(function () { | ||
done(); | ||
}); | ||
|
||
hbs.registerHelper('subscribe_form', subscribe_form); | ||
}); | ||
|
||
after(function () { | ||
// @NOTE: We have to deregister the new helper, otherwise we operate on the global hbs engine | ||
// which has registered the subscribe form helper. This is caused by the theme engine creating | ||
// a global hbs instance as soon as you require the file. | ||
hbs.handlebars.unregisterHelper('subscribe_form'); | ||
}); | ||
|
||
it('returns a form with basic expected structure', function () { | ||
var rendered = subscribe_form({data: {root: ''}, hash: {}}); | ||
should.exist(rendered); | ||
|
||
should.exist(rendered); | ||
rendered.string.should.match(/form method="post" action="\/subscribe\/"/); | ||
rendered.string.should.match(/button id="" class="" type="submit"/); | ||
}); | ||
|
||
it('returns adds classes when passed as parameters', function () { | ||
var rendered = subscribe_form({data: {root: ''}, hash: { | ||
form_class: 'form-class', | ||
button_class: 'button-class' | ||
}}); | ||
should.exist(rendered); | ||
|
||
should.exist(rendered); | ||
rendered.string.should.match(/form method="post" action="\/subscribe\/" id="" class="form-class"/); | ||
rendered.string.should.match(/button id="" class="button-class" type="submit"/); | ||
}); | ||
|
||
it('returns adds classes when passed as parameters', function () { | ||
var rendered = subscribe_form({data: {root: ''}, hash: { | ||
form_id: 'form-id', | ||
button_id: 'button-id' | ||
}}); | ||
should.exist(rendered); | ||
|
||
should.exist(rendered); | ||
rendered.string.should.match(/form method="post" action="\/subscribe\/" id="form-id" class=""/); | ||
rendered.string.should.match(/button id="button-id" class="" type="submit"/); | ||
}); | ||
}); |
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
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