Commit 26f25696 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner

Separate `asFormattedString` and `asEncodedURLString`

Separate `asEncodedURLString` into two constituent methods, allowing
access to an un-encoded `asFormattedString`, which returns a string
formatted for (e.g.) copying to the clipboard.
parent ee714018
...@@ -80,6 +80,17 @@ describe('VersionData', () => { ...@@ -80,6 +80,17 @@ describe('VersionData', () => {
}); });
}); });
describe('#asFormattedString', () => {
['timestamp', 'account', 'url'].forEach(prop => {
it(`includes a line for the value of ${prop} in the string`, () => {
const versionData = new VersionData({}, {});
const formatted = versionData.asFormattedString();
const subStr = `${prop}: ${versionData[prop]}\r\n`;
assert.include(formatted, subStr);
});
});
});
describe('#asEncodedURLString', () => { describe('#asEncodedURLString', () => {
['timestamp', 'account'].forEach(prop => { ['timestamp', 'account'].forEach(prop => {
it(`includes encoded value for ${prop} in URL string`, () => { it(`includes encoded value for ${prop} in URL string`, () => {
......
...@@ -55,19 +55,29 @@ class VersionData { ...@@ -55,19 +55,29 @@ class VersionData {
} }
/** /**
* Return a single, encoded URL string of version data suitable for use in * Return a single formatted string representing version data, suitable for
* a querystring (as the value of a single parameter) * copying to the clipboard.
* *
* @return {string} - URI-encoded string * @return {string} - Single, multiline string representing current version data
*/ */
asEncodedURLString() { asFormattedString() {
let versionString = ''; let versionString = '';
for (let prop in this) { for (let prop in this) {
if (Object.prototype.hasOwnProperty.call(this, prop)) { if (Object.prototype.hasOwnProperty.call(this, prop)) {
versionString += `${prop}: ${this[prop]}\r\n`; versionString += `${prop}: ${this[prop]}\r\n`;
} }
} }
return encodeURIComponent(versionString); return versionString;
}
/**
* Return a single, encoded URL string of version data suitable for use in
* a querystring (as the value of a single parameter)
*
* @return {string} - URI-encoded string
*/
asEncodedURLString() {
return encodeURIComponent(this.asFormattedString());
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment