File size: 1,514 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
/**
* @jest-environment jsdom
*/
// @ts-nocheck - TODO: Fix TypeScript issues
import { screen } from '@testing-library/react';
import React from 'react';
import { renderWithProvider } from 'calypso/test-helpers/testing-library';
import SidebarItem from '../item';
const render = ( el ) => renderWithProvider( el );
test( 'external links open in a new tab', () => {
// Don't test external links using the traditional "example.com" domain, because that's the domain
// Testing Library uses as the default window.location, so they don't appear to be external.
render( <SidebarItem label="My Example" link="https://my-example.com" /> );
expect( screen.getByRole( 'link', { name: 'My Example' } ) ).toHaveAttribute(
'target',
'_blank'
);
} );
test( 'external links can be forced to open in the same tab', () => {
render( <SidebarItem label="My Example" link="https://my-example.com" forceInternalLink /> );
expect( screen.getByRole( 'link', { name: 'My Example' } ) ).not.toHaveAttribute(
'target',
'_blank'
);
} );
test( 'internal links open in a the same tab', () => {
render( <SidebarItem label="Home" link="/home/example.com" /> );
expect( screen.getByRole( 'link', { name: 'Home' } ) ).not.toHaveAttribute( 'target', '_blank' );
} );
test( 'internal links can be forced to open in a new tab', () => {
render( <SidebarItem label="Home" link="/home/example.com" forceExternalLink /> );
expect( screen.getByRole( 'link', { name: 'Home' } ) ).toHaveAttribute( 'target', '_blank' );
} );
|