Add attachment_views_test.js tests
This commit is contained in:
parent
aa55b6a538
commit
1e498294e0
4 changed files with 37 additions and 15 deletions
|
@ -90,19 +90,22 @@
|
||||||
this.saveFile();
|
this.saveFile();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
saveFile: function() {
|
suggestedName: function() {
|
||||||
var blob = this.blob;
|
var suggestion = 'signal';
|
||||||
var suggestedName = 'signal';
|
|
||||||
if (this.timestamp) {
|
if (this.timestamp) {
|
||||||
suggestedName += moment(this.timestamp).format('-YYYY-MM-DD-HHmmss');
|
suggestion += moment(this.timestamp).format('-YYYY-MM-DD-HHmmss');
|
||||||
}
|
}
|
||||||
if (this.fileType) {
|
if (this.fileType) {
|
||||||
suggestedName += '.' + this.fileType;
|
suggestion += '.' + this.fileType;
|
||||||
}
|
}
|
||||||
|
return suggestion;
|
||||||
|
},
|
||||||
|
saveFile: function() {
|
||||||
|
var blob = this.blob;
|
||||||
var w = extension.windows.getViews()[0];
|
var w = extension.windows.getViews()[0];
|
||||||
if (w && w.chrome && w.chrome.fileSystem) {
|
if (w && w.chrome && w.chrome.fileSystem) {
|
||||||
w.chrome.fileSystem.chooseEntry({
|
w.chrome.fileSystem.chooseEntry({
|
||||||
type: 'saveFile', suggestedName: suggestedName
|
type: 'saveFile', suggestedName: this.suggestedName()
|
||||||
}, function(entry) {
|
}, function(entry) {
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -538,6 +538,7 @@
|
||||||
<script type="text/javascript" src="views/whisper_view_test.js"></script>
|
<script type="text/javascript" src="views/whisper_view_test.js"></script>
|
||||||
<script type="text/javascript" src="views/group_update_view_test.js"></script>
|
<script type="text/javascript" src="views/group_update_view_test.js"></script>
|
||||||
<script type="text/javascript" src="views/message_view_test.js"></script>
|
<script type="text/javascript" src="views/message_view_test.js"></script>
|
||||||
|
<script type="text/javascript" src="views/attachment_view_test.js"></script>
|
||||||
<script type="text/javascript" src="views/timestamp_view_test.js"></script>
|
<script type="text/javascript" src="views/timestamp_view_test.js"></script>
|
||||||
<script type="text/javascript" src="views/list_view_test.js"></script>
|
<script type="text/javascript" src="views/list_view_test.js"></script>
|
||||||
<script type="text/javascript" src="views/conversation_search_view_test.js"></script>
|
<script type="text/javascript" src="views/conversation_search_view_test.js"></script>
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
describe('AttachmentView', function() {
|
|
||||||
|
|
||||||
it('should display an error for an unsupported type', function() {
|
|
||||||
var attachment = { contentType: 'html/text' };
|
|
||||||
var view = new Whisper.AttachmentView({model: attachment}).render();
|
|
||||||
assert.match(view.$el.text(), /Sorry, your attachment has a type, html, that is not currently supported./);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
27
test/views/attachment_view_test.js
Normal file
27
test/views/attachment_view_test.js
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
describe('AttachmentView', function() {
|
||||||
|
|
||||||
|
it('should render a data url for arbitrary content', function() {
|
||||||
|
var attachment = { contentType: 'arbitrary/content' };
|
||||||
|
var view = new Whisper.AttachmentView({model: attachment}).render();
|
||||||
|
assert.equal(view.el.firstChild.tagName, "A");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render an image for images', function() {
|
||||||
|
var now = new Date().getTime();
|
||||||
|
var attachment = { contentType: 'image/png', data: 'grumpy cat' };
|
||||||
|
var view = new Whisper.AttachmentView({model: attachment, timestamp: now}).render();
|
||||||
|
assert.equal(view.el.firstChild.tagName, "IMG");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shoud have correct filename format', function() {
|
||||||
|
var epoch = new Date((new Date(0)).getTimezoneOffset() * 60 * 1000);
|
||||||
|
var attachment = { contentType: 'image/png', data: 'grumpy cat' };
|
||||||
|
var result = new Whisper.AttachmentView({
|
||||||
|
model: attachment,
|
||||||
|
timestamp: epoch
|
||||||
|
}).suggestedName();
|
||||||
|
|
||||||
|
var expected = '1970-01-01-000000';
|
||||||
|
assert(result === 'signal-' + expected + '.png');
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue