Esempio n. 1
0
  it('dispatches an action to fetch the add-ons to display on update', () => {
    const includeFeaturedThemes = false;
    const includeTrendingExtensions = false;
    const { store } = dispatchClientMetadata();

    const fakeDispatch = sinon.stub(store, 'dispatch');

    const root = render({
      includeFeaturedThemes,
      includeTrendingExtensions,
      store,
    });
    fakeDispatch.resetHistory();

    // We simulate an update to trigger `componentDidUpdate()`.
    root.setProps();

    sinon.assert.callCount(fakeDispatch, 2);
    sinon.assert.calledWith(fakeDispatch, setViewContext(VIEW_CONTEXT_HOME));
    sinon.assert.calledWith(
      fakeDispatch,
      fetchHomeAddons({
        errorHandlerId: root.instance().props.errorHandler.id,
        collectionsToFetch: FEATURED_COLLECTIONS,
        includeFeaturedThemes,
        includeTrendingExtensions,
      }),
    );
  });
Esempio n. 2
0
  it('dispatches an action to fetch the add-ons to display', () => {
    const includeFeaturedThemes = false;
    const includeTrendingExtensions = false;
    const errorHandler = createStubErrorHandler();
    const { store } = dispatchClientMetadata();

    const fakeDispatch = sinon.stub(store, 'dispatch');

    render({
      errorHandler,
      includeFeaturedThemes,
      includeTrendingExtensions,
      store,
    });

    sinon.assert.callCount(fakeDispatch, 2);
    sinon.assert.calledWith(fakeDispatch, setViewContext(VIEW_CONTEXT_HOME));
    sinon.assert.calledWith(
      fakeDispatch,
      fetchHomeAddons({
        errorHandlerId: errorHandler.id,
        collectionsToFetch: FEATURED_COLLECTIONS,
        includeFeaturedThemes,
        includeTrendingExtensions,
      }),
    );
  });
Esempio n. 3
0
 function _fetchHomeAddons(params) {
   sagaTester.dispatch(
     fetchHomeAddons({
       collectionsToFetch: [{ slug: 'some-slug', user: 'some-user' }],
       errorHandlerId: errorHandler.id,
       includeFeaturedThemes: true,
       includeTrendingExtensions: true,
       ...params,
     }),
   );
 }
Esempio n. 4
0
    it('sets `resultsLoaded` to `false` when fetching home add-ons', () => {
      const loadedState = { ...initialState, resultsLoaded: true };

      const state = homeReducer(
        loadedState,
        fetchHomeAddons({
          collectionsToFetch: [],
          errorHandlerId: 'some-error-handler-id',
          includeFeaturedThemes: true,
        }),
      );

      expect(state.resultsLoaded).toEqual(false);
    });
  it('includes featured themes by default', () => {
    const errorHandler = createStubErrorHandler();
    const { store } = dispatchClientMetadata();

    const fakeDispatch = sinon.stub(store, 'dispatch');
    render({ errorHandler, store });

    sinon.assert.callCount(fakeDispatch, 2);
    sinon.assert.calledWith(fakeDispatch, setViewContext(VIEW_CONTEXT_HOME));
    sinon.assert.calledWith(
      fakeDispatch,
      fetchHomeAddons({
        errorHandlerId: errorHandler.id,
        collectionsToFetch: FEATURED_COLLECTIONS,
        includeFeaturedThemes: true,
      }),
    );
  });
Esempio n. 6
0
  loadDataIfNeeded() {
    const {
      dispatch,
      errorHandler,
      includeFeaturedThemes,
      includeTrendingExtensions,
      resultsLoaded,
    } = this.props;

    dispatch(setViewContext(VIEW_CONTEXT_HOME));

    if (!resultsLoaded) {
      dispatch(
        fetchHomeAddons({
          collectionsToFetch: FEATURED_COLLECTIONS,
          errorHandlerId: errorHandler.id,
          includeFeaturedThemes,
          includeTrendingExtensions,
        }),
      );
    }
  }