@automattic/newspack-blocks 2.6.2 → 3.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/.cache/babel/135eb7c6e583be53418b26a29fcc4d81.json.gz +0 -0
  2. package/.cache/babel/2bec24377bb9890c2268bcd4c8f3953c.json.gz +0 -0
  3. package/.cache/babel/9ba57ee86df44178ceb255eaf0e770e3.json.gz +0 -0
  4. package/.cache/babel/a804bf1963e56137e59e37a567cb5e2e.json.gz +0 -0
  5. package/.cache/babel/b94e6dc0852876a37bd23ec88c5b2583.json.gz +0 -0
  6. package/.cache/babel/c04d2af94bb0f10f408a15534301cc86.json.gz +0 -0
  7. package/.cache/babel/c8d4b9ae4be3002e8507d71f1136ebc6.json.gz +0 -0
  8. package/.cache/babel/d21f5515648ce2a2349b0ee5cc787fce.json.gz +0 -0
  9. package/.cache/babel/d3eee0c40fc44bc734dee21a645a4f7d.json.gz +0 -0
  10. package/.cache/babel/d661309b03e38954105e706a32ef09f6.json.gz +0 -0
  11. package/.cache/babel/e2dd36051554e75a2bf087b85c11e43d.json.gz +0 -0
  12. package/.hooks/pre-push +2 -2
  13. package/CHANGELOG.md +21 -0
  14. package/composer.lock +38 -36
  15. package/dist/donate/view.asset.php +1 -1
  16. package/dist/donate/view.css +1 -1
  17. package/dist/donate/view.rtl.css +1 -1
  18. package/dist/editor.asset.php +1 -1
  19. package/dist/editor.css +1 -1
  20. package/dist/editor.js +11 -11
  21. package/dist/editor.rtl.css +1 -1
  22. package/dist/frequencyBased.asset.php +1 -1
  23. package/dist/frequencyBased.css +1 -1
  24. package/dist/frequencyBased.rtl.css +1 -1
  25. package/dist/modalCheckout.asset.php +1 -1
  26. package/dist/modalCheckout.css +1 -1
  27. package/dist/modalCheckout.rtl.css +1 -1
  28. package/dist/tiersBased.asset.php +1 -1
  29. package/dist/tiersBased.css +1 -1
  30. package/dist/tiersBased.js +1 -1
  31. package/dist/tiersBased.rtl.css +1 -1
  32. package/includes/class-modal-checkout.php +11 -14
  33. package/includes/class-newspack-blocks.php +87 -43
  34. package/languages/newspack-blocks-de_DE.po +0 -40
  35. package/languages/newspack-blocks-es_ES.po +0 -40
  36. package/languages/newspack-blocks-fr_BE.po +0 -40
  37. package/languages/newspack-blocks-pt_PT.po +0 -40
  38. package/languages/newspack-blocks.pot +0 -38
  39. package/newspack-blocks.php +2 -14
  40. package/package.json +7 -8
  41. package/src/blocks/checkout-button/edit.js +5 -1
  42. package/src/blocks/donate/block.json +0 -12
  43. package/src/blocks/donate/edit/FrequencyBasedLayout.tsx +61 -106
  44. package/src/blocks/donate/edit/TierBasedLayout.tsx +7 -26
  45. package/src/blocks/donate/edit/components/index.tsx +0 -1
  46. package/src/blocks/donate/edit/index.tsx +157 -152
  47. package/src/blocks/donate/frequency-based/style.scss +5 -0
  48. package/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-base.php +33 -147
  49. package/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-frequency-based.php +21 -10
  50. package/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-tiers-based.php +3 -50
  51. package/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer.php +1 -14
  52. package/src/blocks/donate/styles/editor.scss +6 -28
  53. package/src/blocks/donate/styles/style-variations.scss +17 -8
  54. package/src/blocks/donate/styles/view.scss +9 -0
  55. package/src/blocks/donate/tiers-based/style.scss +0 -11
  56. package/src/blocks/donate/tiers-based/utils.test.js +38 -0
  57. package/src/blocks/donate/tiers-based/utils.ts +1 -2
  58. package/src/blocks/donate/tiers-based/view.ts +0 -33
  59. package/src/blocks/donate/types.ts +0 -16
  60. package/src/blocks/donate/utils.ts +31 -0
  61. package/src/blocks/homepage-articles/block.json +18 -0
  62. package/src/blocks/homepage-articles/class-wp-rest-newspack-articles-controller.php +1 -1
  63. package/src/blocks/homepage-articles/edit.js +3 -0
  64. package/src/blocks/homepage-articles/utils.ts +4 -0
  65. package/src/blocks/homepage-articles/view.php +4 -4
  66. package/src/components/query-controls.js +41 -8
  67. package/src/modal-checkout/checkout.scss +4 -5
  68. package/src/types/index.d.ts +4 -3
  69. package/vendor/autoload.php +1 -1
  70. package/vendor/composer/autoload_real.php +4 -4
  71. package/vendor/composer/autoload_static.php +2 -2
  72. package/vendor/composer/installed.php +2 -2
  73. package/webpack.config.js +0 -1
  74. package/.cache/babel/18dda1142078f066419138e7284f03bf.json.gz +0 -0
  75. package/.cache/babel/1f43960564787ebde7c6d44957cddf0e.json.gz +0 -0
  76. package/.cache/babel/225618337c609eed2be110274ff82be1.json.gz +0 -0
  77. package/.cache/babel/29d960d2fc51492a4bea1f4f165810fb.json.gz +0 -0
  78. package/.cache/babel/2f22325668b5763f8f2c9557833af36f.json.gz +0 -0
  79. package/.cache/babel/39bcc541624feefe54d1493493ae1ce8.json.gz +0 -0
  80. package/.cache/babel/4d450b37d365154f05b17cbf6a009255.json.gz +0 -0
  81. package/.cache/babel/87e2dc4a961b25b0de8d1a8ac88eea13.json.gz +0 -0
  82. package/.cache/babel/91884d41523f3790da70ea305ee187f2.json.gz +0 -0
  83. package/.cache/babel/b1ac90699e641ff99e1449b5d7b686e5.json.gz +0 -0
  84. package/.cache/babel/c5a441fdf7d90d45d2cbeb89967c61fe.json.gz +0 -0
  85. package/.cache/babel/c7cfb8590e887722a3e715c72ee99bac.json.gz +0 -0
  86. package/.cache/babel/e1d8932bb19afa36f476f107dbc6ca39.json.gz +0 -0
  87. package/.cache/babel/f60f8c23ec2b4448cb2815d79207d8c0.json.gz +0 -0
  88. package/dist/donateStreamlined.asset.php +0 -1
  89. package/dist/donateStreamlined.css +0 -1
  90. package/dist/donateStreamlined.js +0 -1
  91. package/dist/donateStreamlined.rtl.css +0 -1
  92. package/src/blocks/donate/class-wp-rest-newspack-donate-controller.php +0 -206
  93. package/src/blocks/donate/edit/components/AdditionalFields.tsx +0 -282
  94. package/src/blocks/donate/streamlined/index.test.js +0 -132
  95. package/src/blocks/donate/streamlined/index.ts +0 -356
  96. package/src/blocks/donate/streamlined/style.scss +0 -306
  97. package/src/blocks/donate/streamlined/utils.test.js +0 -18
  98. package/src/blocks/donate/streamlined/utils.ts +0 -217
  99. package/src/blocks/donate/tiers-based/view.test.js +0 -209
@@ -1,217 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { __, sprintf } from '@wordpress/i18n';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import type { DonationFormValues, DonationFormInputName, DonationSettings } from '../types';
10
-
11
- const isValidEmail = ( string: string ) => /\S+@\S+/.test( string );
12
-
13
- export const validateFormData = (
14
- values: DonationFormValues,
15
- settings: Partial< DonationSettings >
16
- ) => {
17
- const errors: { [ key: string ]: string } = {};
18
- if ( ! isValidEmail( values.email ) ) {
19
- errors.email = __( 'Email address is invalid.', 'newspack-blocks' );
20
- }
21
- const { minimumDonation } = settings;
22
- if ( minimumDonation && parseFloat( values.amount ) < minimumDonation ) {
23
- errors.amount = sprintf(
24
- /* Translators: %d is minimum donation amount set in Reader Revenue wizard or block attributes. */
25
- __( 'Amount must be at least %d.', 'newspack-blocks' ),
26
- minimumDonation
27
- );
28
- }
29
- if ( values.full_name.length === 0 ) {
30
- errors.amount = __( 'Full name should be provided.', 'newspack-blocks' );
31
- }
32
- return errors;
33
- };
34
-
35
- /**
36
- * Renders UI messages in a given DOM element.
37
- */
38
- export const renderMessages = (
39
- messages: ( string | undefined )[],
40
- el: HTMLElement,
41
- type = 'error'
42
- ) => {
43
- el.innerHTML = '';
44
- messages.forEach( message => {
45
- if ( ! message ) {
46
- return;
47
- }
48
- const messageEl = document.createElement( 'div' );
49
- messageEl.classList.add( `type-${ type }` );
50
- messageEl.innerHTML = message;
51
- el.appendChild( messageEl );
52
- } );
53
-
54
- if ( 'success' === type && el.parentElement ) {
55
- el.parentElement.replaceWith( el );
56
- }
57
- };
58
-
59
- const getCookies = () =>
60
- document.cookie.split( '; ' ).reduce< { [ key: string ]: string } >( ( acc, cookieStr ) => {
61
- const cookie = cookieStr.split( '=' );
62
- acc[ cookie[ 0 ] ] = cookie[ 1 ];
63
- return acc;
64
- }, {} );
65
-
66
- /**
67
- * Retrieves donation settings passed via a `data-streamlined-config` HTML attribute.
68
- */
69
- export const getSettings = ( el: HTMLElement ) => {
70
- const settingsElement: HTMLElement | null = el.closest( '[data-streamlined-config]' );
71
- const settings = settingsElement?.getAttribute( 'data-streamlined-config' );
72
- if ( ! settings ) {
73
- return {};
74
- }
75
- const [
76
- currency,
77
- currencySymbol,
78
- siteName,
79
- isCurrencyZeroDecimal,
80
- countryCode,
81
- frequencies,
82
- feeMultiplier,
83
- feeStatic,
84
- stripePublishableKey,
85
- paymentRequestType,
86
- captchaSiteKey,
87
- minimumDonation,
88
- ] = JSON.parse( settings );
89
- return {
90
- currency: currency.toLowerCase(),
91
- currencySymbol,
92
- siteName,
93
- isCurrencyZeroDecimal,
94
- countryCode,
95
- frequencies,
96
- feeMultiplier: parseFloat( feeMultiplier ),
97
- feeStatic: parseFloat( feeStatic ),
98
- stripePublishableKey,
99
- paymentRequestType,
100
- captchaSiteKey,
101
- minimumDonation: parseFloat( minimumDonation ),
102
- };
103
- };
104
-
105
- /**
106
- * Retrieves form values from the donation form HTML element.
107
- */
108
- export const getDonationFormValues = ( formElement: HTMLFormElement ): DonationFormValues => {
109
- const formValues = Object.fromEntries( new FormData( formElement ) ) as DonationFormValues;
110
- const valueKey: DonationFormInputName = `donation_value_${ formValues.donation_frequency }`;
111
- formValues.amount = formValues[ valueKey ];
112
- if ( formValues.amount === 'other' ) {
113
- formValues.amount = formValues[ `${ valueKey }_other` ];
114
- }
115
- if ( ! formValues.amount ) {
116
- formValues.amount = formValues[ `${ valueKey }_untiered` ];
117
- }
118
- if (
119
- formValues.cid &&
120
- typeof formValues.cid === 'string' &&
121
- formValues.cid.indexOf( 'CLIENT_ID' ) === 0
122
- ) {
123
- formValues.cid = getCookies()[ 'newspack-cid' ];
124
- }
125
- return formValues;
126
- };
127
-
128
- /**
129
- * Computes the total amount of the donation, taking into account if the
130
- * donor has opted to cover the processing fee.
131
- */
132
- export const getTotalAmount = (
133
- formElement: HTMLFormElement,
134
- // For the payment request button (Apple/Google Pay), the amount has to be
135
- // delivered in subunits.
136
- { convertToSubunit } = { convertToSubunit: false }
137
- ) => {
138
- const settings = getSettings( formElement );
139
- const { amount = '0', agree_to_pay_fees: paysFees } = getDonationFormValues( formElement );
140
-
141
- const processAmount = ( amountToProcess: number ) =>
142
- convertToSubunit
143
- ? amountToProcess * ( settings.isCurrencyZeroDecimal ? 1 : 100 )
144
- : amountToProcess;
145
-
146
- let feesAmount = 0;
147
- if ( paysFees ) {
148
- feesAmount = processAmount( getFeeAmount( formElement ) || 0 );
149
- }
150
- return processAmount( parseFloat( amount ) ) + feesAmount;
151
- };
152
-
153
- /**
154
- * Creates a `total` value for Stripe's `paymentRequest` creation and updating.
155
- */
156
- export const getPaymentRequestTotal = ( formElement: HTMLFormElement ) => {
157
- const settings = getSettings( formElement );
158
- const { donation_frequency: frequency } = getDonationFormValues( formElement );
159
- const frequencyLabel = settings.frequencies[ frequency ];
160
- return {
161
- label: `${ settings.siteName } (${ frequencyLabel })`,
162
- amount: getTotalAmount( formElement, { convertToSubunit: true } ),
163
- };
164
- };
165
-
166
- /**
167
- * Computes the fee amount.
168
- */
169
- export const computeFeeAmount = ( amount: number, feeMultiplier: number, feeStatic: number ) => {
170
- return parseFloat(
171
- ( ( ( amount + feeStatic ) / ( 100 - feeMultiplier ) ) * 100 - amount ).toFixed( 2 )
172
- );
173
- };
174
-
175
- /**
176
- * Given the donation form HTML element, computes the fee amount.
177
- */
178
- export const getFeeAmount = ( formElement: HTMLFormElement ) => {
179
- const { feeMultiplier, feeStatic } = getSettings( formElement );
180
- if (
181
- undefined === feeMultiplier ||
182
- undefined === feeStatic ||
183
- isNaN( feeMultiplier ) ||
184
- isNaN( feeStatic )
185
- ) {
186
- return 0;
187
- }
188
- const { amount } = getDonationFormValues( formElement );
189
- return computeFeeAmount( parseFloat( amount ), feeMultiplier, feeStatic );
190
- };
191
-
192
- export const sendAPIRequest = async ( endpoint: string, data: object, method = 'POST' ) =>
193
- fetch( `/wp-json/newspack-blocks/v1${ endpoint }`, {
194
- method,
195
- headers: {
196
- 'Content-Type': 'application/json',
197
- },
198
- body: JSON.stringify( data ),
199
- } ).then( async res => {
200
- const responseData = await res.json();
201
- if ( res.ok ) {
202
- return responseData;
203
- }
204
- return { error: responseData };
205
- } );
206
-
207
- export const renderSuccessMessageWithEmail = ( emailAddress: string, messagesEl: HTMLElement ) => {
208
- const successMessage = sprintf(
209
- /* Translators: %s is the email address of the current user. */
210
- __(
211
- 'Your payment has been processed. Thank you for your contribution! You will receive a confirmation email at %s.',
212
- 'newspack-blocks'
213
- ),
214
- emailAddress
215
- );
216
- renderMessages( [ successMessage ], messagesEl, 'success' );
217
- };
@@ -1,209 +0,0 @@
1
- import * as testingLibrary from '@testing-library/dom';
2
- import userEvent from '@testing-library/user-event';
3
- import { encode } from 'html-entities';
4
- import 'regenerator-runtime';
5
-
6
- import { processTiersBasedElements } from '.';
7
-
8
- const frequencies = { once: 'Once', month: 'Monthly', year: 'Annually' };
9
- const stripeSettings = [ 'USD', '$', 'Testing Site', false, 'US', frequencies, '2.9', '0.3' ];
10
- // These amounts contain the "once" frequency on last index, which is not used in the tiers-based block.
11
- const amounts = { once: [ 1, 2, 3, 4 ], month: [ 5, 6, 7, 8 ], year: [ 9, 10, 11, 12 ] };
12
- const TIERS = [
13
- {
14
- heading: 'Small',
15
- },
16
- {
17
- heading: 'Medium',
18
- },
19
- {
20
- heading: 'Large',
21
- },
22
- ];
23
- const MONTH_RENEWAL_DATE = 'December 16, 2022';
24
- const YEAR_RENEWAL_DATE = 'December 16, 2022';
25
- const COLOR = '#3366ff';
26
- const rawTiersBasedConfig = [
27
- 'donation_frequency',
28
- 'donation_value_',
29
- 'month',
30
- TIERS,
31
- amounts,
32
- MONTH_RENEWAL_DATE,
33
- YEAR_RENEWAL_DATE,
34
- true,
35
- COLOR,
36
- ];
37
-
38
- const createDOM = ( settings, tiersConfig ) => {
39
- const parentElement = document.createElement( 'div' );
40
- parentElement.innerHTML = `
41
- <style>.wpbnbd__tiers__view--hidden {display:none;}</style>
42
-
43
- <div
44
- class="wp-block-newspack-blocks-donate wpbnbd wpbnbd--tiers-based is-style-alternate wpbnbd-frequencies--2"
45
- data-streamlined-config="${ encode( JSON.stringify( settings ) ) }"
46
- data-tiers-based-config="${ encode( JSON.stringify( tiersConfig ) ) }"
47
- >
48
- <form data-is-init-form="" onsubmit="return false;">
49
- <div class="wpbnbd__tiers__view">
50
- <input type="hidden" name="newspack_donate" value="1">
51
- <input type="hidden" name="donation_frequency" value="month">
52
- <div class="wpbnbd__tiers">
53
- <div class="wpbnbd__tiers__selection">
54
- <button type="button" data-frequency-slug="month" data-frequency-label=" per month" class="wpbnbd__button wpbnbd__button--active">Monthly</button>
55
- <button type="button" data-frequency-slug="year" data-frequency-label=" per year" class="wpbnbd__button ">Annually</button>
56
- </div>
57
- <div class="wpbnbd__tiers__options">
58
- ${ TIERS.map(
59
- ( tier, index ) => `
60
- <div class="wpbnbd__tiers__tier ">
61
- <div class="wpbnbd__tiers__top">
62
- <h2 class="wpbnbd__tiers__heading">${ tier.heading }</h2>
63
- </div>
64
- <div class="wpbnbd__tiers__amount">
65
- <span>
66
- <span data-frequency-slug="month" data-amount="${ amounts.month[ index ] }" data-tier-index="${ index }">
67
- <h3 class="wpbnbd__tiers__amount__number">$${ amounts.month[ index ] }</h3>
68
- <span class="wpbnbd__tiers__amount__frequency"> per month</span>
69
- </span>
70
- <span style="display:none;" data-frequency-slug="year" data-amount="${ amounts.year[ index ] }" data-tier-index="${ index }">
71
- <h3 class="wpbnbd__tiers__amount__number">$${ amounts.year[ index ] }</h3>
72
- <span class="wpbnbd__tiers__amount__frequency"> per year</span>
73
- </span>
74
- </span>
75
- </div>
76
- <button type="submit" name="donation_value_month" value="${ amounts.month[ index ] }" data-tier-index="${ index }" style="background-color: ${ COLOR }; color: white;">Select </button>
77
- <div class="wpbnbd__tiers__description">This is the description of the plan.</div>
78
- </div>
79
- `
80
- ) }
81
- </div>
82
- <ul class="wpbnbd__tiers__options__dots"><li></li><li></li><li></li></ul>
83
- </div>
84
- </div>
85
- </form>
86
- <div class="wpbnbd__tiers__view wpbnbd__tiers__view--hidden">
87
- <form data-is-streamlined-form="" onsubmit="return false;">
88
- <button class="wpbnbd__tiers__back-button">← <span>Back</span></button>
89
- <div class="wpbnbd__tiers__tier-tile">
90
- <h2>Small</h2>
91
- <div>
92
- <div>
93
- <h3>
94
- <span>$</span>
95
- <span data-amount="">${ amounts.month[ 0 ] }</span>
96
- </h3>
97
- <span data-frequency=""> per month</span>
98
- </div>
99
- <div class="wpbnbd__tiers__tier-tile__note">
100
- Renews on <span data-renews-date="">–</span>
101
- </div>
102
- </div>
103
- </div>
104
- <div class="wp-block-newspack-blocks-donate__stripe stripe-payment"></div>
105
- <input data-is-streamlined-input-amount="" type="hidden" name="donation_value_month" value="${
106
- amounts.month[ 0 ]
107
- }">
108
- <input type="hidden" name="donation_frequency" value="month">
109
- </form>
110
- </div>
111
- </div>
112
- `;
113
- document.body.appendChild( parentElement );
114
- return document.body;
115
- };
116
-
117
- describe( 'Tiers-based Donate block processing', () => {
118
- // Handle the API missing on JSDOM.
119
- Element.prototype.scrollTo = jest.fn();
120
-
121
- const container = createDOM( stripeSettings, rawTiersBasedConfig );
122
- processTiersBasedElements( container );
123
-
124
- it( 'initially only montly amounts are visible', () => {
125
- testingLibrary
126
- .getAllByText( container, 'per month' )
127
- // Only first three are visible, the last "per month" is in the Stripe payment form.
128
- .slice( 0, 3 )
129
- .forEach( el => expect( el ).toBeVisible() );
130
- testingLibrary
131
- .getAllByText( container, 'per year' )
132
- .forEach( el => expect( el ).not.toBeVisible() );
133
-
134
- amounts.month.slice( 0, 3 ).forEach( amount => {
135
- expect( testingLibrary.getByText( container, `$${ amount }` ) ).toBeVisible();
136
- } );
137
- amounts.year.slice( 0, 3 ).forEach( amount => {
138
- expect( testingLibrary.getByText( container, `$${ amount }` ) ).not.toBeVisible();
139
- } );
140
- } );
141
-
142
- it( 'selecting the tier switches the view', async () => {
143
- const selectedTierIndex = 1;
144
- const tierSelectButton = testingLibrary.getAllByText( container, 'Select' )[
145
- selectedTierIndex
146
- ];
147
- await userEvent.click( tierSelectButton );
148
-
149
- const expectedAmount = amounts.month[ selectedTierIndex ];
150
- expect(
151
- // Second heading – on the tile, the first is hidden in tiers options list.
152
- testingLibrary.getAllByText( container, TIERS[ selectedTierIndex ].heading )[ 1 ]
153
- ).toBeVisible();
154
- expect( testingLibrary.getByText( container, expectedAmount ) ).toBeVisible();
155
- expect( testingLibrary.getByText( container, MONTH_RENEWAL_DATE ) ).toBeVisible();
156
- expect(
157
- parseInt( container.querySelector( 'input[name="donation_value_month"]' ).value )
158
- ).toEqual( expectedAmount );
159
- expect( container.querySelector( 'input[name="donation_frequency"]' ).value ).toEqual(
160
- 'month'
161
- );
162
- } );
163
-
164
- it( 'clicking the back button switches the view back to tier selection', async () => {
165
- const backButton = testingLibrary.getByText( container, 'Back' );
166
- await userEvent.click( backButton );
167
- expect( testingLibrary.getByText( container, 'Back' ) ).not.toBeVisible();
168
- } );
169
-
170
- it( 'after switching to annual payments, only yearly amounts are visible', async () => {
171
- const annualPaymentsButton = testingLibrary.getByText( container, 'Annually' );
172
- await userEvent.click( annualPaymentsButton );
173
- testingLibrary
174
- .getAllByText( container, 'per year' )
175
- // Only first three are visible, the last "per year" is in the Stripe payment form.
176
- .slice( 0, 3 )
177
- .forEach( el => expect( el ).toBeVisible() );
178
- testingLibrary
179
- .getAllByText( container, 'per month' )
180
- .forEach( el => expect( el ).not.toBeVisible() );
181
-
182
- amounts.year.slice( 0, 3 ).forEach( amount => {
183
- expect( testingLibrary.getByText( container, `$${ amount }` ) ).toBeVisible();
184
- } );
185
- amounts.month.slice( 0, 3 ).forEach( amount => {
186
- expect( testingLibrary.getByText( container, `$${ amount }` ) ).not.toBeVisible();
187
- } );
188
- } );
189
-
190
- it( 'selecting the tier after choosing annual payment switches the view', async () => {
191
- const selectedTierIndex = 2;
192
- const tierSelectButton = testingLibrary.getAllByText( container, 'Select' )[
193
- selectedTierIndex
194
- ];
195
- await userEvent.click( tierSelectButton );
196
-
197
- const expectedAmount = amounts.year[ selectedTierIndex ];
198
- expect(
199
- // Second heading – on the tile, the first is hidden in tiers options list.
200
- testingLibrary.getAllByText( container, TIERS[ selectedTierIndex ].heading )[ 1 ]
201
- ).toBeVisible();
202
- expect( testingLibrary.getByText( container, expectedAmount ) ).toBeVisible();
203
- expect( testingLibrary.getByText( container, MONTH_RENEWAL_DATE ) ).toBeVisible();
204
- expect(
205
- parseInt( container.querySelector( 'input[name="donation_value_year"]' ).value )
206
- ).toEqual( expectedAmount );
207
- expect( container.querySelector( 'input[name="donation_frequency"]' ).value ).toEqual( 'year' );
208
- } );
209
- } );