anbv29 commented on code in PR #703:
URL: https://github.com/apache/shenyu-dashboard/pull/703#discussion_r4231675769
##########
src/routes/Plugin/Common/selectorPagination.test.js:
##########
@@ -66,3 +66,69 @@ it("resets rule pagination and uses rule page size when
selecting a selector", (
},
});
});
+
+const makeSearchComponent = (plugins = [{ name: "divide", pluginId: "5" }]) =>
{
+ const dispatch = jest.fn();
+ const component = new Common({
+ dispatch,
+ plugins,
+ match: { params: { id: "divide" } },
+ currentNamespaceId: "namespace-1",
+ });
+ component.state = {
+ ...component.state,
+ selectorPage: 3,
+ selectorPageSize: 50,
+ selectorName: "demo",
+ };
+ component.setState = (update, callback) => {
+ component.state = { ...component.state, ...update };
+ if (callback) callback();
+ };
+ return { component, dispatch };
+};
+
+it("searches selectors from page one while preserving the filter and page
size", () => {
+ const { component, dispatch } = makeSearchComponent();
+ component.searchSelector();
+ expect(component.state.selectorPage).toBe(1);
+ expect(dispatch).toHaveBeenCalledWith({
+ type: "common/fetchSelector",
+ payload: {
+ currentPage: 1,
+ pageSize: 50,
+ pluginId: "5",
+ name: "demo",
+ namespaceId: "namespace-1",
+ },
+ });
+});
+
+it.each([true, false])(
+ "resets selector pagination when switching plugins (cached: %s)",
+ (cached) => {
+ const plugins = [{ name: "divide", pluginId: "5" }];
+ const { component, dispatch } = makeSearchComponent(cached ? plugins : []);
+ component.componentDidUpdate({
+ ...component.props,
+ match: { params: { id: "old-plugin" } },
+ });
+ if (!cached) {
+ const fetch = dispatch.mock.calls.find(
+ ([action]) => action.type === "global/fetchPlugins",
+ );
Review Comment:
Added an explicit expectation that the global/fetchPlugins dispatch exists
before invoking its callback, in f5898ce.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]