Eslintify test/backup_test.js
This commit is contained in:
parent
d0bcf506b4
commit
c3acf43c47
8 changed files with 163 additions and 108 deletions
|
@ -23,6 +23,7 @@ ts/**/*.js
|
||||||
!js/logging.js
|
!js/logging.js
|
||||||
!js/models/conversations.js
|
!js/models/conversations.js
|
||||||
!js/models/messages.js
|
!js/models/messages.js
|
||||||
|
!test/backup_test.js
|
||||||
!js/views/attachment_view.js
|
!js/views/attachment_view.js
|
||||||
!js/views/conversation_view.js
|
!js/views/conversation_view.js
|
||||||
!js/views/conversation_search_view.js
|
!js/views/conversation_search_view.js
|
||||||
|
|
|
@ -3,6 +3,11 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
env: {
|
env: {
|
||||||
mocha: true,
|
mocha: true,
|
||||||
|
browser: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
parserOptions: {
|
||||||
|
sourceType: 'script',
|
||||||
},
|
},
|
||||||
|
|
||||||
rules: {
|
rules: {
|
||||||
|
|
12
test/app/.eslintrc.js
Normal file
12
test/app/.eslintrc.js
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
// For reference: https://github.com/airbnb/javascript
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
env: {
|
||||||
|
mocha: true,
|
||||||
|
browser: false,
|
||||||
|
},
|
||||||
|
|
||||||
|
parserOptions: {
|
||||||
|
sourceType: 'module',
|
||||||
|
},
|
||||||
|
};
|
|
@ -1,52 +1,55 @@
|
||||||
|
/* global Signal: false */
|
||||||
|
/* global assert: false */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
describe('Backup', function() {
|
describe('Backup', () => {
|
||||||
describe('_sanitizeFileName', function() {
|
describe('_sanitizeFileName', () => {
|
||||||
it('leaves a basic string alone', function() {
|
it('leaves a basic string alone', () => {
|
||||||
var initial = 'Hello, how are you #5 (\'fine\' + great).jpg';
|
const initial = 'Hello, how are you #5 (\'fine\' + great).jpg';
|
||||||
var expected = initial;
|
const expected = initial;
|
||||||
assert.strictEqual(Signal.Backup._sanitizeFileName(initial), expected);
|
assert.strictEqual(Signal.Backup._sanitizeFileName(initial), expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('replaces all unknown characters', function() {
|
it('replaces all unknown characters', () => {
|
||||||
var initial = '!@$%^&*=';
|
const initial = '!@$%^&*=';
|
||||||
var expected = '________';
|
const expected = '________';
|
||||||
assert.strictEqual(Signal.Backup._sanitizeFileName(initial), expected);
|
assert.strictEqual(Signal.Backup._sanitizeFileName(initial), expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('_trimFileName', function() {
|
describe('_trimFileName', () => {
|
||||||
it('handles a file with no extension', function() {
|
it('handles a file with no extension', () => {
|
||||||
var initial = '0123456789012345678901234567890123456789';
|
const initial = '0123456789012345678901234567890123456789';
|
||||||
var expected = '012345678901234567890123456789';
|
const expected = '012345678901234567890123456789';
|
||||||
assert.strictEqual(Signal.Backup._trimFileName(initial), expected);
|
assert.strictEqual(Signal.Backup._trimFileName(initial), expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles a file with a long extension', function() {
|
it('handles a file with a long extension', () => {
|
||||||
var initial = '0123456789012345678901234567890123456789.01234567890123456789';
|
const initial = '0123456789012345678901234567890123456789.01234567890123456789';
|
||||||
var expected = '012345678901234567890123456789';
|
const expected = '012345678901234567890123456789';
|
||||||
assert.strictEqual(Signal.Backup._trimFileName(initial), expected);
|
assert.strictEqual(Signal.Backup._trimFileName(initial), expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles a file with a normal extension', function() {
|
it('handles a file with a normal extension', () => {
|
||||||
var initial = '01234567890123456789012345678901234567890123456789.jpg';
|
const initial = '01234567890123456789012345678901234567890123456789.jpg';
|
||||||
var expected = '012345678901234567890123.jpg';
|
const expected = '012345678901234567890123.jpg';
|
||||||
assert.strictEqual(Signal.Backup._trimFileName(initial), expected);
|
assert.strictEqual(Signal.Backup._trimFileName(initial), expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('_getExportAttachmentFileName', function() {
|
describe('_getExportAttachmentFileName', () => {
|
||||||
it('uses original filename if attachment has one', function() {
|
it('uses original filename if attachment has one', () => {
|
||||||
var message = {
|
const message = {
|
||||||
body: 'something',
|
body: 'something',
|
||||||
};
|
};
|
||||||
var index = 0;
|
const index = 0;
|
||||||
var attachment = {
|
const attachment = {
|
||||||
fileName: 'blah.jpg'
|
fileName: 'blah.jpg',
|
||||||
};
|
};
|
||||||
var expected = 'blah.jpg';
|
const expected = 'blah.jpg';
|
||||||
|
|
||||||
var actual = Signal.Backup._getExportAttachmentFileName(
|
const actual = Signal.Backup._getExportAttachmentFileName(
|
||||||
message,
|
message,
|
||||||
index,
|
index,
|
||||||
attachment
|
attachment
|
||||||
|
@ -54,36 +57,17 @@ describe('Backup', function() {
|
||||||
assert.strictEqual(actual, expected);
|
assert.strictEqual(actual, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses attachment id if no filename', function() {
|
it('uses attachment id if no filename', () => {
|
||||||
var message = {
|
const message = {
|
||||||
body: 'something',
|
body: 'something',
|
||||||
};
|
};
|
||||||
var index = 0;
|
const index = 0;
|
||||||
var attachment = {
|
const attachment = {
|
||||||
id: '123'
|
|
||||||
};
|
|
||||||
var expected = '123';
|
|
||||||
|
|
||||||
var actual = Signal.Backup._getExportAttachmentFileName(
|
|
||||||
message,
|
|
||||||
index,
|
|
||||||
attachment
|
|
||||||
);
|
|
||||||
assert.strictEqual(actual, expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('uses filename and contentType if available', function() {
|
|
||||||
var message = {
|
|
||||||
body: 'something',
|
|
||||||
};
|
|
||||||
var index = 0;
|
|
||||||
var attachment = {
|
|
||||||
id: '123',
|
id: '123',
|
||||||
contentType: 'image/jpeg'
|
|
||||||
};
|
};
|
||||||
var expected = '123.jpeg';
|
const expected = '123';
|
||||||
|
|
||||||
var actual = Signal.Backup._getExportAttachmentFileName(
|
const actual = Signal.Backup._getExportAttachmentFileName(
|
||||||
message,
|
message,
|
||||||
index,
|
index,
|
||||||
attachment
|
attachment
|
||||||
|
@ -91,18 +75,37 @@ describe('Backup', function() {
|
||||||
assert.strictEqual(actual, expected);
|
assert.strictEqual(actual, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles strange contentType', function() {
|
it('uses filename and contentType if available', () => {
|
||||||
var message = {
|
const message = {
|
||||||
body: 'something',
|
body: 'something',
|
||||||
};
|
};
|
||||||
var index = 0;
|
const index = 0;
|
||||||
var attachment = {
|
const attachment = {
|
||||||
id: '123',
|
id: '123',
|
||||||
contentType: 'something'
|
contentType: 'image/jpeg',
|
||||||
};
|
};
|
||||||
var expected = '123.something';
|
const expected = '123.jpeg';
|
||||||
|
|
||||||
var actual = Signal.Backup._getExportAttachmentFileName(
|
const actual = Signal.Backup._getExportAttachmentFileName(
|
||||||
|
message,
|
||||||
|
index,
|
||||||
|
attachment
|
||||||
|
);
|
||||||
|
assert.strictEqual(actual, expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles strange contentType', () => {
|
||||||
|
const message = {
|
||||||
|
body: 'something',
|
||||||
|
};
|
||||||
|
const index = 0;
|
||||||
|
const attachment = {
|
||||||
|
id: '123',
|
||||||
|
contentType: 'something',
|
||||||
|
};
|
||||||
|
const expected = '123.something';
|
||||||
|
|
||||||
|
const actual = Signal.Backup._getExportAttachmentFileName(
|
||||||
message,
|
message,
|
||||||
index,
|
index,
|
||||||
attachment
|
attachment
|
||||||
|
@ -111,19 +114,19 @@ describe('Backup', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('_getAnonymousAttachmentFileName', function() {
|
describe('_getAnonymousAttachmentFileName', () => {
|
||||||
it('uses message id', function() {
|
it('uses message id', () => {
|
||||||
var message = {
|
const message = {
|
||||||
id: 'id-45',
|
id: 'id-45',
|
||||||
body: 'something',
|
body: 'something',
|
||||||
};
|
};
|
||||||
var index = 0;
|
const index = 0;
|
||||||
var attachment = {
|
const attachment = {
|
||||||
fileName: 'blah.jpg'
|
fileName: 'blah.jpg',
|
||||||
};
|
};
|
||||||
var expected = 'id-45';
|
const expected = 'id-45';
|
||||||
|
|
||||||
var actual = Signal.Backup._getAnonymousAttachmentFileName(
|
const actual = Signal.Backup._getAnonymousAttachmentFileName(
|
||||||
message,
|
message,
|
||||||
index,
|
index,
|
||||||
attachment
|
attachment
|
||||||
|
@ -131,18 +134,18 @@ describe('Backup', function() {
|
||||||
assert.strictEqual(actual, expected);
|
assert.strictEqual(actual, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('appends index if it is above zero', function() {
|
it('appends index if it is above zero', () => {
|
||||||
var message = {
|
const message = {
|
||||||
id: 'id-45',
|
id: 'id-45',
|
||||||
body: 'something',
|
body: 'something',
|
||||||
};
|
};
|
||||||
var index = 1;
|
const index = 1;
|
||||||
var attachment = {
|
const attachment = {
|
||||||
fileName: 'blah.jpg'
|
fileName: 'blah.jpg',
|
||||||
};
|
};
|
||||||
var expected = 'id-45-1';
|
const expected = 'id-45-1';
|
||||||
|
|
||||||
var actual = Signal.Backup._getAnonymousAttachmentFileName(
|
const actual = Signal.Backup._getAnonymousAttachmentFileName(
|
||||||
message,
|
message,
|
||||||
index,
|
index,
|
||||||
attachment
|
attachment
|
||||||
|
@ -151,64 +154,73 @@ describe('Backup', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('_getConversationDirName', function() {
|
describe('_getConversationDirName', () => {
|
||||||
it('uses name if available', function() {
|
it('uses name if available', () => {
|
||||||
var conversation = {
|
const conversation = {
|
||||||
active_at: 123,
|
active_at: 123,
|
||||||
name: '0123456789012345678901234567890123456789',
|
name: '0123456789012345678901234567890123456789',
|
||||||
id: 'id'
|
id: 'id',
|
||||||
};
|
};
|
||||||
var expected = '123 (012345678901234567890123456789 id)';
|
const expected = '123 (012345678901234567890123456789 id)';
|
||||||
assert.strictEqual(Signal.Backup._getConversationDirName(conversation), expected);
|
assert.strictEqual(Signal.Backup._getConversationDirName(conversation), expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses just id if name is not available', function() {
|
it('uses just id if name is not available', () => {
|
||||||
var conversation = {
|
const conversation = {
|
||||||
active_at: 123,
|
active_at: 123,
|
||||||
id: 'id'
|
id: 'id',
|
||||||
};
|
};
|
||||||
var expected = '123 (id)';
|
const expected = '123 (id)';
|
||||||
assert.strictEqual(Signal.Backup._getConversationDirName(conversation), expected);
|
assert.strictEqual(Signal.Backup._getConversationDirName(conversation), expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses inactive for missing active_at', function() {
|
it('uses inactive for missing active_at', () => {
|
||||||
var conversation = {
|
const conversation = {
|
||||||
name: 'name',
|
name: 'name',
|
||||||
id: 'id'
|
id: 'id',
|
||||||
};
|
};
|
||||||
var expected = 'inactive (name id)';
|
const expected = 'inactive (name id)';
|
||||||
assert.strictEqual(Signal.Backup._getConversationDirName(conversation), expected);
|
assert.strictEqual(Signal.Backup._getConversationDirName(conversation), expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('_getConversationLoggingName', function() {
|
describe('_getConversationLoggingName', () => {
|
||||||
it('uses plain id if conversation is private', function() {
|
it('uses plain id if conversation is private', () => {
|
||||||
var conversation = {
|
const conversation = {
|
||||||
active_at: 123,
|
active_at: 123,
|
||||||
id: 'id',
|
id: 'id',
|
||||||
type: 'private'
|
type: 'private',
|
||||||
};
|
};
|
||||||
var expected = '123 (id)';
|
const expected = '123 (id)';
|
||||||
assert.strictEqual(Signal.Backup._getConversationLoggingName(conversation), expected);
|
assert.strictEqual(
|
||||||
|
Signal.Backup._getConversationLoggingName(conversation),
|
||||||
|
expected
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses just id if name is not available', function() {
|
it('uses just id if name is not available', () => {
|
||||||
var conversation = {
|
const conversation = {
|
||||||
active_at: 123,
|
active_at: 123,
|
||||||
id: 'groupId',
|
id: 'groupId',
|
||||||
type: 'group'
|
type: 'group',
|
||||||
};
|
};
|
||||||
var expected = '123 ([REDACTED_GROUP]pId)';
|
const expected = '123 ([REDACTED_GROUP]pId)';
|
||||||
assert.strictEqual(Signal.Backup._getConversationLoggingName(conversation), expected);
|
assert.strictEqual(
|
||||||
|
Signal.Backup._getConversationLoggingName(conversation),
|
||||||
|
expected
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses inactive for missing active_at', function() {
|
it('uses inactive for missing active_at', () => {
|
||||||
var conversation = {
|
const conversation = {
|
||||||
id: 'id',
|
id: 'id',
|
||||||
type: 'private'
|
type: 'private',
|
||||||
};
|
};
|
||||||
var expected = 'inactive (id)';
|
const expected = 'inactive (id)';
|
||||||
assert.strictEqual(Signal.Backup._getConversationLoggingName(conversation), expected);
|
assert.strictEqual(
|
||||||
|
Signal.Backup._getConversationLoggingName(conversation),
|
||||||
|
expected
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"globals": {
|
|
||||||
"check": true,
|
|
||||||
"gen": true
|
|
||||||
}
|
|
||||||
}
|
|
27
test/modules/.eslintrc.js
Normal file
27
test/modules/.eslintrc.js
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
// For reference: https://github.com/airbnb/javascript
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
env: {
|
||||||
|
mocha: true,
|
||||||
|
browser: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
"globals": {
|
||||||
|
check: true,
|
||||||
|
gen: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
parserOptions: {
|
||||||
|
sourceType: 'module',
|
||||||
|
},
|
||||||
|
|
||||||
|
rules: {
|
||||||
|
// We still get the value of this rule, it just allows for dev deps
|
||||||
|
'import/no-extraneous-dependencies': ['error', {
|
||||||
|
devDependencies: true
|
||||||
|
}],
|
||||||
|
|
||||||
|
// We want to keep each test structured the same, even if its contents are tiny
|
||||||
|
'arrow-body-style': 'off',
|
||||||
|
}
|
||||||
|
};
|
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
/* global window: false */
|
/* global window: false */
|
||||||
|
|
||||||
// Because we aren't hosting the Style Guide in Electron, we can't rely on preload.js
|
// Because we aren't hosting the Style Guide in Electron, we can't rely on preload.js
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
/* global window: false */
|
/* global window: false */
|
||||||
|
|
||||||
// Taken from background.html.
|
// Taken from background.html.
|
||||||
|
|
Loading…
Reference in a new issue