Skip to content

Commit

Permalink
whoops
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstinalin committed Dec 6, 2024
1 parent e012cfa commit 66435bc
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/amo/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ export const SPOTLIGHT = 'spotlight';
export const STRATEGIC = 'strategic';

export const ALL_PROMOTED_CATEGORIES = [
LINE,
RECOMMENDED,
LINE,
SPOTLIGHT,
STRATEGIC,
];
Expand Down
16 changes: 10 additions & 6 deletions src/amo/utils/addons.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
FATAL_INSTALL_ERROR,
FATAL_UNINSTALL_ERROR,
INSTALL_FAILED,
ALL_PROMOTED_CATEGORIES,
} from 'amo/constants';
import log from 'amo/logger';
import { getPreviewImage } from 'amo/imageUtils';
Expand Down Expand Up @@ -135,12 +136,15 @@ export const getPromotedCategories = ({
});

// Special logic if we're using the category for badging.
if (
forBadging &&
categories.every((item) => !BADGE_CATEGORIES.includes(item))
) {
categories = [];
// We shouldn't add badges that are in BADGE_CATEGORIES.
if (forBadging) {
categories = categories.filter((category) =>
BADGE_CATEGORIES.includes(category),
);
}

return categories;
return categories.sort(
(a, b) =>
ALL_PROMOTED_CATEGORIES.indexOf(a) - ALL_PROMOTED_CATEGORIES.indexOf(b),
);
};
17 changes: 17 additions & 0 deletions tests/unit/amo/pages/TestAddon.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import {
INCOMPATIBLE_UNSUPPORTED_PLATFORM,
INSTALLING,
RECOMMENDED,
LINE,
SPOTLIGHT,
STRATEGIC,
REVIEWER_TOOLS_VIEW,
SET_VIEW_CONTEXT,
STATIC_THEMES_REVIEW,
Expand Down Expand Up @@ -2965,6 +2968,20 @@ describe(__filename, () => {
},
);

it('does not render the strategic or spotlight badges and correctly render the LINE and RECOMMENDED badges in the correct order', () => {
const categories = [LINE, RECOMMENDED, STRATEGIC, SPOTLIGHT];
addon.promoted = categories.map((category) => ({
category,
apps: [clientApp],
}));
renderWithAddon();
const badges = screen.getAllByClassName('PromotedBadge');
expect(badges).toHaveLength(2);
// Recommended should be on top.
expect(badges[0]).toHaveClass(`PromotedBadge--recommended`);
expect(badges[1]).toHaveClass(`PromotedBadge--line`);
});

// See https://github.com/mozilla/addons-frontend/issues/8285.
it('does not pass an alt property to IconPromotedBadge', () => {
renderWithPromotedCategory();
Expand Down
64 changes: 64 additions & 0 deletions tests/unit/amo/utils/test_addons.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,70 @@ describe(__filename, () => {
).toEqual([category]);
});

it('returns multiple categories if the addon is promoted for the specified app', () => {
const categories = [RECOMMENDED, STRATEGIC, SPOTLIGHT];
const promoted = categories.map((category) => ({
category,
apps: [CLIENT_APP_ANDROID],
}));

const addon = createInternalAddonWithLang({
...fakeAddon,
promoted,
});
const suggestion = createInternalSuggestionWithLang(
createFakeAutocompleteResult({
promoted,
}),
);

expect(
getPromotedCategories({
addon,
clientApp: CLIENT_APP_ANDROID,
}),
).toEqual(categories);
expect(
getPromotedCategories({
addon: suggestion,
clientApp: CLIENT_APP_ANDROID,
}),
).toEqual(categories);
});

it('returns the filtered categories if forBadging is True and the addon is promoted for the specified app', () => {
const categories = [RECOMMENDED, STRATEGIC, SPOTLIGHT];
const promoted = categories.map((category) => ({
category,
apps: [CLIENT_APP_ANDROID],
}));

const addon = createInternalAddonWithLang({
...fakeAddon,
promoted,
});
const suggestion = createInternalSuggestionWithLang(
createFakeAutocompleteResult({
promoted,
}),
);

expect(
getPromotedCategories({
addon,
clientApp: CLIENT_APP_ANDROID,
forBadging: true,
}),
).toEqual([categories[0]]);
expect(
getPromotedCategories({
addon: suggestion,
clientApp: CLIENT_APP_ANDROID,
forBadging: true,
}),
).toEqual([categories[0]]);
});

it('returns the empty list if the addon is not promoted via null', () => {
const addon = createInternalAddonWithLang({
...fakeAddon,
Expand Down

0 comments on commit 66435bc

Please sign in to comment.