2017-05-07 09:49:15 +02:00
|
|
|
|
import sanitizeFilenameLib from 'sanitize-filename';
|
|
|
|
|
import sanitizeFilename from './sanitizeFilename';
|
2018-07-21 15:16:02 +02:00
|
|
|
|
import { DEFAULT_APP_NAME } from '../constants';
|
2017-05-07 09:49:15 +02:00
|
|
|
|
|
|
|
|
|
jest.mock('sanitize-filename');
|
2018-05-24 09:02:44 +02:00
|
|
|
|
sanitizeFilenameLib.mockImplementation((str) => str);
|
2017-05-07 09:49:15 +02:00
|
|
|
|
|
|
|
|
|
test('it should call the sanitize-filename npm module', () => {
|
|
|
|
|
const param = 'abc';
|
|
|
|
|
sanitizeFilename('', param);
|
|
|
|
|
expect(sanitizeFilenameLib).toHaveBeenCalledWith(param);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('replacing non ascii characters', () => {
|
|
|
|
|
const nonAscii = '<27>';
|
2018-05-25 07:24:09 +02:00
|
|
|
|
test('it should return a result without non ascii characters', () => {
|
2017-05-07 09:49:15 +02:00
|
|
|
|
const param = `${nonAscii}abc`;
|
|
|
|
|
const expectedResult = 'abc';
|
|
|
|
|
const result = sanitizeFilename('', param);
|
|
|
|
|
expect(result).toBe(expectedResult);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('when the result of replacing these characters is empty', () => {
|
|
|
|
|
const result = sanitizeFilename('', nonAscii);
|
|
|
|
|
expect(result).toBe(DEFAULT_APP_NAME);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('when the platform is linux', () => {
|
|
|
|
|
test('it should return a kebab cased name', () => {
|
|
|
|
|
const param = 'some name';
|
|
|
|
|
const expectedResult = 'some-name';
|
|
|
|
|
const result = sanitizeFilename('linux', param);
|
|
|
|
|
expect(result).toBe(expectedResult);
|
|
|
|
|
});
|
|
|
|
|
});
|