Skip to content

Commit

Permalink
Fixing test so it uses an epoch time instead of month/date as that de…
Browse files Browse the repository at this point in the history
…pends on timezone where tests are run.
  • Loading branch information
jamesmortensen committed Sep 23, 2022
1 parent 24fc9ce commit d998e28
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions test/filename-generator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,41 @@ describe('Filename Generator Tests', () => {
const generateFilename = require('../src/filename-generator.js');

it('should generate a filename with date 23 Sep if title is empty string', () => {
const filename = generateFilename('', new Date('Sep 23, 2022').getTime());
const filename = generateFilename('', new Date(1663871400000).getTime());
expect(filename).to.equal('untitled-1663871400000');
});

it('should generate a filename with date 23 Sep if title is null', () => {
const filename = generateFilename(null, new Date('Sep 23, 2022').getTime());
const filename = generateFilename(null, new Date(1663871400000).getTime());
expect(filename).to.equal('untitled-1663871400000');
});

it('should generate a filename with date 23 Sep if title is undefined', () => {
const filename = generateFilename(undefined, new Date('Sep 23, 2022').getTime());
const filename = generateFilename(undefined, new Date(1663871400000).getTime());
expect(filename).to.equal('untitled-1663871400000');
});

it('should generate a filename with a simple string and in lowercase', () => {
const filename = generateFilename('Abcdefg', new Date('Sep 23, 2022').getTime());
const filename = generateFilename('Abcdefg', new Date(1663871400000).getTime());
expect(filename).to.equal('abcdefg');
});

it('should generate a filename but cutoff at 170 chars and make it lowercase', () => {
const chars175 = 'AbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxyAbcdefghijklmnopqrstuvwxy';
const chars170 = 'abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrst';
const filename = generateFilename(chars175, new Date('Sep 23, 2022').getTime());
const filename = generateFilename(chars175, new Date(1663871400000).getTime());
expect(filename).to.equal(chars170);
});

it('should generate a filename when title contains a simple url', () => {
const filename = generateFilename('https://example.com/this-is-a-url', new Date('Sep 23, 2022').getTime());
const filename = generateFilename('https://example.com/this-is-a-url', new Date(1663871400000).getTime());
console.log(filename)
expect(filename).to.equal('https---example.com--this-is-a-url');
});

// filenames actually can't contain & and hashes.
xit('should generate a filename when title contains a url with query parameters', () => {
const filename = generateFilename('https://example.com/this-is-a-url?with=query&strings=and#hash', new Date('Sep 23, 2022').getTime());
const filename = generateFilename('https://example.com/this-is-a-url?with=query&strings=and#hash', new Date(1663871400000).getTime());
console.log(filename)
expect(filename).to.equal('https---example.com--this-is-a-url?with--eq--query--amp--strings--eq--and--hash--hash');
});
Expand Down

0 comments on commit d998e28

Please sign in to comment.