mirror of
https://github.com/remoteintech/remote-jobs
synced 2024-12-27 12:53:09 +00:00
2682009c9f
* A few minor tweaks * Add toIdentifierCase function * Use toIdentifierCase function to make profile content more code-friendly * Improve "incomplete profile" indicator checks In order to properly check the "incomplete profile" indicators, the "Company blurb" section should exist. * Return parsed HTML content for each company * Test parsing of invisible "variation selector" character * Strip out invisible "variation selector" character
134 lines
3.2 KiB
JavaScript
134 lines
3.2 KiB
JavaScript
const { assert } = require( 'chai' );
|
|
|
|
const {
|
|
companyNameToProfileFilename,
|
|
jsonStringifyUnicodeEscaped,
|
|
toIdentifierCase,
|
|
stripExtraChars,
|
|
} = require( '../lib' );
|
|
|
|
describe( 'companyNameToProfileFilename function', () => {
|
|
it( 'should lowercase and convert spaces to dashes', () => {
|
|
assert.strictEqual(
|
|
companyNameToProfileFilename( 'My Company-Name' ),
|
|
'my-company-name'
|
|
);
|
|
} );
|
|
|
|
it( 'should expand ampersands', () => {
|
|
assert.strictEqual(
|
|
companyNameToProfileFilename( '&text&stuff&' ),
|
|
'and-text-and-stuff-and'
|
|
);
|
|
} );
|
|
|
|
it( 'should remove apostrophes', () => {
|
|
assert.strictEqual(
|
|
companyNameToProfileFilename( 'Let\'s Encrypt' ),
|
|
'lets-encrypt'
|
|
);
|
|
} );
|
|
|
|
it( 'should lowercase and strip non-alphanumeric characters', () => {
|
|
assert.strictEqual(
|
|
companyNameToProfileFilename( 'My@123 *Markdown* _Company@Name_' ),
|
|
'my-123-markdown-company-name'
|
|
);
|
|
} );
|
|
|
|
it( 'should trim leading and trailing whitespace etc', () => {
|
|
assert.strictEqual(
|
|
companyNameToProfileFilename( ' My WEIRD company name \'$$$$' ),
|
|
'my-weird-company-name'
|
|
);
|
|
} );
|
|
} );
|
|
|
|
describe( 'jsonStringifyUnicodeEscaped function', () => {
|
|
it( 'should equal JSON.stringify for non-Unicode-expanded inputs', () => {
|
|
assert.strictEqual(
|
|
jsonStringifyUnicodeEscaped( 'abc def' ),
|
|
'"abc def"'
|
|
);
|
|
assert.strictEqual(
|
|
jsonStringifyUnicodeEscaped( '\'\\"\nabc\ndef@#$\'' ),
|
|
'"\'\\\\\\"\\nabc\\ndef@#$\'"'
|
|
);
|
|
} );
|
|
|
|
it( 'should escape Unicode-expanded characters', () => {
|
|
assert.strictEqual(
|
|
jsonStringifyUnicodeEscaped( '\u26a0\ufe0f*' ),
|
|
'"\\u26a0\\ufe0f*"'
|
|
);
|
|
assert.strictEqual(
|
|
jsonStringifyUnicodeEscaped( '\u26a0 Emoji \u26a0\ufe0f and\nother \\text' ),
|
|
'"\\u26a0 Emoji \\u26a0\\ufe0f and\\nother \\\\text"'
|
|
);
|
|
} );
|
|
} );
|
|
|
|
describe( 'toIdentifierCase function', () => {
|
|
it( 'should convert all valid headings to the correct identifiers', () => {
|
|
assert.strictEqual(
|
|
toIdentifierCase( 'Company blurb' ),
|
|
'companyBlurb'
|
|
);
|
|
assert.strictEqual(
|
|
toIdentifierCase( 'Company size' ),
|
|
'companySize'
|
|
);
|
|
assert.strictEqual(
|
|
toIdentifierCase( 'Remote status' ),
|
|
'remoteStatus'
|
|
);
|
|
assert.strictEqual(
|
|
toIdentifierCase( 'Region' ),
|
|
'region'
|
|
);
|
|
assert.strictEqual(
|
|
toIdentifierCase( 'Company technologies' ),
|
|
'companyTechnologies'
|
|
);
|
|
assert.strictEqual(
|
|
toIdentifierCase( 'Office locations' ),
|
|
'officeLocations'
|
|
);
|
|
assert.strictEqual(
|
|
toIdentifierCase( 'How to apply' ),
|
|
'howToApply'
|
|
);
|
|
} );
|
|
|
|
it( 'should behave reasonably for other input values', () => {
|
|
assert.strictEqual(
|
|
toIdentifierCase( ' With Whitespace ' ),
|
|
'withWhitespace'
|
|
);
|
|
assert.strictEqual(
|
|
toIdentifierCase( 'with <extra> chars 123.' ),
|
|
'withExtraChars123'
|
|
);
|
|
assert.strictEqual(
|
|
toIdentifierCase( 'Let\'s Encrypt' ),
|
|
'letsEncrypt'
|
|
);
|
|
} );
|
|
} );
|
|
|
|
describe( 'stripExtraChars function', () => {
|
|
it( 'should strip unwanted invisible characters', () => {
|
|
assert.strictEqual(
|
|
stripExtraChars( 'abc\ufe0f def' ),
|
|
'abc def'
|
|
);
|
|
assert.strictEqual(
|
|
stripExtraChars( '\u26a0\ufe0f' ),
|
|
'\u26a0'
|
|
);
|
|
assert.strictEqual(
|
|
stripExtraChars( '\u26a0\ufe0f\ufe0f \u26a0\ufe0f\ufe0f' ),
|
|
'\u26a0 \u26a0'
|
|
);
|
|
} );
|
|
} );
|