|
| 1 | +/** |
| 2 | + * @jest-environment jsdom |
| 3 | + */ |
| 4 | +jest.mock( '@automattic/calypso-config', () => { |
| 5 | + const configApi = () => ''; |
| 6 | + configApi.isEnabled = jest.fn( ( flag ) => flag === 'is_odyssey' ); |
| 7 | + return configApi; |
| 8 | +} ); |
| 9 | + |
| 10 | +jest.mock( 'calypso/state/analytics/actions', () => ( { |
| 11 | + recordTracksEvent: jest.fn( () => ( { type: 'ANALYTICS_EVENT_RECORD' } ) ), |
| 12 | +} ) ); |
| 13 | + |
| 14 | +import { render, screen } from '@testing-library/react'; |
| 15 | +import { Banner } from '../index'; |
| 16 | + |
| 17 | +const props = { |
| 18 | + title: 'banner title', |
| 19 | + siteSlug: 'example.com', |
| 20 | + canUserUpgrade: true, |
| 21 | +}; |
| 22 | + |
| 23 | +describe( 'Banner hrefs in wp-admin (Odyssey)', () => { |
| 24 | + test( 'absolutizes the computed plans href', () => { |
| 25 | + const { container } = render( <Banner { ...props } /> ); |
| 26 | + |
| 27 | + expect( container.querySelector( 'a' ) ).toHaveAttribute( |
| 28 | + 'href', |
| 29 | + 'https://wordpress.com/plans/example.com' |
| 30 | + ); |
| 31 | + } ); |
| 32 | + |
| 33 | + test( 'absolutizes the computed plans href with feature and plan args', () => { |
| 34 | + const { container } = render( |
| 35 | + <Banner { ...props } feature="advanced-seo" plan="business-bundle" /> |
| 36 | + ); |
| 37 | + |
| 38 | + expect( container.querySelector( 'a' ) ).toHaveAttribute( |
| 39 | + 'href', |
| 40 | + 'https://wordpress.com/plans/example.com?feature=advanced-seo&plan=business-bundle' |
| 41 | + ); |
| 42 | + } ); |
| 43 | + |
| 44 | + test( 'absolutizes the computed plans href with a customerType arg', () => { |
| 45 | + const { container } = render( <Banner { ...props } customerType="business" /> ); |
| 46 | + |
| 47 | + expect( container.querySelector( 'a' ) ).toHaveAttribute( |
| 48 | + 'href', |
| 49 | + 'https://wordpress.com/plans/example.com?customerType=business' |
| 50 | + ); |
| 51 | + } ); |
| 52 | + |
| 53 | + test( 'absolutizes a caller-provided href', () => { |
| 54 | + const { container } = render( <Banner { ...props } href="/post/example.com" /> ); |
| 55 | + |
| 56 | + expect( container.querySelector( 'a' ) ).toHaveAttribute( |
| 57 | + 'href', |
| 58 | + 'https://wordpress.com/post/example.com' |
| 59 | + ); |
| 60 | + } ); |
| 61 | + |
| 62 | + test( 'absolutizes the call-to-action button href', () => { |
| 63 | + render( <Banner { ...props } callToAction="Upgrade" forceHref={ false } /> ); |
| 64 | + |
| 65 | + expect( screen.getByRole( 'link', { name: 'Upgrade' } ) ).toHaveAttribute( |
| 66 | + 'href', |
| 67 | + 'https://wordpress.com/plans/example.com' |
| 68 | + ); |
| 69 | + } ); |
| 70 | + |
| 71 | + test( 'absolutizes the secondary call-to-action href', () => { |
| 72 | + render( |
| 73 | + <Banner |
| 74 | + { ...props } |
| 75 | + callToAction="Upgrade" |
| 76 | + secondaryCallToAction="Learn more" |
| 77 | + secondaryHref="/support/example.com" |
| 78 | + /> |
| 79 | + ); |
| 80 | + |
| 81 | + expect( screen.getByRole( 'link', { name: 'Learn more' } ) ).toHaveAttribute( |
| 82 | + 'href', |
| 83 | + 'https://wordpress.com/support/example.com' |
| 84 | + ); |
| 85 | + } ); |
| 86 | + |
| 87 | + test( 'leaves an absolute href untouched', () => { |
| 88 | + const { container } = render( |
| 89 | + <Banner { ...props } href="https://example.com/wp-admin/admin.php?page=stats" /> |
| 90 | + ); |
| 91 | + |
| 92 | + expect( container.querySelector( 'a' ) ).toHaveAttribute( |
| 93 | + 'href', |
| 94 | + 'https://example.com/wp-admin/admin.php?page=stats' |
| 95 | + ); |
| 96 | + } ); |
| 97 | +} ); |
0 commit comments