Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 5 additions & 21 deletions packages/shared/src/components/feeds/MobileFeedActions.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import type { ReactElement } from 'react';
import React from 'react';
import { QueryClient } from '@tanstack/react-query';
import { GrowthBook } from '@growthbook/growthbook';
import { render, screen } from '@testing-library/react';
import loggedUser from '../../../__tests__/fixture/loggedUser';
import { TestBootProvider } from '../../../__tests__/helpers/boot';
import { useReadingStreak } from '../../hooks/streaks';
import { MobileFeedActions } from './MobileFeedActions';

const mockQuestButton = jest.fn(
(): ReactElement => <div data-testid="quest-button">Quest button</div>,
);
const mockQuestButton = jest.fn<ReactElement, [{ compact?: boolean }]>(() => (
<div data-testid="quest-button">Quest button</div>
));

jest.mock('next/dynamic', () => () => {
return function MockDynamicComponent() {
Expand Down Expand Up @@ -58,31 +57,16 @@ jest.mock('../quest/QuestButton', () => ({

const mockUseReadingStreak = useReadingStreak as jest.Mock;

const getGrowthBook = (isQuestsFeatureEnabled = true): GrowthBook => {
const gb = new GrowthBook();

gb.setFeatures({
quests: {
defaultValue: isQuestsFeatureEnabled,
},
});

return gb;
};

const renderComponent = ({
optOutQuestSystem = false,
isQuestsFeatureEnabled = true,
}: {
optOutQuestSystem?: boolean;
isQuestsFeatureEnabled?: boolean;
} = {}) =>
render(
<TestBootProvider
client={new QueryClient()}
auth={{ user: loggedUser }}
settings={{ optOutQuestSystem }}
gb={getGrowthBook(isQuestsFeatureEnabled)}
>
<MobileFeedActions />
</TestBootProvider>,
Expand All @@ -99,7 +83,7 @@ describe('MobileFeedActions', () => {
});

it('should render the quest entry next to the streak button', () => {
renderComponent({ optOutQuestSystem: false, isQuestsFeatureEnabled: true });
renderComponent({ optOutQuestSystem: false });

const actionButtons = screen.getAllByTestId(/^(streak|quest)-button$/);

Expand All @@ -112,7 +96,7 @@ describe('MobileFeedActions', () => {
});

it('should hide the quest entry when opted out from quests', () => {
renderComponent({ optOutQuestSystem: true, isQuestsFeatureEnabled: true });
renderComponent({ optOutQuestSystem: true });

expect(screen.queryByTestId('quest-button')).not.toBeInTheDocument();
});
Expand Down
14 changes: 1 addition & 13 deletions packages/shared/src/components/header/QuestHeaderButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import type { ReactElement } from 'react';
import React from 'react';
import { useAuthContext } from '../../contexts/AuthContext';
import { useSettingsContext } from '../../contexts/SettingsContext';
import { useConditionalFeature } from '../../hooks/useConditionalFeature';
import { questsFeature } from '../../lib/featureManagement';
import { QuestButton } from '../quest/QuestButton';

interface QuestHeaderButtonProps {
Expand All @@ -15,18 +13,8 @@ export function QuestHeaderButton({
}: QuestHeaderButtonProps): ReactElement | null {
const { isLoggedIn, isAuthReady } = useAuthContext();
const { loadedSettings, optOutQuestSystem } = useSettingsContext();
const { value: isQuestsFeatureEnabled } = useConditionalFeature({
feature: questsFeature,
shouldEvaluate: isLoggedIn,
});

if (
!isAuthReady ||
!loadedSettings ||
!isLoggedIn ||
isQuestsFeatureEnabled !== true ||
optOutQuestSystem
) {
if (!isAuthReady || !loadedSettings || !isLoggedIn || optOutQuestSystem) {
return null;
}

Expand Down
31 changes: 3 additions & 28 deletions packages/shared/src/components/layout/HeaderButtons.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { ReactElement } from 'react';
import React from 'react';
import { QueryClient } from '@tanstack/react-query';
import { render, screen } from '@testing-library/react';
import { GrowthBook } from '@growthbook/growthbook-react';
import { TestBootProvider } from '../../../__tests__/helpers/boot';
import { HeaderButtons } from './HeaderButtons';

Expand Down Expand Up @@ -34,53 +33,29 @@ jest.mock('../quest/QuestButton', () => ({
QuestButton: (): ReactElement => <div>Quest button</div>,
}));

const getGrowthBook = (isQuestsFeatureEnabled = true): GrowthBook => {
const gb = new GrowthBook();

gb.setFeatures({
quests: {
defaultValue: isQuestsFeatureEnabled,
},
});

return gb;
};

const renderComponent = ({
optOutQuestSystem = false,
isQuestsFeatureEnabled = true,
}: {
optOutQuestSystem?: boolean;
isQuestsFeatureEnabled?: boolean;
} = {}) =>
render(
<TestBootProvider
client={new QueryClient()}
settings={{ optOutQuestSystem }}
gb={getGrowthBook(isQuestsFeatureEnabled)}
>
<HeaderButtons />
</TestBootProvider>,
);

describe('HeaderButtons', () => {
it('should render the quest entry when quest experiment is enabled', () => {
renderComponent({ optOutQuestSystem: false, isQuestsFeatureEnabled: true });
it('should render the quest entry for logged-in users', () => {
renderComponent({ optOutQuestSystem: false });

expect(screen.getByText('Quest button')).toBeInTheDocument();
});

it('should hide the quest entry when opted out from quests', () => {
renderComponent({ optOutQuestSystem: true, isQuestsFeatureEnabled: true });

expect(screen.queryByText('Quest button')).not.toBeInTheDocument();
});

it('should hide the quest entry when quest experiment is disabled', () => {
renderComponent({
optOutQuestSystem: false,
isQuestsFeatureEnabled: false,
});
renderComponent({ optOutQuestSystem: true });

expect(screen.queryByText('Quest button')).not.toBeInTheDocument();
});
Expand Down
28 changes: 3 additions & 25 deletions packages/shared/src/components/profile/ProfileSettingsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ import { VolunteeringIcon } from '../icons/Volunteering';
import { GraduationIcon } from '../icons/Graduation';
import { MedalBadgeIcon } from '../icons/MedalBadge';
import { MedalIcon } from '../icons/Medal';
import { questsFeature } from '../../lib/featureManagement';
import { useConditionalFeature } from '../../hooks/useConditionalFeature';

type MenuItems = Record<
string,
Expand All @@ -87,11 +85,6 @@ const useAccountPageItems = ({ onClose }: { onClose?: () => void } = {}) => {
const { logEvent } = useLogContext();
const { user } = useAuthContext();

const { value: isQuestsFeatureEnabled } = useConditionalFeature({
feature: questsFeature,
shouldEvaluate: !!user,
});

const items = useMemo(
() =>
defineMenuItems({
Expand Down Expand Up @@ -347,7 +340,7 @@ const useAccountPageItems = ({ onClose }: { onClose?: () => void } = {}) => {
[logEvent, onClose, openModal, user?.username],
);

return { items, isQuestsFeatureEnabled };
return { items };
};

interface ProfileSettingsMenuProps {
Expand All @@ -363,8 +356,7 @@ export const InnerProfileSettingsMenu = ({
const { asPath } = useRouter();
const isMobile = useViewSize(ViewSize.MobileL);
const hasAccessToCores = useHasAccessToCores();
const { items: accountPageItems, isQuestsFeatureEnabled } =
useAccountPageItems({ onClose });
const { items: accountPageItems } = useAccountPageItems({ onClose });

return (
<nav className={classNames('flex flex-col gap-2', className)}>
Expand All @@ -377,25 +369,11 @@ export const InnerProfileSettingsMenu = ({
withSeparator={!lastItem}
title={menuItem.title ?? undefined}
items={Object.entries(menuItem.items)
.filter(([itemKey, item]) => {
.filter(([, item]) => {
if (item.href === walletUrl && !hasAccessToCores) {
return false;
}

if (
itemKey === 'gamification' &&
isQuestsFeatureEnabled !== true
) {
return false;
}

if (
itemKey === 'gameCenter' &&
isQuestsFeatureEnabled !== true
) {
return false;
}

return true;
})
.map(([, item]: [string, ProfileSectionItemProps]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
gameCenterMilestoneSectionId,
webappUrl,
} from '../../../lib/constants';
import { questsFeature } from '../../../lib/featureManagement';
import { useConditionalFeature } from '../../../hooks';
import useCustomDefaultFeed from '../../../hooks/feed/useCustomDefaultFeed';
import { useQuestDashboard } from '../../../hooks/useQuestDashboard';
Expand Down Expand Up @@ -64,10 +63,10 @@ describe('MainSection', () => {
},
isLoggedIn: true,
});
mockUseConditionalFeature.mockImplementation(({ feature }) => ({
value: feature === questsFeature,
mockUseConditionalFeature.mockReturnValue({
value: false,
isLoading: false,
}));
});
mockUseCustomDefaultFeed.mockReturnValue({
isCustomDefaultFeed: false,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { useConditionalFeature } from '../../../hooks';
import {
featurePlusApiLanding,
featureYearInReview,
questsFeature,
} from '../../../lib/featureManagement';
import { useQuestDashboard } from '../../../hooks/useQuestDashboard';
import { Typography, TypographyColor } from '../../typography/Typography';
Expand All @@ -53,10 +52,6 @@ export const MainSection = ({
feature: featureYearInReview,
shouldEvaluate: isLoggedIn,
});
const { value: showGameCenter } = useConditionalFeature({
feature: questsFeature,
shouldEvaluate: isLoggedIn,
});
const { data: questDashboard } = useQuestDashboard();
const claimableMilestoneCount = useMemo(
() =>
Expand Down Expand Up @@ -115,7 +110,7 @@ export const MainSection = ({
claimableMilestoneCount > 0 ? `#${gameCenterMilestoneSectionId}` : ''
}`;

const gameCenter = showGameCenter
const gameCenter = isLoggedIn
? {
icon: (active: boolean) => (
<ListIcon Icon={() => <JoystickIcon secondary={active} />} />
Expand Down Expand Up @@ -202,7 +197,6 @@ export const MainSection = ({
isLoggedIn,
isPlus,
onNavTabClick,
showGameCenter,
showYearInReview,
user,
]);
Expand Down
2 changes: 0 additions & 2 deletions packages/shared/src/lib/featureManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ export const featureProfileCompletionIndicator = new Feature(
0,
);

export const questsFeature = new Feature('quests', false);

export const achievementTrackingWidgetFeature = new Feature(
'achievement_tracking_widget',
false,
Expand Down
Loading
Loading