Eslintify test/backup_test.js

This commit is contained in:
Scott Nonnenberg 2018-04-20 12:11:56 -07:00
parent d0bcf506b4
commit c3acf43c47
No known key found for this signature in database
GPG key ID: 5F82280C35134661
8 changed files with 163 additions and 108 deletions

View file

@ -23,6 +23,7 @@ ts/**/*.js
!js/logging.js
!js/models/conversations.js
!js/models/messages.js
!test/backup_test.js
!js/views/attachment_view.js
!js/views/conversation_view.js
!js/views/conversation_search_view.js

View file

@ -3,6 +3,11 @@
module.exports = {
env: {
mocha: true,
browser: true,
},
parserOptions: {
sourceType: 'script',
},
rules: {

12
test/app/.eslintrc.js Normal file
View file

@ -0,0 +1,12 @@
// For reference: https://github.com/airbnb/javascript
module.exports = {
env: {
mocha: true,
browser: false,
},
parserOptions: {
sourceType: 'module',
},
};

View file

@ -1,52 +1,55 @@
/* global Signal: false */
/* global assert: false */
'use strict';
describe('Backup', function() {
describe('_sanitizeFileName', function() {
it('leaves a basic string alone', function() {
var initial = 'Hello, how are you #5 (\'fine\' + great).jpg';
var expected = initial;
describe('Backup', () => {
describe('_sanitizeFileName', () => {
it('leaves a basic string alone', () => {
const initial = 'Hello, how are you #5 (\'fine\' + great).jpg';
const expected = initial;
assert.strictEqual(Signal.Backup._sanitizeFileName(initial), expected);
});
it('replaces all unknown characters', function() {
var initial = '!@$%^&*=';
var expected = '________';
it('replaces all unknown characters', () => {
const initial = '!@$%^&*=';
const expected = '________';
assert.strictEqual(Signal.Backup._sanitizeFileName(initial), expected);
});
});
describe('_trimFileName', function() {
it('handles a file with no extension', function() {
var initial = '0123456789012345678901234567890123456789';
var expected = '012345678901234567890123456789';
describe('_trimFileName', () => {
it('handles a file with no extension', () => {
const initial = '0123456789012345678901234567890123456789';
const expected = '012345678901234567890123456789';
assert.strictEqual(Signal.Backup._trimFileName(initial), expected);
});
it('handles a file with a long extension', function() {
var initial = '0123456789012345678901234567890123456789.01234567890123456789';
var expected = '012345678901234567890123456789';
it('handles a file with a long extension', () => {
const initial = '0123456789012345678901234567890123456789.01234567890123456789';
const expected = '012345678901234567890123456789';
assert.strictEqual(Signal.Backup._trimFileName(initial), expected);
});
it('handles a file with a normal extension', function() {
var initial = '01234567890123456789012345678901234567890123456789.jpg';
var expected = '012345678901234567890123.jpg';
it('handles a file with a normal extension', () => {
const initial = '01234567890123456789012345678901234567890123456789.jpg';
const expected = '012345678901234567890123.jpg';
assert.strictEqual(Signal.Backup._trimFileName(initial), expected);
});
});
describe('_getExportAttachmentFileName', function() {
it('uses original filename if attachment has one', function() {
var message = {
describe('_getExportAttachmentFileName', () => {
it('uses original filename if attachment has one', () => {
const message = {
body: 'something',
};
var index = 0;
var attachment = {
fileName: 'blah.jpg'
const index = 0;
const attachment = {
fileName: 'blah.jpg',
};
var expected = 'blah.jpg';
const expected = 'blah.jpg';
var actual = Signal.Backup._getExportAttachmentFileName(
const actual = Signal.Backup._getExportAttachmentFileName(
message,
index,
attachment
@ -54,36 +57,17 @@ describe('Backup', function() {
assert.strictEqual(actual, expected);
});
it('uses attachment id if no filename', function() {
var message = {
it('uses attachment id if no filename', () => {
const message = {
body: 'something',
};
var index = 0;
var 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 = {
const index = 0;
const attachment = {
id: '123',
contentType: 'image/jpeg'
};
var expected = '123.jpeg';
const expected = '123';
var actual = Signal.Backup._getExportAttachmentFileName(
const actual = Signal.Backup._getExportAttachmentFileName(
message,
index,
attachment
@ -91,18 +75,37 @@ describe('Backup', function() {
assert.strictEqual(actual, expected);
});
it('handles strange contentType', function() {
var message = {
it('uses filename and contentType if available', () => {
const message = {
body: 'something',
};
var index = 0;
var attachment = {
const index = 0;
const attachment = {
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,
index,
attachment
@ -111,19 +114,19 @@ describe('Backup', function() {
});
});
describe('_getAnonymousAttachmentFileName', function() {
it('uses message id', function() {
var message = {
describe('_getAnonymousAttachmentFileName', () => {
it('uses message id', () => {
const message = {
id: 'id-45',
body: 'something',
};
var index = 0;
var attachment = {
fileName: 'blah.jpg'
const index = 0;
const attachment = {
fileName: 'blah.jpg',
};
var expected = 'id-45';
const expected = 'id-45';
var actual = Signal.Backup._getAnonymousAttachmentFileName(
const actual = Signal.Backup._getAnonymousAttachmentFileName(
message,
index,
attachment
@ -131,18 +134,18 @@ describe('Backup', function() {
assert.strictEqual(actual, expected);
});
it('appends index if it is above zero', function() {
var message = {
it('appends index if it is above zero', () => {
const message = {
id: 'id-45',
body: 'something',
};
var index = 1;
var attachment = {
fileName: 'blah.jpg'
const index = 1;
const attachment = {
fileName: 'blah.jpg',
};
var expected = 'id-45-1';
const expected = 'id-45-1';
var actual = Signal.Backup._getAnonymousAttachmentFileName(
const actual = Signal.Backup._getAnonymousAttachmentFileName(
message,
index,
attachment
@ -151,64 +154,73 @@ describe('Backup', function() {
});
});
describe('_getConversationDirName', function() {
it('uses name if available', function() {
var conversation = {
describe('_getConversationDirName', () => {
it('uses name if available', () => {
const conversation = {
active_at: 123,
name: '0123456789012345678901234567890123456789',
id: 'id'
id: 'id',
};
var expected = '123 (012345678901234567890123456789 id)';
const expected = '123 (012345678901234567890123456789 id)';
assert.strictEqual(Signal.Backup._getConversationDirName(conversation), expected);
});
it('uses just id if name is not available', function() {
var conversation = {
it('uses just id if name is not available', () => {
const conversation = {
active_at: 123,
id: 'id'
id: 'id',
};
var expected = '123 (id)';
const expected = '123 (id)';
assert.strictEqual(Signal.Backup._getConversationDirName(conversation), expected);
});
it('uses inactive for missing active_at', function() {
var conversation = {
it('uses inactive for missing active_at', () => {
const conversation = {
name: 'name',
id: 'id'
id: 'id',
};
var expected = 'inactive (name id)';
const expected = 'inactive (name id)';
assert.strictEqual(Signal.Backup._getConversationDirName(conversation), expected);
});
});
describe('_getConversationLoggingName', function() {
it('uses plain id if conversation is private', function() {
var conversation = {
describe('_getConversationLoggingName', () => {
it('uses plain id if conversation is private', () => {
const conversation = {
active_at: 123,
id: 'id',
type: 'private'
type: 'private',
};
var expected = '123 (id)';
assert.strictEqual(Signal.Backup._getConversationLoggingName(conversation), expected);
const expected = '123 (id)';
assert.strictEqual(
Signal.Backup._getConversationLoggingName(conversation),
expected
);
});
it('uses just id if name is not available', function() {
var conversation = {
it('uses just id if name is not available', () => {
const conversation = {
active_at: 123,
id: 'groupId',
type: 'group'
type: 'group',
};
var expected = '123 ([REDACTED_GROUP]pId)';
assert.strictEqual(Signal.Backup._getConversationLoggingName(conversation), expected);
const expected = '123 ([REDACTED_GROUP]pId)';
assert.strictEqual(
Signal.Backup._getConversationLoggingName(conversation),
expected
);
});
it('uses inactive for missing active_at', function() {
var conversation = {
it('uses inactive for missing active_at', () => {
const conversation = {
id: 'id',
type: 'private'
type: 'private',
};
var expected = 'inactive (id)';
assert.strictEqual(Signal.Backup._getConversationLoggingName(conversation), expected);
const expected = 'inactive (id)';
assert.strictEqual(
Signal.Backup._getConversationLoggingName(conversation),
expected
);
});
});
});

View file

@ -1,6 +0,0 @@
{
"globals": {
"check": true,
"gen": true
}
}

27
test/modules/.eslintrc.js Normal file
View 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',
}
};

View file

@ -1,3 +1,5 @@
'use strict';
/* global window: false */
// Because we aren't hosting the Style Guide in Electron, we can't rely on preload.js

View file

@ -1,3 +1,5 @@
'use strict';
/* global window: false */
// Taken from background.html.