mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Multiple checks for pinnedItems (#11031)
* remove null/undefined entries from pinnedItems when an item is toggled - more inner checks + test * drawer: fix when there isn't a page available * rollback cleaning up pinnedEntries on item-toggle * remove "re-setting" pinnedItems * remove the filter
This commit is contained in:
@@ -62,6 +62,18 @@ describe('inAppRewards', () => {
|
|||||||
expect(result[9].path).to.eql('potion');
|
expect(result[9].path).to.eql('potion');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('ignores null/undefined entries', () => {
|
||||||
|
user.pinnedItems = testPinnedItems;
|
||||||
|
user.pinnedItems.push(null);
|
||||||
|
user.pinnedItems.push(undefined);
|
||||||
|
user.pinnedItemsOrder = testPinnedItemsOrder;
|
||||||
|
|
||||||
|
let result = inAppRewards(user);
|
||||||
|
|
||||||
|
expect(result[2].path).to.eql('armoire');
|
||||||
|
expect(result[9].path).to.eql('potion');
|
||||||
|
});
|
||||||
|
|
||||||
it('does not return seasonal items which have been unpinned', () => {
|
it('does not return seasonal items which have been unpinned', () => {
|
||||||
if (officialPinnedItems.length === 0) {
|
if (officialPinnedItems.length === 0) {
|
||||||
return; // if no seasonal items, this test is not applicable
|
return; // if no seasonal items, this test is not applicable
|
||||||
|
|||||||
18
test/common/ops/pinnedGearUtils.js
Normal file
18
test/common/ops/pinnedGearUtils.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import {
|
||||||
|
generateUser,
|
||||||
|
} from '../../helpers/common.helper';
|
||||||
|
import {addPinnedGear} from '../../../website/common/script/ops/pinnedGearUtils';
|
||||||
|
|
||||||
|
describe('shared.ops.pinnedGearUtils.addPinnedGear', () => {
|
||||||
|
let user;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
user = generateUser();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('not adds an item with empty properties to pinnedItems', () => {
|
||||||
|
addPinnedGear(user, undefined, undefined);
|
||||||
|
|
||||||
|
expect(user.pinnedItems.length).to.be.eql(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -174,7 +174,9 @@ export default {
|
|||||||
let minPaddingBottom = 20;
|
let minPaddingBottom = 20;
|
||||||
let drawerHeight = this.$el.offsetHeight;
|
let drawerHeight = this.$el.offsetHeight;
|
||||||
let standardPage = document.getElementsByClassName('standard-page')[0];
|
let standardPage = document.getElementsByClassName('standard-page')[0];
|
||||||
standardPage.style.paddingBottom = `${drawerHeight + minPaddingBottom}px`;
|
if (standardPage) {
|
||||||
|
standardPage.style.paddingBottom = `${drawerHeight + minPaddingBottom}px`;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
toggle () {
|
toggle () {
|
||||||
this.open = !this.isOpen;
|
this.open = !this.isOpen;
|
||||||
|
|||||||
@@ -20,9 +20,6 @@ function buyItem (store, params) {
|
|||||||
|
|
||||||
let opResult = buyOp(user, {params, quantity});
|
let opResult = buyOp(user, {params, quantity});
|
||||||
|
|
||||||
user.pinnedItems = opResult[0].pinnedItems;
|
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
result: opResult,
|
result: opResult,
|
||||||
httpCall: axios.post(`/api/v4/user/buy/${params.key}`),
|
httpCall: axios.post(`/api/v4/user/buy/${params.key}`),
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import getOfficialPinnedItems from './getOfficialPinnedItems';
|
|||||||
import compactArray from 'lodash/compact';
|
import compactArray from 'lodash/compact';
|
||||||
|
|
||||||
import getItemByPathAndType from './getItemByPathAndType';
|
import getItemByPathAndType from './getItemByPathAndType';
|
||||||
|
import {checkPinnedAreasForNullEntries} from '../ops/pinnedGearUtils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Orders the pinned items so we always get our inAppRewards in the order
|
* Orders the pinned items so we always get our inAppRewards in the order
|
||||||
@@ -32,6 +33,8 @@ function sortInAppRewards (user, items) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = function getPinnedItems (user) {
|
module.exports = function getPinnedItems (user) {
|
||||||
|
checkPinnedAreasForNullEntries(user);
|
||||||
|
|
||||||
let officialPinnedItems = getOfficialPinnedItems(user);
|
let officialPinnedItems = getOfficialPinnedItems(user);
|
||||||
|
|
||||||
const officialPinnedItemsNotUnpinned = officialPinnedItems.filter(officialPin => {
|
const officialPinnedItemsNotUnpinned = officialPinnedItems.filter(officialPin => {
|
||||||
@@ -41,11 +44,12 @@ module.exports = function getPinnedItems (user) {
|
|||||||
|
|
||||||
const pinnedItems = officialPinnedItemsNotUnpinned.concat(user.pinnedItems);
|
const pinnedItems = officialPinnedItemsNotUnpinned.concat(user.pinnedItems);
|
||||||
|
|
||||||
let items = pinnedItems.map(({type, path}) => {
|
let items = pinnedItems
|
||||||
let item = getItemByPathAndType(type, path);
|
.map(({type, path}) => {
|
||||||
|
let item = getItemByPathAndType(type, path);
|
||||||
|
|
||||||
return getItemInfo(user, type, item, officialPinnedItems);
|
return getItemInfo(user, type, item, officialPinnedItems);
|
||||||
});
|
});
|
||||||
|
|
||||||
shops.checkMarketGearLocked(user, items);
|
shops.checkMarketGearLocked(user, items);
|
||||||
|
|
||||||
|
|||||||
@@ -107,7 +107,8 @@ function getClassName (classType, language) {
|
|||||||
// TODO Refactor the `.locked` logic
|
// TODO Refactor the `.locked` logic
|
||||||
shops.checkMarketGearLocked = function checkMarketGearLocked (user, items) {
|
shops.checkMarketGearLocked = function checkMarketGearLocked (user, items) {
|
||||||
let result = filter(items, ['pinType', 'marketGear']);
|
let result = filter(items, ['pinType', 'marketGear']);
|
||||||
let availableGear = map(updateStore(user), (item) => getItemInfo(user, 'marketGear', item).path);
|
const officialPinnedItems = getOfficialPinnedItems(user);
|
||||||
|
let availableGear = map(updateStore(user), (item) => getItemInfo(user, 'marketGear', item, officialPinnedItems).path);
|
||||||
for (let gear of result) {
|
for (let gear of result) {
|
||||||
if (gear.klass !== user.stats.class) {
|
if (gear.klass !== user.stats.class) {
|
||||||
gear.locked = true;
|
gear.locked = true;
|
||||||
|
|||||||
@@ -27,6 +27,15 @@ function pathExistsInArray (array, path) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkForNullEntries (array) {
|
||||||
|
return array.filter(e => Boolean(e));
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkPinnedAreasForNullEntries (user) {
|
||||||
|
user.pinnedItems = checkForNullEntries(user.pinnedItems);
|
||||||
|
user.unpinnedItems = checkForNullEntries(user.unpinnedItems);
|
||||||
|
}
|
||||||
|
|
||||||
function selectGearToPin (user) {
|
function selectGearToPin (user) {
|
||||||
let changes = [];
|
let changes = [];
|
||||||
|
|
||||||
@@ -41,11 +50,10 @@ function selectGearToPin (user) {
|
|||||||
return sortBy(changes, (change) => sortOrder[change.type]);
|
return sortBy(changes, (change) => sortOrder[change.type]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function addPinnedGear (user, type, path) {
|
function addPinnedGear (user, type, path) {
|
||||||
const foundIndex = pathExistsInArray(user.pinnedItems, path);
|
const foundIndex = pathExistsInArray(user.pinnedItems, path);
|
||||||
|
|
||||||
if (foundIndex === -1) {
|
if (foundIndex === -1 && type && path) {
|
||||||
user.pinnedItems.push({
|
user.pinnedItems.push({
|
||||||
type,
|
type,
|
||||||
path,
|
path,
|
||||||
@@ -176,5 +184,6 @@ module.exports = {
|
|||||||
togglePinnedItem,
|
togglePinnedItem,
|
||||||
removeItemByPath,
|
removeItemByPath,
|
||||||
selectGearToPin,
|
selectGearToPin,
|
||||||
|
checkPinnedAreasForNullEntries,
|
||||||
isPinned,
|
isPinned,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user