@@ -1534,3 +1534,38 @@ test.describe('Non-child page resolution', () => {
15341534 // The detailed sidebar filtering is tested by the survey test which verifies no duplicate entries
15351535 } )
15361536} )
1537+
1538+ test . describe ( 'copy as markdown button' , ( ) => {
1539+ // The article-body fetch backing this button is served for this fixture page
1540+ // (see src/fixtures/tests/api-article-body.ts), so the copy path succeeds.
1541+ const articlePath = '/en/get-started/start-your-journey/api-article-body-test-page'
1542+
1543+ test ( 'swaps the copy icon for a checkmark after a successful copy' , async ( { page, context } ) => {
1544+ // The click handler writes the article markdown to the clipboard.
1545+ await context . grantPermissions ( [ 'clipboard-read' , 'clipboard-write' ] )
1546+
1547+ await page . goto ( articlePath )
1548+ await turnOffExperimentsInPage ( page )
1549+
1550+ const copyButton = page . getByRole ( 'button' , { name : 'Copy as Markdown' } )
1551+ await expect ( copyButton ) . toBeVisible ( )
1552+
1553+ // Before clicking, the leading icon is the copy icon, not the checkmark.
1554+ await expect ( copyButton . locator ( '.octicon-copy' ) ) . toBeVisible ( )
1555+ await expect ( copyButton . locator ( '.octicon-check' ) ) . toHaveCount ( 0 )
1556+
1557+ await copyButton . click ( )
1558+
1559+ // After a successful copy, the icon swaps to a checkmark...
1560+ await expect ( copyButton . locator ( '.octicon-check' ) ) . toBeVisible ( )
1561+ await expect ( copyButton . locator ( '.octicon-copy' ) ) . toHaveCount ( 0 )
1562+
1563+ // ...and the article markdown lands on the clipboard.
1564+ const clipboardText = await page . evaluate ( ( ) => navigator . clipboard . readText ( ) )
1565+ expect ( clipboardText ) . toContain ( 'About GitHub' )
1566+
1567+ // The checkmark is temporary and reverts to the copy icon (2s timeout).
1568+ await expect ( copyButton . locator ( '.octicon-copy' ) ) . toBeVisible ( { timeout : 5000 } )
1569+ await expect ( copyButton . locator ( '.octicon-check' ) ) . toHaveCount ( 0 )
1570+ } )
1571+ } )
0 commit comments