Convert remaining main process tests to TypeScript

This commit is contained in:
Evan Hahn 2022-01-11 19:10:35 -06:00 committed by GitHub
parent 8f2c663a12
commit a5a73e869c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 33 deletions

View file

@ -0,0 +1,112 @@
// Copyright 2018-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import { _urlToPath } from '../../../app/protocol_filter';
describe('Protocol Filter', () => {
describe('_urlToPath', () => {
it('returns proper file path for unix style file URI with hash', () => {
const path =
'file:///Users/someone/Development/signal/electron/background.html#first-page';
const expected =
'/Users/someone/Development/signal/electron/background.html';
const actual = _urlToPath(path);
assert.strictEqual(actual, expected);
});
it('returns proper file path for unix style file URI with querystring', () => {
const path =
'file:///Users/someone/Development/signal/electron/background.html?name=Signal&locale=en&version=2.4.0';
const expected =
'/Users/someone/Development/signal/electron/background.html';
const actual = _urlToPath(path);
assert.strictEqual(actual, expected);
});
it('returns proper file path for unix style file URI with hash and querystring', () => {
const path =
'file:///Users/someone/Development/signal/electron/background.html#somewhere?name=Signal';
const expected =
'/Users/someone/Development/signal/electron/background.html';
const actual = _urlToPath(path);
assert.strictEqual(actual, expected);
});
it('returns proper file path for file URI on windows', () => {
const path =
'file:///C:/Users/Someone/dev/desktop/background.html?name=Signal&locale=en&version=2.4.0';
const expected = 'C:/Users/Someone/dev/desktop/background.html';
const isWindows = true;
const actual = _urlToPath(path, { isWindows });
assert.strictEqual(actual, expected);
});
it('translates from URL format to filesystem format', () => {
const path =
'file:///Users/someone/Development%20Files/signal/electron/background.html';
const expected =
'/Users/someone/Development Files/signal/electron/background.html';
const actual = _urlToPath(path);
assert.strictEqual(actual, expected);
});
it('translates from URL format to filesystem format', () => {
const path =
'file:///Users/someone/Development%20Files/signal/electron/background.html';
const expected =
'/Users/someone/Development Files/signal/electron/background.html';
const actual = _urlToPath(path);
assert.strictEqual(actual, expected);
});
it('handles UNC path', () => {
const path = '//share/path';
const expected = '//share/path';
const actual = _urlToPath(path);
assert.strictEqual(actual, expected);
});
it('handles UNC path on windows', () => {
const path = '//share/path';
const expected = '//share/path';
const isWindows = true;
const actual = _urlToPath(path, { isWindows });
assert.strictEqual(actual, expected);
});
it('handles simple relative path', () => {
const path = 'file://relative/path';
const expected = 'relative/path';
const actual = _urlToPath(path);
assert.strictEqual(actual, expected);
});
it('handles simple relative path on Windows', () => {
const path = 'file://relative/path';
const expected = 'elative/path';
const isWindows = true;
const actual = _urlToPath(path, { isWindows });
assert.strictEqual(actual, expected);
});
it('hands back a path with .. in it', () => {
const path = 'file://../../..';
const expected = '../../..';
const actual = _urlToPath(path);
assert.strictEqual(actual, expected);
});
});
});

View file

@ -0,0 +1,43 @@
// Copyright 2020-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import { getLanguages } from '../../../app/spell_check';
describe('SpellCheck', () => {
describe('getLanguages', () => {
it('works with locale and base available', () => {
assert.deepEqual(getLanguages('en-US', ['en-US', 'en-CA', 'en']), [
'en-US',
'en',
]);
});
it('works with neither locale nor base available', () => {
assert.deepEqual(getLanguages('en-US', ['en-NZ', 'en-CA']), [
'en-NZ',
'en-CA',
]);
});
it('works with only base locale available', () => {
assert.deepEqual(getLanguages('en-US', ['en', 'en-CA']), ['en']);
});
it('works with only full locale available', () => {
assert.deepEqual(getLanguages('en-US', ['en-CA', 'en-US']), ['en-US']);
});
it('works with base provided and base available', () => {
assert.deepEqual(getLanguages('en', ['en-CA', 'en-US', 'en']), ['en']);
});
it('works with base provided and base not available', () => {
assert.deepEqual(getLanguages('en', ['en-CA', 'en-US']), [
'en-CA',
'en-US',
]);
});
});
});