From c7c7d0d781814313488cc936ee80c3cab11a37ec Mon Sep 17 00:00:00 2001 From: Tony Date: Mon, 14 Oct 2024 14:26:46 +0200 Subject: [PATCH] feat(web): hide consumption toggle behind ff (#7314) * feat(web): hide consumption toggle behind ff * tests(web): update cypress tests to have atom context --- web/src/App.tsx | 13 ++- .../features/map-controls/MapControls.cy.tsx | 99 ++++++++++------- web/src/features/map-controls/MapControls.tsx | 5 +- .../features/map-controls/ZoomControls.tsx | 5 +- web/src/features/modals/SettingsModal.cy.tsx | 105 ++++++++++-------- web/src/features/modals/SettingsModal.tsx | 5 +- 6 files changed, 138 insertions(+), 94 deletions(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index b5e08d33fd..21a0aa1f7e 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -8,15 +8,18 @@ import { AppStoreBanner } from 'components/AppStoreBanner'; import LoadingOverlay from 'components/LoadingOverlay'; import { OnboardingModal } from 'components/modals/OnboardingModal'; import ErrorComponent from 'features/error-boundary/ErrorBoundary'; +import { useFeatureFlag } from 'features/feature-flags/api'; import Header from 'features/header/Header'; import UpdatePrompt from 'features/service-worker/UpdatePrompt'; import { useDarkMode } from 'hooks/theme'; import { useGetCanonicalUrl } from 'hooks/useGetCanonicalUrl'; +import { useSetAtom } from 'jotai'; import { lazy, ReactElement, Suspense, useEffect, useLayoutEffect } from 'react'; import { Helmet } from 'react-helmet-async'; import { useTranslation } from 'react-i18next'; import trackEvent from 'utils/analytics'; -import { metaTitleSuffix, TrackEvent } from 'utils/constants'; +import { metaTitleSuffix, Mode, TrackEvent } from 'utils/constants'; +import { productionConsumptionAtom } from 'utils/state/atoms'; const MapWrapper = lazy(async () => import('features/map/MapWrapper')); const LeftPanel = lazy(async () => import('features/panels/LeftPanel')); @@ -46,6 +49,14 @@ export default function App(): ReactElement { const shouldUseDarkMode = useDarkMode(); const { t, i18n } = useTranslation(); const canonicalUrl = useGetCanonicalUrl(); + const setConsumptionAtom = useSetAtom(productionConsumptionAtom); + const isConsumptionOnlyMode = useFeatureFlag('consumption-only'); + + useEffect(() => { + if (isConsumptionOnlyMode) { + setConsumptionAtom(Mode.CONSUMPTION); + } + }, [isConsumptionOnlyMode, setConsumptionAtom]); // Update classes on theme change useLayoutEffect(() => { diff --git a/web/src/features/map-controls/MapControls.cy.tsx b/web/src/features/map-controls/MapControls.cy.tsx index b013ee6d66..7c80efb6a8 100644 --- a/web/src/features/map-controls/MapControls.cy.tsx +++ b/web/src/features/map-controls/MapControls.cy.tsx @@ -1,49 +1,66 @@ +import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { I18nextProvider } from 'react-i18next'; import i18n from 'translation/i18n'; import MapControls from './MapControls'; -it('can change language', () => { - cy.viewport(800, 500); - cy.mount( - - - - ); - cy.get('[data-test-id=language-selector-open-button]').click(); - cy.contains('English').click(); - cy.contains('country'); - cy.contains('zone'); - cy.contains('production'); - cy.contains('consumption'); - cy.get('[data-test-id=language-selector-open-button]').click(); - cy.contains('Deutsch').click(); - cy.contains('Produktion'); - cy.contains('Verbrauch'); - cy.get('[data-test-id=language-selector-open-button]').click(); - cy.contains('Svenska').click(); - cy.contains('produktion'); - cy.contains('konsumtion'); - cy.contains('land'); - cy.contains('zon'); - cy.get('[data-test-id=language-selector-open-button]').click(); - cy.contains('English').click(); -}); +describe('MapControls', () => { + const queryClient = new QueryClient(); -it('can change theme', () => { - cy.viewport(800, 500); - cy.mount(); - cy.get('[data-test-id=theme-selector-open-button]').click(); - cy.contains('System'); - cy.contains('Light') - .click() - .should(() => { - expect(localStorage.getItem('theme')).to.eq('"light"'); - }); - cy.get('[data-test-id=theme-selector-open-button]').click(); - cy.contains('Dark') - .click() - .should(() => { - expect(localStorage.getItem('theme')).to.eq('"dark"'); + beforeEach(() => { + cy.intercept('/feature-flags', { + body: { 'consumption-only': false }, }); + }); + + it('can change language', () => { + cy.viewport(800, 500); + cy.mount( + + + + + + ); + cy.get('[data-test-id=language-selector-open-button]').click(); + cy.contains('English').click(); + cy.contains('country'); + cy.contains('zone'); + cy.contains('production'); + cy.contains('consumption'); + cy.get('[data-test-id=language-selector-open-button]').click(); + cy.contains('Deutsch').click(); + cy.contains('Produktion'); + cy.contains('Verbrauch'); + cy.get('[data-test-id=language-selector-open-button]').click(); + cy.contains('Svenska').click(); + cy.contains('produktion'); + cy.contains('konsumtion'); + cy.contains('land'); + cy.contains('zon'); + cy.get('[data-test-id=language-selector-open-button]').click(); + cy.contains('English').click(); + }); + + it('can change theme', () => { + cy.viewport(800, 500); + cy.mount( + + + + ); + cy.get('[data-test-id=theme-selector-open-button]').click(); + cy.contains('System'); + cy.contains('Light') + .click() + .should(() => { + expect(localStorage.getItem('theme')).to.eq('"light"'); + }); + cy.get('[data-test-id=theme-selector-open-button]').click(); + cy.contains('Dark') + .click() + .should(() => { + expect(localStorage.getItem('theme')).to.eq('"dark"'); + }); + }); }); diff --git a/web/src/features/map-controls/MapControls.tsx b/web/src/features/map-controls/MapControls.tsx index 74ccd411e4..f9d83f39ff 100644 --- a/web/src/features/map-controls/MapControls.tsx +++ b/web/src/features/map-controls/MapControls.tsx @@ -1,3 +1,4 @@ +import { useFeatureFlag } from 'features/feature-flags/api'; import { useAtom, useAtomValue } from 'jotai'; import { EyeOff, Sun, Wind } from 'lucide-react'; import { useTransition } from 'react'; @@ -112,10 +113,12 @@ function DesktopMapControls() { trackEvent(TrackEvent.COLORBLIND_MODE_TOGGLED); }; + const isConsumptionOnlyMode = useFeatureFlag('consumption-only'); + return (
- + {!isConsumptionOnlyMode && }
diff --git a/web/src/features/map-controls/ZoomControls.tsx b/web/src/features/map-controls/ZoomControls.tsx index fc577dc8b1..f9e55ce538 100644 --- a/web/src/features/map-controls/ZoomControls.tsx +++ b/web/src/features/map-controls/ZoomControls.tsx @@ -1,12 +1,15 @@ +import { useFeatureFlag } from 'features/feature-flags/api'; import { ReactElement } from 'react'; import { NavigationControl } from 'react-map-gl/maplibre'; export default function ZoomControls(): ReactElement { + const isConsumptionOnlyMode = useFeatureFlag('consumption-only'); + const marginTop = isConsumptionOnlyMode ? 54 : 98; return ( { - cy.viewport(500, 500); - cy.mount( - - - - ); - cy.contains('Wind data is currently unavailable'); - cy.contains('Solar data is currently unavailable'); - cy.get('[data-test-id=language-selector-open-button]').click(); - cy.contains('English').click(); - cy.contains('country'); - cy.contains('zone'); - cy.contains('production'); - cy.contains('consumption'); - cy.get('[data-test-id=language-selector-open-button]').click(); - cy.contains('Deutsch').click(); - cy.contains('Produktion'); - cy.contains('Verbrauch'); - cy.get('[data-test-id=language-selector-open-button]').click(); - cy.contains('Svenska').click(); - cy.contains('produktion'); - cy.contains('konsumtion'); - cy.contains('land'); - cy.contains('zon'); - cy.get('[data-test-id=language-selector-open-button]').click(); - cy.contains('English').click(); -}); +describe('SettingsModalContent', () => { + const queryClient = new QueryClient(); + + it('can change language', () => { + cy.viewport(500, 500); + cy.mount( + + + + + + ); + cy.contains('Wind data is currently unavailable'); + cy.contains('Solar data is currently unavailable'); + cy.get('[data-test-id=language-selector-open-button]').click(); + cy.contains('English').click(); + cy.contains('country'); + cy.contains('zone'); + cy.contains('production'); + cy.contains('consumption'); + cy.get('[data-test-id=language-selector-open-button]').click(); + cy.contains('Deutsch').click(); + cy.contains('Produktion'); + cy.contains('Verbrauch'); + cy.get('[data-test-id=language-selector-open-button]').click(); + cy.contains('Svenska').click(); + cy.contains('produktion'); + cy.contains('konsumtion'); + cy.contains('land'); + cy.contains('zon'); + cy.get('[data-test-id=language-selector-open-button]').click(); + cy.contains('English').click(); + }); -it('can change theme', () => { - cy.viewport(500, 500); - cy.mount( - - - - ); - cy.get('[data-test-id=theme-selector-open-button]').click(); - cy.contains('System'); - cy.contains('Light') - .click() - .should(() => { - expect(localStorage.getItem('theme')).to.eq('"light"'); - }); - cy.get('[data-test-id=theme-selector-open-button]').click(); - cy.contains('Dark') - .click() - .should(() => { - expect(localStorage.getItem('theme')).to.eq('"dark"'); - }); + it('can change theme', () => { + cy.viewport(500, 500); + cy.mount( + + + + + + ); + cy.get('[data-test-id=theme-selector-open-button]').click(); + cy.contains('System'); + cy.contains('Light') + .click() + .should(() => { + expect(localStorage.getItem('theme')).to.eq('"light"'); + }); + cy.get('[data-test-id=theme-selector-open-button]').click(); + cy.contains('Dark') + .click() + .should(() => { + expect(localStorage.getItem('theme')).to.eq('"dark"'); + }); + }); }); diff --git a/web/src/features/modals/SettingsModal.tsx b/web/src/features/modals/SettingsModal.tsx index aa76c51224..82c6d64d64 100644 --- a/web/src/features/modals/SettingsModal.tsx +++ b/web/src/features/modals/SettingsModal.tsx @@ -1,5 +1,6 @@ import { Button } from 'components/Button'; import Modal from 'components/Modal'; +import { useFeatureFlag } from 'features/feature-flags/api'; import ConsumptionProductionToggle from 'features/map-controls/ConsumptionProductionToggle'; import { LanguageSelector } from 'features/map-controls/LanguageSelector'; import { weatherButtonMap } from 'features/map-controls/MapControls'; @@ -67,12 +68,12 @@ export function SettingsModalContent() { const areWeatherLayersAllowed = useAtomValue(areWeatherLayersAllowedAtom); const [isColorblindModeEnabled, setIsColorblindModeEnabled] = useAtom(colorblindModeAtom); - + const isConsumptionOnlyMode = useFeatureFlag('consumption-only'); const { t } = useTranslation(); return (
- + {!isConsumptionOnlyMode && }