From 57dffb474b3c956dfa28a04de4a973729191bf0b Mon Sep 17 00:00:00 2001 From: Sperling-0 Date: Tue, 17 Dec 2024 15:19:31 +0100 Subject: [PATCH] Prepare VAR for C24_WMDE_Desktop_DE_22 Ticket: https://phabricator.wikimedia.org/T382301 --- .../C24_WMDE_Desktop_DE_22/banner_var.ts | 2 +- .../components/BannerVar.vue | 180 ++++++++++++++++++ .../content/BannerSlidesVar.vue | 48 +++++ .../content/BannerTextVar.vue | 32 ++++ .../components/BannerVar.spec.ts | 178 +++++++++++++++++ 5 files changed, 439 insertions(+), 1 deletion(-) create mode 100644 banners/desktop/C24_WMDE_Desktop_DE_22/components/BannerVar.vue create mode 100644 banners/desktop/C24_WMDE_Desktop_DE_22/content/BannerSlidesVar.vue create mode 100644 banners/desktop/C24_WMDE_Desktop_DE_22/content/BannerTextVar.vue create mode 100644 test/banners/desktop/C24_WMDE_Desktop_DE_22/components/BannerVar.spec.ts diff --git a/banners/desktop/C24_WMDE_Desktop_DE_22/banner_var.ts b/banners/desktop/C24_WMDE_Desktop_DE_22/banner_var.ts index 4c1e2ca7c..c49bfc19d 100644 --- a/banners/desktop/C24_WMDE_Desktop_DE_22/banner_var.ts +++ b/banners/desktop/C24_WMDE_Desktop_DE_22/banner_var.ts @@ -3,7 +3,7 @@ import { createVueApp } from '@src/createVueApp'; import './styles/styles.scss'; import BannerConductor from '@src/components/BannerConductor/FallbackBannerConductor.vue'; -import Banner from './components/BannerCtrl.vue'; +import Banner from './components/BannerVar.vue'; import FallbackBanner from './components/FallbackBanner.vue'; import { UrlRuntimeEnvironment } from '@src/utils/RuntimeEnvironment'; import { WindowResizeHandler } from '@src/utils/ResizeHandler'; diff --git a/banners/desktop/C24_WMDE_Desktop_DE_22/components/BannerVar.vue b/banners/desktop/C24_WMDE_Desktop_DE_22/components/BannerVar.vue new file mode 100644 index 000000000..3ea4476b2 --- /dev/null +++ b/banners/desktop/C24_WMDE_Desktop_DE_22/components/BannerVar.vue @@ -0,0 +1,180 @@ + + + diff --git a/banners/desktop/C24_WMDE_Desktop_DE_22/content/BannerSlidesVar.vue b/banners/desktop/C24_WMDE_Desktop_DE_22/content/BannerSlidesVar.vue new file mode 100644 index 000000000..991443c11 --- /dev/null +++ b/banners/desktop/C24_WMDE_Desktop_DE_22/content/BannerSlidesVar.vue @@ -0,0 +1,48 @@ + + + diff --git a/banners/desktop/C24_WMDE_Desktop_DE_22/content/BannerTextVar.vue b/banners/desktop/C24_WMDE_Desktop_DE_22/content/BannerTextVar.vue new file mode 100644 index 000000000..e7280312f --- /dev/null +++ b/banners/desktop/C24_WMDE_Desktop_DE_22/content/BannerTextVar.vue @@ -0,0 +1,32 @@ + + + diff --git a/test/banners/desktop/C24_WMDE_Desktop_DE_22/components/BannerVar.spec.ts b/test/banners/desktop/C24_WMDE_Desktop_DE_22/components/BannerVar.spec.ts new file mode 100644 index 000000000..0b033258b --- /dev/null +++ b/test/banners/desktop/C24_WMDE_Desktop_DE_22/components/BannerVar.spec.ts @@ -0,0 +1,178 @@ +import { beforeEach, describe, test, vi } from 'vitest'; +import { mount, VueWrapper } from '@vue/test-utils'; +import Banner from '@banners/desktop/C24_WMDE_Desktop_DE_22/components/BannerVar.vue'; +import { BannerStates } from '@src/components/BannerConductor/StateMachine/BannerStates'; +import { newDynamicContent } from '@test/banners/dynamicCampaignContent'; +import { useOfFundsContent } from '@test/banners/useOfFundsContent'; +import { formItems } from '@test/banners/formItems'; +import { CurrencyEn } from '@src/utils/DynamicContent/formatters/CurrencyEn'; +import { useOfFundsFeatures } from '@test/features/UseOfFunds'; +import { + bannerContentAnimatedTextFeatures, + bannerContentDateAndTimeFeatures, + bannerContentDisplaySwitchFeatures, + bannerContentFeatures +} from '@test/features/BannerContent'; +import { donationFormFeatures } from '@test/features/forms/MainDonation_UpgradeToYearlyButton'; +import { useFormModel } from '@src/components/composables/useFormModel'; +import { resetFormModel } from '@test/resetFormModel'; +import { DynamicContent } from '@src/utils/DynamicContent/DynamicContent'; +import { bannerAutoHideFeatures, bannerMainFeatures } from '@test/features/MainBanner'; +import { formActionSwitchFeatures } from '@test/features/form_action_switch/MainDonation_UpgradeToYearlyButton'; +import { softCloseFeatures } from '@test/features/SoftCloseDesktop'; +import { alreadyDonatedModalFeatures } from '@test/features/AlreadyDonatedModal'; +import { softCloseSubmitTrackingFeaturesDesktop } from '@test/features/SoftCloseSubmitTrackingDesktop'; +import { Tracker } from '@src/tracking/Tracker'; +import { TimerStub } from '@test/fixtures/TimerStub'; +import { Timer } from '@src/utils/Timer'; + +const formModel = useFormModel(); +const translator = ( key: string ): string => key; +let tracker: Tracker; + +describe( 'BannerVar.vue', () => { + + beforeEach( () => { + resetFormModel( formModel ); + tracker = { + trackEvent: vi.fn() + }; + } ); + + const getWrapper = ( dynamicContent: DynamicContent = null, timer: Timer = null ): VueWrapper => { + return mount( Banner, { + attachTo: document.body, + props: { + bannerState: BannerStates.Pending, + useOfFundsContent, + remainingImpressions: 10, + localCloseTracker: { + getItem: () => '', + setItem: () => {} + } + }, + global: { + mocks: { + $translate: translator + }, + provide: { + translator: { translate: translator }, + dynamicCampaignText: dynamicContent ?? newDynamicContent(), + currentCampaignTimePercentage: 42, + formActions: { + donateWithAddressAction: 'https://example.com/with-address', + donateAnonymouslyAction: 'https://example.com/without-address' + }, + currencyFormatter: new CurrencyEn(), + formItems, + tracker, + timer: timer ?? new TimerStub() + } + } + } ); + }; + + describe( 'Main Banner', () => { + test.each( [ + [ 'expectDoesNotEmitCloseEvent' ] + ] )( '%s', async ( testName: string ) => { + await bannerMainFeatures[ testName ]( getWrapper() ); + } ); + + test.each( [ + [ 'expectClosesBannerWhenWindowBecomesSmall' ] + ] )( '%s', async ( testName: string ) => { + await bannerAutoHideFeatures[ testName ]( getWrapper ); + } ); + } ); + + describe( 'Content', () => { + test.each( [ + [ 'expectSlideShowPlaysWhenBecomesVisible' ], + [ 'expectSlideShowStopsOnFormInteraction' ] + ] )( '%s', async ( testName: string ) => { + await bannerContentFeatures[ testName ]( getWrapper() ); + } ); + + test.each( [ + [ 'expectShowsSlideShowOnSmallSizes' ], + [ 'expectShowsMessageOnLargeSizes' ] + ] )( '%s', async ( testName: string ) => { + await bannerContentDisplaySwitchFeatures[ testName ]( getWrapper, 1300 ); + } ); + + test.each( [ + [ 'expectShowsAnimatedVisitorsVsDonorsSentenceInMessage' ], + [ 'expectShowsAnimatedVisitorsVsDonorsSentenceInSlideShow' ] + ] )( '%s', async ( testName: string ) => { + await bannerContentAnimatedTextFeatures[ testName ]( getWrapper ); + } ); + + test.each( [ + [ 'expectShowsLiveDateAndTimeInTitle' ] + ] )( '%s', async ( testName: string ) => { + await bannerContentDateAndTimeFeatures[ testName ]( getWrapper ); + } ); + } ); + + describe( 'Donation Form Happy Paths', () => { + test.each( [ + [ 'expectMainDonationFormSubmitsWhenSofortIsSelected' ], + [ 'expectMainDonationFormSubmitsWhenYearlyIsSelected' ], + [ 'expectMainDonationFormGoesToUpgrade' ], + [ 'expectUpgradeToYearlyFormSubmitsUpgrade' ], + [ 'expectUpgradeToYearlyFormSubmitsDontUpgrade' ] + ] )( '%s', async ( testName: string ) => { + await donationFormFeatures[ testName ]( getWrapper() ); + } ); + + test.each( [ + [ 'expectMainDonationFormSubmitsWithAddressForDirectDebit' ], + [ 'expectMainDonationFormSubmitsWithAddressForPayPal' ], + [ 'expectUpgradeToYearlyFormSubmitsWithAddressForDirectDebit' ], + [ 'expectUpgradeToYearlyFormSubmitsWithAddressForPayPal' ] + ] )( '%s', async ( testName: string ) => { + await formActionSwitchFeatures[ testName ]( getWrapper() ); + } ); + } ); + + describe( 'Soft Close', () => { + test.each( [ + [ 'expectShowsSoftClose' ], + [ 'expectEmitsSoftCloseCloseEvent' ], + [ 'expectEmitsSoftCloseMaybeLaterEvent' ], + [ 'expectEmitsSoftCloseTimeOutEvent' ], + [ 'expectEmitsBannerContentChangedOnSoftClose' ], + [ 'expectShowsCloseIcon' ], + [ 'expectCloseIconEmitsCloseEvent' ] + ] )( '%s', async ( testName: string ) => { + await softCloseFeatures[ testName ]( getWrapper ); + } ); + } ); + + describe( 'Soft Close Submit Tracking', () => { + test.each( [ + [ 'expectEmitsBannerSubmitOnReturnEvent' ], + [ 'expectDoesNotEmitsBannerSubmitOnReturnEventWhenLocalStorageItemIsMissing' ] + ] )( '%s', async ( testName: string ) => { + await softCloseSubmitTrackingFeaturesDesktop[ testName ]( getWrapper(), tracker ); + } ); + } ); + + describe( 'Already Donated', () => { + test.each( [ + [ 'expectFiresMaybeLaterEventOnLinkClick' ] + ] )( '%s', async ( testName: string ) => { + await alreadyDonatedModalFeatures[ testName ]( getWrapper() ); + } ); + } ); + + describe( 'Use of Funds', () => { + test.each( [ + [ 'expectShowsUseOfFunds' ], + [ 'expectHidesUseOfFunds' ] + ] )( '%s', async ( testName: string ) => { + await useOfFundsFeatures[ testName ]( getWrapper() ); + } ); + } ); +} );