Commit d53e4c34 authored by Eduardo Sanz García's avatar Eduardo Sanz García Committed by Eduardo

Improved string formatting of the client's version

Reordered fields according to the UI and capitalised properties.
parent 1e202a16
...@@ -79,22 +79,38 @@ describe('sidebar/helpers/version-data', () => { ...@@ -79,22 +79,38 @@ describe('sidebar/helpers/version-data', () => {
}); });
describe('#asFormattedString', () => { describe('#asFormattedString', () => {
['timestamp', 'account', 'url'].forEach(prop => { [
it(`includes a line for the value of ${prop} in the string`, () => { ['Version', 'version'],
['User Agent', 'userAgent'],
['URL', 'url'],
['Fingerprint', 'fingerprint'],
['Account', 'account'],
['Date', 'timestamp'],
].forEach(prop => {
it(`includes a line for the value of ${prop[1]} in the string`, () => {
const versionData = new VersionData({}, {}); const versionData = new VersionData({}, {});
const formatted = versionData.asFormattedString(); const formatted = versionData.asFormattedString();
const subStr = `${prop}: ${versionData[prop]}\r\n`; const subStr = `${prop[0]}: ${versionData[prop[1]]}\n`;
assert.include(formatted, subStr); assert.include(formatted, subStr);
}); });
}); });
}); });
describe('#asEncodedURLString', () => { describe('#asEncodedURLString', () => {
['timestamp', 'account'].forEach(prop => { [
it(`includes encoded value for ${prop} in URL string`, () => { ['Version', 'version'],
['User Agent', 'userAgent'],
['URL', 'url'],
['Fingerprint', 'fingerprint'],
['Account', 'account'],
['Date', 'timestamp'],
].forEach(prop => {
it(`includes encoded value for ${prop[1]} in URL string`, () => {
const versionData = new VersionData({}, {}); const versionData = new VersionData({}, {});
const encoded = versionData.asEncodedURLString(); const encoded = versionData.asEncodedURLString();
const subStr = encodeURIComponent(`${prop}: ${versionData[prop]}\r\n`); const subStr = encodeURIComponent(
`${prop[0]}: ${versionData[prop[1]]}\n`
);
assert.include(encoded, subStr); assert.include(encoded, subStr);
}); });
}); });
......
...@@ -35,15 +35,15 @@ export default class VersionData { ...@@ -35,15 +35,15 @@ export default class VersionData {
} }
} }
this.timestamp = new Date().toString(); this.version = '__VERSION__'; // replaced by versionify
this.userAgent = window_.navigator.userAgent;
this.url = documentInfo.uri || noValueString; this.url = documentInfo.uri || noValueString;
this.fingerprint = this.fingerprint =
docMeta && docMeta.documentFingerprint docMeta && docMeta.documentFingerprint
? docMeta.documentFingerprint ? docMeta.documentFingerprint
: noValueString; : noValueString;
this.account = accountString; this.account = accountString;
this.userAgent = window_.navigator.userAgent; this.timestamp = new Date().toString();
this.version = '__VERSION__';
} }
/** /**
...@@ -53,13 +53,13 @@ export default class VersionData { ...@@ -53,13 +53,13 @@ export default class VersionData {
* @return {string} - Single, multiline string representing current version data * @return {string} - Single, multiline string representing current version data
*/ */
asFormattedString() { asFormattedString() {
let versionString = ''; return `Version: ${this.version}
for (let prop in this) { User Agent: ${this.userAgent}
if (Object.prototype.hasOwnProperty.call(this, prop)) { URL: ${this.url}
versionString += `${prop}: ${this[prop]}\r\n`; Fingerprint: ${this.fingerprint}
} Account: ${this.account}
} Date: ${this.timestamp}
return versionString; `;
} }
/** /**
......
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