describe( '#canBeTranslated', () => { test( 'should return true by default', () => { expect( canBeTranslated() ).toEqual( true ); } ); test( 'should return false for elements in the exception list', () => { expect( canBeTranslated( 'en' ) ).toEqual( false ); expect( canBeTranslated( 'sr_latin' ) ).toEqual( false ); } ); test( 'should return true for languages not in the exception list', () => { expect( canBeTranslated( 'de' ) ).toEqual( true ); } ); } );
test( 'should not change URL for `en`', () => { [ 'https://wordpress.com/', 'https://de.wordpress.com/', 'https://wordpress.com/start/', 'https://wordpress.com/wp-login.php?action=lostpassword', ].forEach( ( fullUrl ) => { getLocaleSlug.mockImplementationOnce( () => 'en' ); expect( localizeUrl( fullUrl ) ).toEqual( fullUrl ); } ); } );
describe('.compare', () => { it('can run on a simple matrix', () => { const exponentials = [1, 2, 3, 4]; const kernel = gpuMock(compare, { output: [4], }); expect(kernel(0, exponentials)).toEqual(Float32Array.from([-0, 2, 3, 4])); expect(kernel(1, exponentials)).toEqual(Float32Array.from([1, 1, 3, 4])); expect(kernel(2, exponentials)).toEqual(Float32Array.from([1, 2, 2, 4])); expect(kernel(3, exponentials)).toEqual(Float32Array.from([1, 2, 3, 3])); }); });
test( 'should render left-arrow icon when the direction prop is "back".', () => { const wrapper = shallow( <NavigationLink { ...props } direction="back" /> ); expect( wrapper.find( Gridicon ) ).toHaveLength( 1 ); expect( wrapper.childAt( 0 ).props().icon ).toEqual( 'arrow-left' ); expect( wrapper.childAt( 1 ).text() ).toEqual( 'translated:Back' ); } );
test('can handle array of booleans', () => { const dataFormatter = new DataFormatter([true, false]); const indices = dataFormatter.toIndexes([true, false, true, false]); indices.forEach((value) => expect(value >= 0)); expect(dataFormatter.toCharacters(indices)).toEqual([ true, false, true, false, ]); });
test( 'trailing slash variations', () => { getLocaleSlug.mockImplementationOnce( () => 'de' ); expect( localizeUrl( 'https://automattic.com/cookies/' ) ).toEqual( 'https://automattic.com/de/cookies/' ); getLocaleSlug.mockImplementationOnce( () => 'de' ); expect( localizeUrl( 'https://automattic.com/cookies' ) ).toEqual( 'https://automattic.com/de/cookies/' ); } );
describe( 'setSiteType()', () => { test( 'should return the expected action object', () => { const siteType = 'Blog'; expect( setSiteType( siteType ) ).toEqual( { type: SIGNUP_STEPS_SITE_TYPE_SET, siteType, } ); } ); } );
test( 'should insert a new URL when followed', () => { const original = deepFreeze( { 'discover.wordpress.com': { is_following: true }, 'dailypost.wordpress.com': { is_following: true }, } ); const state = items( original, { type: READER_RECORD_FOLLOW, payload: { url: 'http://data.blog' }, } ); expect( state[ 'data.blog' ] ).toEqual( { is_following: true } ); } );
test( 'should find options with a literal string key', () => { expect( output ).toEqual( expect.stringContaining( 'msgctxt "context with a literal string key"\nmsgid "The string key text"\nmsgstr ""\n' ) ); } );
test( 'should not change relative URLs', () => { [ '/me/account', '/settings' ].forEach( ( fullUrl ) => { getLocaleSlug.mockImplementationOnce( () => 'en' ); expect( localizeUrl( fullUrl ) ).toEqual( fullUrl ); getLocaleSlug.mockImplementationOnce( () => 'fr' ); expect( localizeUrl( fullUrl ) ).toEqual( fullUrl ); } ); } );
test( 'WordPress.com URLs', () => { getLocaleSlug.mockImplementationOnce( () => 'en' ); expect( localizeUrl( 'https://wordpress.com/wp-login.php?action=lostpassword' ) ).toEqual( 'https://wordpress.com/wp-login.php?action=lostpassword' ); getLocaleSlug.mockImplementationOnce( () => 'de' ); expect( localizeUrl( 'https://wordpress.com/wp-login.php?action=lostpassword' ) ).toEqual( 'https://de.wordpress.com/wp-login.php?action=lostpassword' ); } );
test('can handle array of array of booleans', () => { const dataFormatter = new DataFormatter([[true], [false]]); const indices = dataFormatter.toIndexes([true, false]); indices.forEach((value) => expect(value >= 0)); expect(dataFormatter.toCharacters(indices)).toEqual([true, false]); });