mirror of
https://github.com/datahub-project/datahub.git
synced 2025-07-23 09:32:04 +00:00
28 lines
1.2 KiB
JavaScript
28 lines
1.2 KiB
JavaScript
import { encode, decode } from 'wherehows-web/utils/encode-decode-uri-component-with-space';
|
|
import { module, test } from 'qunit';
|
|
|
|
module('Unit | Utility | encode decode uri component with space', function() {
|
|
const unEncodedAlphaNumericWithSpace = 'ABC 123 with space';
|
|
const decodedAlphaNumericWithSpace = 'ABC+123+with+space';
|
|
const reservedChars = "Aa0-_.!~*'()";
|
|
|
|
test('encode function', function(assert) {
|
|
let result = encode(unEncodedAlphaNumericWithSpace);
|
|
|
|
assert.ok(typeof result === 'string', 'encode returns a value');
|
|
assert.notOk(/%20/.test(result), 'result does not contain %20 replacement for space');
|
|
assert.equal(result, decodedAlphaNumericWithSpace, 'result is encoded as expected');
|
|
|
|
result = encode(reservedChars);
|
|
assert.equal(reservedChars, result, 'reserved characters should be untouched');
|
|
});
|
|
|
|
test('decode function', function(assert) {
|
|
let result = decode(decodedAlphaNumericWithSpace);
|
|
|
|
assert.ok(typeof result === 'string', 'encode returns a value');
|
|
assert.notOk(/\+/.test(result), 'result does not contain + replacement for space');
|
|
assert.equal(result, unEncodedAlphaNumericWithSpace, 'result is decoded as expected');
|
|
});
|
|
});
|