diff --git a/tests/e2e/admin.test.ts b/tests/e2e/admin.test.ts index 5fa74b88344..bc1ab6f4673 100644 --- a/tests/e2e/admin.test.ts +++ b/tests/e2e/admin.test.ts @@ -17,6 +17,8 @@ test('create a bot and manage its access token', async ({page, request}) => { await page.getByRole('row', {name: /^user /}).getByRole('radio', {name: 'Read', exact: true}).check(); await page.getByRole('button', {name: 'Generate Token'}).click(); const token = await page.getByRole('code').textContent(); + await page.getByRole('button', {name: 'Copy', exact: true}).click(); + await expect.poll(() => page.evaluate(() => navigator.clipboard.readText())).toBe(token); const response = await request.get('/api/v1/user', {headers: {Authorization: `token ${token}`}}); expect(await response.json()).toMatchObject({login: botName, type: 'Bot'}); diff --git a/web_src/js/modules/clipboard.ts b/web_src/js/modules/clipboard.ts index 19a76a32ca7..96fa2ab0f2c 100644 --- a/web_src/js/modules/clipboard.ts +++ b/web_src/js/modules/clipboard.ts @@ -64,7 +64,7 @@ function replaceWithFeedbackSvg(origSvg: SVGElement, success: boolean): () => vo // Enable clipboard copy from HTML attributes. These properties are supported: // - data-clipboard-text: Direct text to copy -// - data-clipboard-target: Holds a selector for an element. "value" of or , or "textContent" of will be copied +// - data-clipboard-target: Holds a selector for an element. "value" of or , or "textContent" of other elements will be copied export function initGlobalCopyToClipboardListener() { document.addEventListener('click', async (e) => { const target = (e.target as HTMLElement).closest('[data-clipboard-text], [data-clipboard-target]'); @@ -78,10 +78,8 @@ export function initGlobalCopyToClipboardListener() { const textTarget = document.querySelector(textSelector)!; if (textTarget.nodeName === 'INPUT' || textTarget.nodeName === 'TEXTAREA') { text = (textTarget as HTMLInputElement | HTMLTextAreaElement).value; - } else if (textTarget.nodeName === 'DIV') { - text = textTarget.textContent; } else { - throw new Error(`Unsupported element for clipboard target: ${textSelector}`); + text = textTarget.textContent; } } // now, text can not be null