File size: 2,494 Bytes
1e92f2d |
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
/**
* @jest-environment jsdom
*/
import { isMobile } from '@automattic/viewport';
import {
GP_PROJECT,
GP_BASE_URL,
GP_PROJECT_TRANSLATION_SET_SLUGS,
} from 'calypso/lib/i18n-utils/constants';
import { getTranslationPermaLink, normalizeDetailsFromTranslationData } from '../utils';
jest.mock( '@automattic/viewport', () => ( {
isMobile: jest.fn(),
} ) );
// see: `languages` array in config/_shared.json
const languagesMock = [
{
langSlug: 'de',
},
{
langSlug: 'de_formal',
parentLangSlug: 'de',
},
];
const mockGpApiResponseItem = {
original_id: '149708',
original: {
singular: 'Manage which sites appear in your profile.',
plural: null,
context: null,
},
original_comment: 'Hi!',
project: 'test',
translations: [
{
id: '7286107',
original_id: '149708',
translation_set_id: '60740',
translation_0: 'Verwalte, welche Websites in Ihrem Profil angezeigt werden.',
translation_1: 'Plural!',
user_id: '1018671',
status: 'current',
date_added: '2018-03-21 05:46:44',
date_modified: '2018-03-21 05:46:44',
warnings: null,
user_id_last_modified: '1018671',
},
],
};
describe( 'Community Translator', () => {
afterEach( () => {
isMobile.mockReset();
} );
describe( 'getTranslationPermaLink()', () => {
test( 'should return null by default', () => {
expect( getTranslationPermaLink() ).toBe( null );
} );
test( 'should return valid url with correct params for root language', () => {
expect( getTranslationPermaLink( '123', languagesMock[ 0 ] ) ).toBe(
`${ GP_BASE_URL }/projects/${ GP_PROJECT }/${ languagesMock[ 0 ].langSlug }/default?filters[original_id]=123`
);
} );
test( 'should return valid url with correct params for locale variant', () => {
expect( getTranslationPermaLink( '321', languagesMock[ 1 ], 'bean' ) ).toBe(
`${ GP_BASE_URL }/projects/bean/${ languagesMock[ 1 ].parentLangSlug }/` +
`${
GP_PROJECT_TRANSLATION_SET_SLUGS[ languagesMock[ 1 ].langSlug ]
}?filters[original_id]=321`
);
} );
} );
describe( 'normalizeDetailsFromTranslationData()', () => {
test( 'should return valid url with correct params for root language', () => {
expect( normalizeDetailsFromTranslationData( mockGpApiResponseItem ) ).toEqual( {
originalId: '149708',
comment: 'Hi!',
translatedSingular: 'Verwalte, welche Websites in Ihrem Profil angezeigt werden.',
translatedPlural: 'Plural!',
lastModified: '2018-03-21 05:46:44',
} );
} );
} );
} );
|