1+ import React from 'react'
2+ import { render , act } from '@testing-library/react'
3+ import '@testing-library/jest-dom/extend-expect'
4+
5+ import { mockViewport } from '../../../src/mocks/viewport'
6+
7+ import Component from './Component'
8+
9+ const VIEWPORT_DESKTOP = { width : "1440px" , height : "900px" }
10+ const VIEWPORT_MOBILE = { width : "320px" , height : "568px" }
11+
12+ describe ( 'It renders correctly on server, desktop and mobile' , ( ) => {
13+ it ( 'works on the server' , ( ) => {
14+ const { getByText } = render ( < Component /> )
15+
16+ expect ( getByText ( 'server' ) ) . toBeInTheDocument ( ) ;
17+ } )
18+
19+ it ( 'works on desktop' , ( ) => {
20+ const viewport = mockViewport ( VIEWPORT_DESKTOP )
21+
22+ const { getByText } = render ( < Component /> ) ;
23+
24+ expect ( getByText ( 'desktop' ) ) . toBeInTheDocument ( ) ;
25+
26+ viewport . cleanup ( )
27+ } )
28+
29+ it ( 'works on mobile' , ( ) => {
30+ const viewport = mockViewport ( VIEWPORT_MOBILE )
31+
32+ const { getByText } = render ( < Component /> ) ;
33+
34+ expect ( getByText ( 'not desktop' ) ) . toBeInTheDocument ( ) ;
35+
36+ viewport . cleanup ( )
37+ } ) ;
38+
39+ it ( 'works on desktop and mobile, even if we change the viewport description' , ( ) => {
40+ const viewport = mockViewport ( VIEWPORT_DESKTOP )
41+
42+ const { getByText, queryByText } = render ( < Component /> )
43+
44+ expect ( getByText ( 'desktop' ) ) . toBeInTheDocument ( )
45+ expect ( queryByText ( 'not desktop' ) ) . not . toBeInTheDocument ( )
46+
47+ act ( ( ) => {
48+ viewport . set ( VIEWPORT_MOBILE )
49+ } )
50+
51+ expect ( getByText ( 'not desktop' ) ) . toBeInTheDocument ( )
52+ expect ( queryByText ( 'desktop' ) ) . not . toBeInTheDocument ( )
53+
54+ viewport . cleanup ( )
55+ } )
56+ } )
0 commit comments