github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ui/src/test-utils/connectedMount.tsx (about)

     1  // Copyright 2020 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  import React from "react";
    12  import { mount, ReactWrapper } from "enzyme";
    13  import { Action, Store } from "redux";
    14  import { Provider } from "react-redux";
    15  import { ConnectedRouter } from "connected-react-router";
    16  import { createMemoryHistory } from "history";
    17  
    18  import "src/enzymeInit";
    19  import { AdminUIState, createAdminUIStore } from "src/redux/state";
    20  
    21  export function connectedMount(nodeFactory: (store: Store<AdminUIState>) => React.ReactNode) {
    22    const history = createMemoryHistory({
    23      initialEntries: ["/"],
    24    });
    25    const store: Store<AdminUIState, Action> = createAdminUIStore(history);
    26    const wrapper: ReactWrapper = mount(
    27      <Provider store={store}>
    28        <ConnectedRouter history={history}>
    29          {
    30            nodeFactory(store)
    31          }
    32        </ConnectedRouter>
    33      </Provider>);
    34    return wrapper;
    35  }