Skip to content

Commit

Permalink
Add useFilteredConnections tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraenhansen committed Nov 8, 2024
1 parent 683827b commit 75ef919
Showing 1 changed file with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,38 @@ describe('useFilteredConnections', function () {
});
});

context('excluding inactive connections', function () {
it('should match only connected collections items', function () {
const { result, rerender } = renderHookWithContext(
useFilteredConnections,
{
initialProps: {
connections: mockSidebarConnections,
filterRegex: null,
fetchAllCollections: fetchAllCollectionsStub,
onDatabaseExpand: onDatabaseExpandStub,
excludeInactive: true,
},
}
);

expect(result.current.filtered).to.be.deep.equal([
sidebarConnections[0],
sidebarConnections[1],
]);

rerender({
connections: mockSidebarConnections,
filterRegex: null,
fetchAllCollections: fetchAllCollectionsStub,
onDatabaseExpand: onDatabaseExpandStub,
excludeInactive: false,
});

expect(result.current.filtered).to.be.undefined;
});
});

context('and a connection is toggled', function () {
it('should return the appropriate connection expanded state for the toggled connection', async function () {
const { result } = renderHookWithContext(useFilteredConnections, {
Expand Down Expand Up @@ -609,6 +641,40 @@ describe('useFilteredConnections', function () {
});
});

context('excluding inactive connections', function () {
it('should match only connected collections items', function () {
const { result, rerender } = renderHookWithContext(
useFilteredConnections,
{
initialProps: {
connections: mockSidebarConnections,
filterRegex: new RegExp('connection_1'),
fetchAllCollections: fetchAllCollectionsStub,
onDatabaseExpand: onDatabaseExpandStub,
excludeInactive: true,
},
}
);

expect(result.current.filtered).to.be.deep.equal([
sidebarConnections[0],
]);

rerender({
connections: mockSidebarConnections,
filterRegex: new RegExp('connection_1'),
fetchAllCollections: fetchAllCollectionsStub,
onDatabaseExpand: onDatabaseExpandStub,
excludeInactive: false,
});

expect(result.current.filtered).to.be.deep.equal([
sidebarConnections[0],
sidebarConnections[2],
]);
});
});

context('and items are already collapsed', function () {
it('should expand the items temporarily', async function () {
const { result, rerender } = renderHookWithContext(
Expand Down

0 comments on commit 75ef919

Please sign in to comment.