Exemplo n.º 1
0
  it('dispatches deleteCollectionAddonNotes when deleteNote is called', () => {
    const authorUserId = 11;
    const { store } = dispatchSignInActions({ userId: authorUserId });

    const addons = createFakeCollectionAddons();
    const addonId = addons[0].addon.id;
    const detail = createFakeCollectionDetail({
      authorId: authorUserId,
    });
    const errorHandler = createStubErrorHandler();
    const fakeDispatch = sinon.spy(store, 'dispatch');
    const page = 123;
    const sort = COLLECTION_SORT_NAME;

    store.dispatch(
      loadCurrentCollection({
        addons,
        detail,
        pageSize: DEFAULT_API_PAGE_SIZE,
      }),
    );
    const root = renderComponent({
      editing: true,
      errorHandler,
      location: createFakeLocation({ query: { page, collection_sort: sort } }),
      store,
    });

    fakeDispatch.resetHistory();

    // This simulates the user clicking the "Delete" button on the
    // EditableCollectionAddon component's comment form.
    const deleteNote = root.find(AddonsCard).prop('deleteNote');
    deleteNote(addonId, errorHandler);
    sinon.assert.callCount(fakeDispatch, 1);
    sinon.assert.calledWith(
      fakeDispatch,
      deleteCollectionAddonNotes({
        addonId,
        errorHandlerId: errorHandler.id,
        filters: { page, collectionSort: sort },
        slug: detail.slug,
        username: detail.author.username,
      }),
    );
  });
    it('deletes notes for a collection add-on by updating the notes to an empty string', async () => {
      const params = {
        addonId: 123,
        filters: { page: 2 },
        slug: 'some-other-slug',
        username: '******',
      };
      const state = sagaTester.getState();

      mockApi
        .expects('updateCollectionAddon')
        .withArgs({
          addonId: params.addonId,
          api: state.api,
          notes: '',
          slug: params.slug,
          username: params.username,
        })
        .once()
        .returns(Promise.resolve());

      sagaTester.dispatch(
        deleteCollectionAddonNotes({
          errorHandlerId: errorHandler.id,
          ...params,
        }),
      );

      const expectedFetchAction = fetchCurrentCollectionPage({
        filters: params.filters,
        errorHandlerId: errorHandler.id,
        slug: params.slug,
        username: params.username,
      });

      const fetchAction = await sagaTester.waitFor(expectedFetchAction.type);
      expect(fetchAction).toEqual(expectedFetchAction);
      mockApi.verify();
    });
Exemplo n.º 3
0
  deleteNote: DeleteAddonNoteFunc = (
    addonId: number,
    errorHandler: ErrorHandlerType,
  ) => {
    const { collection, dispatch, filters } = this.props;

    invariant(collection, 'collection is required');

    const { slug, authorId: userId } = collection;

    invariant(slug, 'slug is required');
    invariant(userId, 'userId is required');

    dispatch(
      deleteCollectionAddonNotes({
        addonId,
        errorHandlerId: errorHandler.id,
        filters,
        slug,
        userId,
      }),
    );
  };