2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2015-2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-11-02 18:02:53 +00:00
|
|
|
/* global Whisper */
|
|
|
|
|
|
|
|
describe('Whisper.View', () => {
|
|
|
|
it('renders a template with render_attributes', () => {
|
|
|
|
const ViewClass = Whisper.View.extend({
|
2015-03-05 23:25:49 +00:00
|
|
|
template: '<div>{{ variable }}</div>',
|
2015-03-07 01:05:36 +00:00
|
|
|
render_attributes: {
|
2018-04-27 21:25:04 +00:00
|
|
|
variable: 'value',
|
|
|
|
},
|
2015-03-05 23:25:49 +00:00
|
|
|
});
|
|
|
|
|
2018-11-02 18:02:53 +00:00
|
|
|
const view = new ViewClass();
|
2015-03-05 23:25:49 +00:00
|
|
|
view.render();
|
|
|
|
assert.strictEqual(view.$el.html(), '<div>value</div>');
|
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
it('renders a template with no render_attributes', () => {
|
|
|
|
const ViewClass = Whisper.View.extend({
|
2018-04-27 21:25:04 +00:00
|
|
|
template: '<div>static text</div>',
|
2015-03-05 23:25:49 +00:00
|
|
|
});
|
|
|
|
|
2018-11-02 18:02:53 +00:00
|
|
|
const view = new ViewClass();
|
2015-03-05 23:25:49 +00:00
|
|
|
view.render();
|
|
|
|
assert.strictEqual(view.$el.html(), '<div>static text</div>');
|
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
it('renders a template function with render_attributes function', () => {
|
|
|
|
const ViewClass = Whisper.View.extend({
|
|
|
|
template() {
|
2018-04-27 21:25:04 +00:00
|
|
|
return '<div>{{ variable }}</div>';
|
|
|
|
},
|
2018-11-02 18:02:53 +00:00
|
|
|
render_attributes() {
|
2015-03-05 23:25:49 +00:00
|
|
|
return { variable: 'value' };
|
2018-04-27 21:25:04 +00:00
|
|
|
},
|
2015-03-05 23:25:49 +00:00
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
const view = new ViewClass();
|
2015-03-05 23:25:49 +00:00
|
|
|
view.render();
|
|
|
|
assert.strictEqual(view.$el.html(), '<div>value</div>');
|
|
|
|
});
|
|
|
|
});
|