Skip to content

Commit a8447ba

Browse files
authored
Update demo sites to open link in browser instead of copying the link (#790)
* Replace copy demo link with open in browser * Add test to check the button click
1 parent 57777d3 commit a8447ba

2 files changed

Lines changed: 36 additions & 8 deletions

File tree

‎src/components/content-tab-snapshots.tsx‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import { useSnapshots } from '../hooks/use-snapshots';
1515
import { useUpdateDemoSite } from '../hooks/use-update-demo-site';
1616
import { cx } from '../lib/cx';
1717
import { getIpcApi } from '../lib/get-ipc-api';
18+
import { ArrowIcon } from './arrow-icon';
1819
import { Badge } from './badge';
1920
import Button from './button';
20-
import { CopyTextButton } from './copy-text-button';
2121
import offlineIcon from './offline-icon';
2222
import ProgressBar from './progress-bar';
2323
import { ScreenshotDemoSite } from './screenshot-demo-site';
@@ -189,13 +189,16 @@ function SnapshotRow( {
189189
</div>
190190
<Badge>{ __( 'Demo site' ) }</Badge>
191191
</div>
192-
<CopyTextButton
193-
text={ urlWithHTTPS }
194-
label={ `${ urlWithHTTPS }, ${ __( 'Copy site url to clipboard' ) }` }
195-
copyConfirmation={ __( 'Copied!' ) }
192+
<Button
193+
variant="link"
194+
className="!text-a8c-gray-70 hover:!text-a8c-blueberry max-w-[100%]"
195+
onClick={ () => {
196+
getIpcApi().openURL( urlWithHTTPS );
197+
} }
196198
>
197-
{ urlWithHTTPS }
198-
</CopyTextButton>
199+
<span className="truncate">{ urlWithHTTPS }</span>
200+
<ArrowIcon />
201+
</Button>
199202
<div className="mt-2 text-a8c-gray-70 whitespace-nowrap overflow-hidden truncate flex-1">
200203
{ sprintf( __( 'Expires in %s' ), countDown ) }
201204
</div>

‎src/components/tests/content-tab-snapshots.test.tsx‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ const archiveSite = jest.fn();
3030
jest.mock( '../../hooks/use-archive-site' );
3131

3232
const mockShowMessageBox = jest.fn();
33+
const mockOpenURL = jest.fn();
3334
jest.mock( '../../lib/get-ipc-api', () => ( {
3435
getIpcApi: () => ( {
35-
openURL: jest.fn(),
36+
openURL: mockOpenURL,
3637
generateProposedSitePath: jest.fn(),
3738
showMessageBox: mockShowMessageBox,
3839
} ),
@@ -432,6 +433,30 @@ describe( 'ContentTabSnapshots', () => {
432433
expect( clearSnapshotsButton ).not.toBeInTheDocument();
433434
} );
434435
} );
436+
437+
test( 'clicking the demo site URL opens the browser', async () => {
438+
const user = userEvent.setup();
439+
( useSnapshots as jest.Mock ).mockReturnValue( {
440+
snapshots: [
441+
{
442+
url: 'fake-site.fake',
443+
atomicSiteId: 150,
444+
localSiteId: 'site-id-1',
445+
date: new Date().getTime(),
446+
deleted: false,
447+
},
448+
],
449+
fetchSnapshotUsage: jest.fn(),
450+
} );
451+
452+
render( <ContentTabSnapshots selectedSite={ selectedSite } /> );
453+
454+
const urlButton = screen.getByRole( 'button', { name: 'https://fake-site.fake ↗' } );
455+
expect( urlButton ).toBeVisible();
456+
await user.click( urlButton );
457+
458+
expect( mockOpenURL ).toHaveBeenCalledWith( 'https://fake-site.fake' );
459+
} );
435460
} );
436461

437462
describe( 'AddDemoSiteWithProgress', () => {

0 commit comments

Comments
 (0)