2018-03-07 13:31:17 -08:00
|
|
|
import { encode, decode } from 'wherehows-web/utils/encode-decode-uri-component-with-space';
|
|
|
|
import { module, test } from 'qunit';
|
|
|
|
|
2018-08-09 23:25:55 -07:00
|
|
|
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-_.!~*'()";
|
2018-03-07 13:31:17 -08:00
|
|
|
|
2018-08-09 23:25:55 -07:00
|
|
|
test('encode function', function(assert) {
|
|
|
|
let result = encode(unEncodedAlphaNumericWithSpace);
|
2018-03-07 13:31:17 -08:00
|
|
|
|
2018-08-09 23:25:55 -07:00
|
|
|
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');
|
2018-03-07 13:31:17 -08:00
|
|
|
|
2018-08-09 23:25:55 -07:00
|
|
|
result = encode(reservedChars);
|
|
|
|
assert.equal(reservedChars, result, 'reserved characters should be untouched');
|
|
|
|
});
|
2018-03-07 13:31:17 -08:00
|
|
|
|
2018-08-09 23:25:55 -07:00
|
|
|
test('decode function', function(assert) {
|
|
|
|
let result = decode(decodedAlphaNumericWithSpace);
|
2018-03-07 13:31:17 -08:00
|
|
|
|
2018-08-09 23:25:55 -07:00
|
|
|
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');
|
|
|
|
});
|
2018-03-07 13:31:17 -08:00
|
|
|
});
|