mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-01 20:59:45 +09:00
fix: copy new access token to clipboard (#39496)
Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
@@ -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'});
|
||||
|
||||
|
||||
@@ -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 <input> or <textarea>, or "textContent" of <div> will be copied
|
||||
// - data-clipboard-target: Holds a selector for an element. "value" of <input> or <textarea>, or "textContent" of other elements will be copied
|
||||
export function initGlobalCopyToClipboardListener() {
|
||||
document.addEventListener('click', async (e) => {
|
||||
const target = (e.target as HTMLElement).closest<HTMLElement>('[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
|
||||
|
||||
Reference in New Issue
Block a user