Download wp-calypso/client/reader/test/utils.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.61 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/wp-calypso/client/reader/test/utils.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/wp-calypso/client/reader/test/utils.ts
-
curl -L -o utils.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/wp-calypso/client/reader/test/utils.ts
1.61 kB
| import page from '@automattic/calypso-router'; | |
| import { AppState } from 'calypso/types'; | |
| import { getSafeImageUrlForReader, showSelectedPost } from '../utils'; | |
| jest.mock( '@automattic/calypso-router', () => jest.fn() ); | |
| describe( 'reader utils', () => { | |
| const dispatch = jest.fn(); | |
| const getState = () => | |
| ( { | |
| reader: { | |
| posts: { | |
| items: {}, | |
| }, | |
| }, | |
| } ) as AppState; | |
| beforeEach( () => { | |
| jest.resetAllMocks(); | |
| } ); | |
| describe( '#showSelectedPost', () => { | |
| test( 'does not do anything if postKey argument is missing', () => { | |
| showSelectedPost( {} )( dispatch, getState ); | |
| expect( page ).not.toHaveBeenCalled(); | |
| } ); | |
| test( 'redirects if passed a post key', () => { | |
| showSelectedPost( { postKey: { feedId: 1, postId: 5 } } )( dispatch, getState ); | |
| expect( page ).toHaveBeenCalledTimes( 1 ); | |
| } ); | |
| test( 'redirects to a #comments URL if we passed comments argument', () => { | |
| showSelectedPost( { postKey: { feedId: 1, postId: 5 }, comments: true } )( | |
| dispatch, | |
| getState | |
| ); | |
| expect( page as ( url: string ) => void ).toHaveBeenCalledWith( | |
| '/reader/feeds/1/posts/5#comments' | |
| ); // | |
| } ); | |
| } ); | |
| describe( 'getSafeImageUrlForReader', () => { | |
| test( 'returns the url as is if it is from a trusted host', () => { | |
| const url = 'https://www.redditstatic.com/image.jpg'; | |
| expect( getSafeImageUrlForReader( url ) ).toEqual( url ); | |
| } ); | |
| test( 'returns the Photon url if it is not from a trusted host', () => { | |
| const url = 'https://www.example.com/image.jpg'; | |
| expect( getSafeImageUrlForReader( url ) ).not.toEqual( url ); | |
| } ); | |
| } ); | |
| } ); | |