Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Oct 10, 2023
1 parent 1084739 commit 6881750
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 25 deletions.
4 changes: 4 additions & 0 deletions packages/core-data/src/hooks/test/use-entity-records.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ describe( 'useEntityRecords', () => {
hasResolved: false,
isResolving: false,
status: 'IDLE',
totalItems: null,
totalPages: null,
} );

// Fetch request should have been issued
Expand All @@ -65,6 +67,8 @@ describe( 'useEntityRecords', () => {
hasResolved: true,
isResolving: false,
status: 'SUCCESS',
totalItems: null,
totalPages: null,
} );
} );
} );
10 changes: 7 additions & 3 deletions packages/core-data/src/queried-data/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,13 @@ const queries = ( state = {}, action ) => {
Object.entries( contextQueries ).map(
( [ query, queryItems ] ) => [
query,
queryItems.filter(
( queryId ) => ! removedItems[ queryId ]
),
{
...queryItems,
itemIds: queryItems.itemIds.filter(
( queryId ) =>
! removedItems[ queryId ]
),
},
]
)
),
Expand Down
18 changes: 9 additions & 9 deletions packages/core-data/src/queried-data/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe( 'reducer', () => {
default: { 1: true },
},
queries: {
default: { 's=a': [ 1 ] },
default: { 's=a': { itemIds: [ 1 ] } },
},
} );
} );
Expand Down Expand Up @@ -200,8 +200,8 @@ describe( 'reducer', () => {
},
queries: {
default: {
'': [ 1, 2, 3, 4 ],
's=a': [ 1, 3 ],
'': { itemIds: [ 1, 2, 3, 4 ] },
's=a': { itemIds: [ 1, 3 ] },
},
},
} );
Expand All @@ -218,8 +218,8 @@ describe( 'reducer', () => {
},
queries: {
default: {
'': [ 1, 2, 4 ],
's=a': [ 1 ],
'': { itemIds: [ 1, 2, 4 ] },
's=a': { itemIds: [ 1 ] },
},
},
} );
Expand All @@ -238,8 +238,8 @@ describe( 'reducer', () => {
},
queries: {
default: {
'': [ 'foo//bar1', 'foo//bar2', 'foo//bar3' ],
's=2': [ 'foo//bar2' ],
'': { itemIds: [ 'foo//bar1', 'foo//bar2', 'foo//bar3' ] },
's=2': { itemIds: [ 'foo//bar2' ] },
},
},
} );
Expand All @@ -258,8 +258,8 @@ describe( 'reducer', () => {
},
queries: {
default: {
'': [ 'foo//bar1', 'foo//bar3' ],
's=2': [],
'': { itemIds: [ 'foo//bar1', 'foo//bar3' ] },
's=2': { itemIds: [] },
},
},
} );
Expand Down
16 changes: 8 additions & 8 deletions packages/core-data/src/queried-data/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe( 'getQueriedItems', () => {
},
queries: {
default: {
'': [ 1, 2 ],
'': { itemIds: [ 1, 2 ] },
},
},
};
Expand All @@ -56,7 +56,7 @@ describe( 'getQueriedItems', () => {
2: true,
},
},
queries: [ 1, 2 ],
queries: { itemIds: [ 1, 2 ] },
};

const resultA = getQueriedItems( state, {} );
Expand All @@ -81,8 +81,8 @@ describe( 'getQueriedItems', () => {
},
queries: {
default: {
'': [ 1, 2 ],
'include=1': [ 1 ],
'': { itemIds: [ 1, 2 ] },
'include=1': { itemIds: [ 1 ] },
},
},
};
Expand Down Expand Up @@ -116,7 +116,7 @@ describe( 'getQueriedItems', () => {
},
queries: {
default: {
'_fields=content': [ 1, 2 ],
'_fields=content': { itemIds: [ 1, 2 ] },
},
},
};
Expand Down Expand Up @@ -161,7 +161,7 @@ describe( 'getQueriedItems', () => {
},
queries: {
default: {
'_fields=content%2Cmeta.template': [ 1, 2 ],
'_fields=content%2Cmeta.template': { itemIds: [ 1, 2 ] },
},
},
};
Expand Down Expand Up @@ -198,7 +198,7 @@ describe( 'getQueriedItems', () => {
},
queries: {
default: {
'': [ 1, 2 ],
'': { itemIds: [ 1, 2 ] },
},
},
};
Expand Down Expand Up @@ -230,7 +230,7 @@ describe( 'getQueriedItems', () => {
},
queries: {
default: {
'': [ 1, 2 ],
'': { itemIds: [ 1, 2 ] },
},
},
};
Expand Down
1 change: 0 additions & 1 deletion packages/core-data/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ export const getEntityRecords =
};
} else {
records = Object.values( await apiFetch( { path } ) );
meta = {};
}

// If we request fields but the result doesn't contain the fields,
Expand Down
5 changes: 4 additions & 1 deletion packages/core-data/src/test/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ describe( 'getEntityRecords', () => {
'root',
'postType',
Object.values( POST_TYPES ),
{}
{},
false,
undefined,
undefined
);
} );

Expand Down
8 changes: 5 additions & 3 deletions packages/core-data/src/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ describe( 'hasEntityRecords', () => {
},
queries: {
default: {
'': [ 'post', 'page' ],
'': { itemIds: [ 'post', 'page' ] },
},
},
},
Expand Down Expand Up @@ -361,7 +361,7 @@ describe( 'getEntityRecords', () => {
},
queries: {
default: {
'': [ 'post', 'page' ],
'': { itemIds: [ 'post', 'page' ] },
},
},
},
Expand Down Expand Up @@ -399,7 +399,9 @@ describe( 'getEntityRecords', () => {
},
queries: {
default: {
'_fields=id%2Ccontent': [ 1 ],
'_fields=id%2Ccontent': {
itemIds: [ 1 ],
},
},
},
},
Expand Down

0 comments on commit 6881750

Please sign in to comment.