signal-desktop/test/views/whisper_view_test.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

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({
template: '<div>{{ variable }}</div>',
render_attributes: {
2018-04-27 21:25:04 +00:00
variable: 'value',
},
});
2018-11-02 18:02:53 +00:00
const view = new ViewClass();
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>',
});
2018-11-02 18:02:53 +00:00
const view = new ViewClass();
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() {
return { variable: 'value' };
2018-04-27 21:25:04 +00:00
},
});
2018-11-02 18:02:53 +00:00
const view = new ViewClass();
view.render();
assert.strictEqual(view.$el.html(), '<div>value</div>');
});
});