import { flagUrl } from '..';
describe( 'flagUrl', () => {
test( 'Given a valid country code, returns an SVG file path', () => {
// Note that the 'real' helper function returns a full path,
// not just a filename plus extension. However, that behavior
// relies on a webpack loader, which we can't fully emulate
// in a testing context. The closest we can get to this behavior
// uses a mock to return just a filename with extension, but no path.
expect( flagUrl( 'us' ) ).toBe( 'us.svg' );
} );
test( 'Given an invalid country code, returns a fallback inline SVG', () => {
const gridicon = `
`;
const expectedGlobeSvg = 'data:image/svg+xml;utf8,' + encodeURIComponent( gridicon );
expect( flagUrl( 'blerg' ) ).toBe( expectedGlobeSvg );
} );
test( 'Given a country code without a flag, returns a fallback inline SVG', () => {
const gridicon = `
`;
const expectedGlobeSvg = 'data:image/svg+xml;utf8,' + encodeURIComponent( gridicon );
expect( flagUrl( 'zz' ) ).toBe( expectedGlobeSvg );
} );
} );