Skip to content

Commit

Permalink
Ensure incoming font is returned.
Browse files Browse the repository at this point in the history
  • Loading branch information
jffng committed Nov 15, 2023
1 parent 5d8b9d9 commit c102315
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function getIntersectingFontFaces( incoming, existing ) {
} );
}
);
matches.push( { ...existingFont, fontFace: matchingFaces } );
matches.push( { ...incomingFont, fontFace: matchingFaces } );
} else {
matches.push( incomingFont );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import getIntersectingFontFaces from '../get-intersecting-font-faces';

describe( 'getIntersectingFontFaces', () => {
it( 'returns matching font faces for matching font family', () => {
const intendedFontsFamilies = [
const incomingFontFamilies = [
{
slug: 'lobster',
fontFace: [
Expand All @@ -30,15 +30,15 @@ describe( 'getIntersectingFontFaces', () => {
];

const result = getIntersectingFontFaces(
intendedFontsFamilies,
incomingFontFamilies,
existingFontFamilies
);

expect( result ).toEqual( intendedFontsFamilies );
expect( result ).toEqual( incomingFontFamilies );
} );

it( 'returns empty array when there is no match', () => {
const intendedFontsFamilies = [
const incomingFontFamilies = [
{
slug: 'lobster',
fontFace: [
Expand All @@ -63,15 +63,15 @@ describe( 'getIntersectingFontFaces', () => {
];

const result = getIntersectingFontFaces(
intendedFontsFamilies,
incomingFontFamilies,
existingFontFamilies
);

expect( result ).toEqual( [] );
} );

it( 'returns matching font faces', () => {
const intendedFontsFamilies = [
const incomingFontFamilies = [
{
slug: 'lobster',
fontFace: [
Expand Down Expand Up @@ -129,15 +129,15 @@ describe( 'getIntersectingFontFaces', () => {
];

const result = getIntersectingFontFaces(
intendedFontsFamilies,
incomingFontFamilies,
existingFontFamilies
);

expect( result ).toEqual( expectedOutput );
} );

it( 'returns empty array when the first list is empty', () => {
const intendedFontsFamilies = [];
const incomingFontFamilies = [];

const existingFontFamilies = [
{
Expand All @@ -152,15 +152,15 @@ describe( 'getIntersectingFontFaces', () => {
];

const result = getIntersectingFontFaces(
intendedFontsFamilies,
incomingFontFamilies,
existingFontFamilies
);

expect( result ).toEqual( [] );
} );

it( 'returns empty array when the second list is empty', () => {
const intendedFontsFamilies = [
const incomingFontFamilies = [
{
slug: 'lobster',
fontFace: [
Expand All @@ -175,15 +175,15 @@ describe( 'getIntersectingFontFaces', () => {
const existingFontFamilies = [];

const result = getIntersectingFontFaces(
intendedFontsFamilies,
incomingFontFamilies,
existingFontFamilies
);

expect( result ).toEqual( [] );
} );

it( 'returns intersecting font family when there are no fonfaces', () => {
const intendedFontsFamilies = [
const incomingFontFamilies = [
{
slug: 'piazzolla',
fontFace: [ { fontStyle: 'normal', fontWeight: '400' } ],
Expand All @@ -200,15 +200,15 @@ describe( 'getIntersectingFontFaces', () => {
];

const result = getIntersectingFontFaces(
intendedFontsFamilies,
incomingFontFamilies,
existingFontFamilies
);

expect( result ).toEqual( existingFontFamilies );
} );

it( 'returns intersecting if there is an intended font face and is not present in the returning it should not be returned', () => {
const intendedFontsFamilies = [
const incomingFontFamilies = [
{
slug: 'piazzolla',
fontFace: [ { fontStyle: 'normal', fontWeight: '400' } ],
Expand All @@ -226,7 +226,7 @@ describe( 'getIntersectingFontFaces', () => {
];

const result = getIntersectingFontFaces(
intendedFontsFamilies,
incomingFontFamilies,
existingFontFamilies
);
const expected = [
Expand All @@ -237,4 +237,35 @@ describe( 'getIntersectingFontFaces', () => {
];
expect( result ).toEqual( expected );
} );

it( 'updates font family definition using the incoming data', () => {
const incomingFontFamilies = [
{
slug: 'gothic-a1',
fontFace: [ { fontStyle: 'normal', fontWeight: '400' } ],
fontFamily: "'Gothic A1', serif",
},
];

const existingFontFamilies = [
{
slug: 'gothic-a1',
fontFace: [ { fontStyle: 'normal', fontWeight: '400' } ],
fontFamily: 'Gothic A1, serif',
},
];

const result = getIntersectingFontFaces(
incomingFontFamilies,
existingFontFamilies
);
const expected = [
{
slug: 'gothic-a1',
fontFace: [ { fontStyle: 'normal', fontWeight: '400' } ],
fontFamily: "'Gothic A1', serif",
},
];
expect( result ).toEqual( expected );
} );
} );

0 comments on commit c102315

Please sign in to comment.