Skip to content

Commit

Permalink
Merge 3d74389 into 5debce9
Browse files Browse the repository at this point in the history
  • Loading branch information
rebmullin committed May 17, 2018
2 parents 5debce9 + 3d74389 commit 85f43d3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 116 deletions.
6 changes: 2 additions & 4 deletions src/amo/components/AddonsByAuthorsCard/index.js
Expand Up @@ -55,11 +55,9 @@ export class AddonsByAuthorsCardBase extends React.Component<Props> {
}

componentWillMount() {
const { addons, addonType, authorUsernames, forAddonSlug } = this.props;
const { addonType, authorUsernames, forAddonSlug } = this.props;

if (!addons) {
this.dispatchFetchAddonsByAuthors({ addonType, authorUsernames, forAddonSlug });
}
this.dispatchFetchAddonsByAuthors({ addonType, authorUsernames, forAddonSlug });
}

componentWillReceiveProps({
Expand Down
133 changes: 21 additions & 112 deletions tests/unit/amo/components/TestAddonsByAuthorsCard.js
Expand Up @@ -105,7 +105,7 @@ describe(__filename, () => {
);
}

function renderAddonsWithType({ addonType, showMore, multipleAuthors = false } = {}) {
function renderAddonsWithType({ addonType, multipleAuthors = false } = {}) {
const authorUsernames = multipleAuthors ?
[fakeAuthorOne.username, fakeAuthorTwo.username] : [fakeAuthorOne.username];
const { store } = dispatchClientMetadata();
Expand All @@ -114,7 +114,6 @@ describe(__filename, () => {

return render({
addonType,
showMore,
authorUsernames,
errorHandler,
store,
Expand Down Expand Up @@ -232,6 +231,26 @@ describe(__filename, () => {
}));
});

it('dispatches fetchAddonsByAuthors on mount', () => {
const { store } = dispatchClientMetadata();
const dispatchSpy = sinon.spy(store, 'dispatch');
const errorHandler = createStubErrorHandler();

render({
addonType: ADDON_TYPE_EXTENSION,
authorUsernames: ['test2'],
errorHandler,
store,
});

sinon.assert.callCount(dispatchSpy, 1);
sinon.assert.calledWith(dispatchSpy, fetchAddonsByAuthors({
addonType: ADDON_TYPE_EXTENSION,
authorUsernames: ['test2'],
errorHandlerId: errorHandler.id,
}));
});

it('should dispatch a fetch action if authorUsernames are updated', () => {
const { store } = dispatchClientMetadata();
const dispatchSpy = sinon.spy(store, 'dispatch');
Expand Down Expand Up @@ -357,17 +376,6 @@ describe(__filename, () => {
.toHaveProp('header', `More dictionaries by ${fakeAuthor.name}`);
});

it('shows dictionaries in header for ADDON_TYPE_DICT without More text', () => {
const root = renderAddonsWithType({
addonType: ADDON_TYPE_DICT,
showMore: false,
multipleAuthors: false,
});

expect(root.find(AddonsCard))
.toHaveProp('header', `Dictionaries by ${fakeAuthor.name}`);
});

it('shows dictionaries in header for ADDON_TYPE_DICT with multiple authors', () => {
const root = renderAddonsWithType({
addonType: ADDON_TYPE_DICT,
Expand All @@ -378,17 +386,6 @@ describe(__filename, () => {
.toHaveProp('header', 'More dictionaries by these translators');
});

it('shows dictionaries in header for ADDON_TYPE_DICT with multiple authors and without More text', () => {
const root = renderAddonsWithType({
addonType: ADDON_TYPE_DICT,
showMore: false,
multipleAuthors: true,
});

expect(root.find(AddonsCard))
.toHaveProp('header', `Dictionaries by these translators`);
});

it('shows extensions in header for ADDON_TYPE_EXTENSION', () => {
const root = renderAddonsWithType({
addonType: ADDON_TYPE_EXTENSION,
Expand All @@ -399,17 +396,6 @@ describe(__filename, () => {
.toHaveProp('header', `More extensions by ${fakeAuthor.name}`);
});

it('shows extensions in header for ADDON_TYPE_EXTENSION without More text', () => {
const root = renderAddonsWithType({
addonType: ADDON_TYPE_EXTENSION,
showMore: false,
multipleAuthors: false,
});

expect(root.find(AddonsCard))
.toHaveProp('header', `Extensions by ${fakeAuthor.name}`);
});

it('shows extensions in header for ADDON_TYPE_EXTENSION with multiple authors', () => {
const root = renderAddonsWithType({
addonType: ADDON_TYPE_EXTENSION,
Expand All @@ -420,17 +406,6 @@ describe(__filename, () => {
.toHaveProp('header', 'More extensions by these developers');
});

it('shows extensions in header for ADDON_TYPE_EXTENSION with multiple authors and without More text', () => {
const root = renderAddonsWithType({
addonType: ADDON_TYPE_EXTENSION,
showMore: false,
multipleAuthors: true,
});

expect(root.find(AddonsCard))
.toHaveProp('header', 'Extensions by these developers');
});

it('shows extensions in header for ADDON_TYPE_LANG', () => {
const root = renderAddonsWithType({
addonType: ADDON_TYPE_LANG,
Expand All @@ -441,17 +416,6 @@ describe(__filename, () => {
.toHaveProp('header', `More language packs by ${fakeAuthor.name}`);
});

it('shows extensions in header for ADDON_TYPE_LANG without More text', () => {
const root = renderAddonsWithType({
addonType: ADDON_TYPE_LANG,
showMore: false,
multipleAuthors: false,
});

expect(root.find(AddonsCard))
.toHaveProp('header', `Language packs by ${fakeAuthor.name}`);
});

it('shows extensions in header for ADDON_TYPE_LANG with multiple authors', () => {
const root = renderAddonsWithType({
addonType: ADDON_TYPE_LANG,
Expand All @@ -462,17 +426,6 @@ describe(__filename, () => {
.toHaveProp('header', 'More language packs by these translators');
});

it('shows extensions in header for ADDON_TYPE_LANG with multiple authors and without More text', () => {
const root = renderAddonsWithType({
addonType: ADDON_TYPE_LANG,
showMore: false,
multipleAuthors: true,
});

expect(root.find(AddonsCard))
.toHaveProp('header', 'Language packs by these translators');
});

it('shows extensions in header for ADDON_TYPE_THEME', () => {
const root = renderAddonsWithType({
addonType: ADDON_TYPE_THEME,
Expand All @@ -483,17 +436,6 @@ describe(__filename, () => {
.toHaveProp('header', `More themes by ${fakeAuthor.name}`);
});

it('shows extensions in header for ADDON_TYPE_THEME without More text', () => {
const root = renderAddonsWithType({
addonType: ADDON_TYPE_THEME,
showMore: false,
multipleAuthors: false,
});

expect(root.find(AddonsCard))
.toHaveProp('header', `Themes by ${fakeAuthor.name}`);
});

it('shows extensions in header for ADDON_TYPE_THEME with multiple authors', () => {
const root = renderAddonsWithType({
addonType: ADDON_TYPE_THEME,
Expand All @@ -504,17 +446,6 @@ describe(__filename, () => {
.toHaveProp('header', 'More themes by these artists');
});

it('shows extensions in header for ADDON_TYPE_THEME with multiple authors and without More text ', () => {
const root = renderAddonsWithType({
addonType: ADDON_TYPE_THEME,
showMore: false,
multipleAuthors: true,
});

expect(root.find(AddonsCard))
.toHaveProp('header', 'Themes by these artists');
});

it('shows add-ons in header if no specific addonType translation found', () => {
const root = renderAddonsWithType({
addonType: ADDON_TYPE_OPENSEARCH,
Expand All @@ -525,17 +456,6 @@ describe(__filename, () => {
.toHaveProp('header', `More add-ons by ${fakeAuthor.name}`);
});

it('shows add-ons in header if no specific addonType translation found without More text', () => {
const root = renderAddonsWithType({
addonType: ADDON_TYPE_OPENSEARCH,
showMore: false,
multipleAuthors: false,
});

expect(root.find(AddonsCard))
.toHaveProp('header', `Add-ons by ${fakeAuthor.name}`);
});

it('shows add-ons in header if no specific addonType found with multiple authors', () => {
const root = renderAddonsWithType({
addonType: ADDON_TYPE_OPENSEARCH,
Expand All @@ -545,15 +465,4 @@ describe(__filename, () => {
expect(root.find(AddonsCard))
.toHaveProp('header', 'More add-ons by these developers');
});

it('shows add-ons in header if no specific addonType found with multiple authors and without More text', () => {
const root = renderAddonsWithType({
addonType: ADDON_TYPE_OPENSEARCH,
showMore: false,
multipleAuthors: true,
});

expect(root.find(AddonsCard))
.toHaveProp('header', 'Add-ons by these developers');
});
});

0 comments on commit 85f43d3

Please sign in to comment.