url format tests

This commit is contained in:
antelle 2020-03-21 12:08:27 +01:00
parent b96b477f65
commit c6c307c50c
2 changed files with 36 additions and 1 deletions

View File

@ -1,6 +1,6 @@
const UrlFormat = {
multiSlashRegex: /\/{2,}/g,
lastPartRegex: /\/?[^\/\\]+$/,
lastPartRegex: /[\/\\]?[^\/\\]+$/,
kdbxEndRegex: /\.kdbx$/i,
getDataFileName(url) {

View File

@ -0,0 +1,35 @@
import { expect } from 'chai';
import { UrlFormat } from 'util/formatting/url-format';
describe('UrlFormat', () => {
it('should extract file name from url', () => {
expect(UrlFormat.getDataFileName('https://example.com/data/My.file.kDBx?x=1')).to.eql(
'My.file'
);
});
it('should determine if url represents a kdbx file', () => {
expect(UrlFormat.isKdbx('//data/file.KdBx')).to.be.true;
expect(UrlFormat.isKdbx('//data/file.kdb')).to.be.false;
expect(UrlFormat.isKdbx('//data/file.kdbxx')).to.be.false;
});
it('should replace multiple slashes', () => {
expect(UrlFormat.fixSlashes('//data/file//ext')).to.eql('/data/file/ext');
});
it('should get directory url by full url', () => {
expect(UrlFormat.fileToDir('/var/data/My.file.kdbx')).to.eql('/var/data');
expect(UrlFormat.fileToDir('\\\\share\\data\\My.file.kdbx')).to.eql('\\\\share\\data');
expect(UrlFormat.fileToDir('My.file.kdbx')).to.eql('/');
});
it('should make url from parts', () => {
expect(
UrlFormat.makeUrl('/path', {
hello: 'world',
data: '= &'
})
).to.eql('/path?hello=world&data=%3D%20%26');
});
});