diff --git a/app/assets/javascripts/copyToClipboard.js b/app/assets/javascripts/copyToClipboard.js
index 03d5325d4..74dcc207c 100644
--- a/app/assets/javascripts/copyToClipboard.js
+++ b/app/assets/javascripts/copyToClipboard.js
@@ -7,9 +7,7 @@
const states = {
'valueVisible': (options) => `
-
- ${options.valueLabel ? '' + options.thing + ': ' : ''}${options.value}
-
+ ${options.valueLabel ? '' + options.thing + ': ' : ''}${options.value}
${options.onload ? '' : options.thing + ' returned to page, press button to copy to clipboard'}
diff --git a/tests/javascripts/copyToClipboard.test.js b/tests/javascripts/copyToClipboard.test.js
index 3757a7dfd..6511aa6d5 100644
--- a/tests/javascripts/copyToClipboard.test.js
+++ b/tests/javascripts/copyToClipboard.test.js
@@ -25,9 +25,7 @@ describe('copy to clipboard', () => {
${options.thing}
-
- ${(options.name === options.thing) ? '' + options.thing + ': ' : ''}${apiKey}
-
+ ${(options.name === options.thing) ? '' + options.thing + ': ' : ''}${apiKey}
`;
@@ -152,6 +150,12 @@ describe('copy to clipboard', () => {
});
+ test("It should render the 'thing' without extra whitespace", () => {
+
+ expect(component.querySelector('.copy-to-clipboard__value').textContent).toBe('00000000-0000-0000-0000-000000000000');
+
+ });
+
});
describe("If it's one of many in the page", () => {
@@ -344,13 +348,13 @@ describe('copy to clipboard', () => {
});
- test("the copied selection (range) should start after the prefix of the id", () => {
+ test("the copied selection (range) should start after visually hidden prefix", () => {
- // that selection (a range) should have a startOffset past the first two nodes:
- // index 0: text node containing the whitespace before the prefix
- // index 1: the prefix node
+ // that selection (a range) should have a startOffset of 1:
+ // index 0: the visually hidden prefix node, for example "Template ID: " or "API key: "
+ // index 1: the value node
expect(rangeMock.setStart).toHaveBeenCalled();
- expect(rangeMock.setStart.mock.calls[0][1]).toEqual(2);
+ expect(rangeMock.setStart.mock.calls[0][1]).toEqual(1);
// reset any methods in the global space
window.queryCommandSupported = undefined;