-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathindex.jsx
More file actions
52 lines (44 loc) · 1.68 KB
/
Copy pathindex.jsx
File metadata and controls
52 lines (44 loc) · 1.68 KB
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
44
45
46
47
48
49
50
51
52
/**
* @jest-environment jsdom
*/
import { render } from '@testing-library/react';
import Head from '../';
const restProxyHref = 'https://public-api.wordpress.com/wp-admin/rest-proxy/?v=2.0';
describe( 'Head', () => {
test( 'should render default title', () => {
render( <Head /> );
// React 18 renders `<title>` in the container; React 19 hoists it into
// the document head. Query the document for the `<title>` element so this
// works under both versions.
expect( document.querySelector( 'title' )?.textContent ).toBe( 'WordPress.com' );
} );
test( 'should render custom title', () => {
const title = 'Arbitrary Custom Title';
render( <Head title={ title } /> );
expect( document.querySelector( 'title' )?.textContent ).toBe( title );
} );
test( 'should prefetch the REST proxy by default', () => {
render( <Head /> );
expect(
document.querySelector( `link[rel="prefetch"][href="${ restProxyHref }"]` )
).toBeTruthy();
} );
test( 'should skip the REST proxy prefetch when disabled', () => {
render( <Head shouldPrefetchRestProxy={ false } /> );
expect(
document.querySelector( `link[rel="prefetch"][href="${ restProxyHref }"]` )
).toBeNull();
} );
test( 'should block zoom via maximum-scale by default', () => {
render( <Head /> );
expect( document.querySelector( 'meta[name="viewport"]' )?.getAttribute( 'content' ) ).toBe(
'width=device-width, initial-scale=1, maximum-scale=1'
);
} );
test( 'should allow zoom by dropping maximum-scale when allowZoom is set', () => {
render( <Head allowZoom /> );
expect( document.querySelector( 'meta[name="viewport"]' )?.getAttribute( 'content' ) ).toBe(
'width=device-width, initial-scale=1'
);
} );
} );