Skip to content
Snippets Groups Projects
Unverified Commit 611e7216 authored by Tom Robinson's avatar Tom Robinson Committed by GitHub
Browse files

Merge pull request #8749 from metabase/fix-entity-list-loader

Fix EntityListLoader
parents 444818dc 7dfba691
No related branches found
No related tags found
No related merge requests found
......@@ -45,6 +45,9 @@ const getMemoizedEntityQuery = createMemoizedSelector(
@paginationState()
@connect((state, props) => {
let { entityDef, entityQuery, page, pageSize } = props;
if (typeof entityQuery === "function") {
entityQuery = entityQuery(state, props);
}
if (typeof pageSize === "number" && typeof page === "number") {
entityQuery = { limit: pageSize, offset: pageSize * page, ...entityQuery };
}
......
......@@ -43,7 +43,7 @@ const DEFAULT_OPTIONS: Options = {
export type APIMethod = (d?: Data, o?: Options) => Promise<any>;
export type APICreator = (t: string, o?: Options | TransformFn) => APIMethod;
class Api extends EventEmitter {
export class Api extends EventEmitter {
basename: "";
GET: APICreator;
......
import React from "react";
import { mount } from "enzyme";
import EntityListLoader from "metabase/entities/containers/EntityListLoader";
import { Provider } from "react-redux";
import entitiesReducer from "metabase/redux/entities";
import { getStore } from "metabase/store";
import { Api } from "metabase/lib/api";
const MockEntityProvider = ({ children }) => (
<Provider store={getStore({ entities: entitiesReducer })}>
{children}
</Provider>
);
describe("EntityListLoader", () => {
let _makeRequest;
beforeEach(() => {
_makeRequest = Api.prototype._makeRequest;
Api.prototype._makeRequest = jest.fn().mockReturnValue(Promise.resolve([]));
});
afterEach(() => {
Api.prototype._makeRequest = _makeRequest;
});
describe("with entityType of search", () => {
it("should handle object entityQuery", async () => {
mount(
<MockEntityProvider>
<EntityListLoader
entityType="search"
entityQuery={{ collection: "foo" }}
/>
</MockEntityProvider>,
);
expect(
Api.prototype._makeRequest.mock.calls.map(c => c.slice(0, 2)),
).toEqual([["GET", "/api/collection/foo/items"]]);
});
it("should handle function entityQuery", async () => {
mount(
<MockEntityProvider>
<EntityListLoader
entityType="search"
entityQuery={(state, props) => ({ collection: props.collectionId })}
collectionId="foo"
/>
</MockEntityProvider>,
);
expect(
Api.prototype._makeRequest.mock.calls.map(c => c.slice(0, 2)),
).toEqual([["GET", "/api/collection/foo/items"]]);
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment