|
| 1 | +/** |
| 2 | + * External dependencies |
| 3 | + */ |
| 4 | +import { test, expect, Page } from '@playwright/test'; |
| 5 | +/** |
| 6 | + * Internal dependencies |
| 7 | + */ |
| 8 | +import { getMerchant, getShopper } from '../../utils/helpers'; |
| 9 | +import { |
| 10 | + activateMulticurrency, |
| 11 | + addMulticurrencyWidget, |
| 12 | + deactivateMulticurrency, |
| 13 | + removeMulticurrencyWidget, |
| 14 | +} from '../../utils/merchant'; |
| 15 | +import * as navigation from '../../utils/shopper-navigation'; |
| 16 | + |
| 17 | +test.describe( 'Multi-currency widget setup', () => { |
| 18 | + let merchantPage: Page; |
| 19 | + let shopperPage: Page; |
| 20 | + let wasMulticurrencyEnabled: boolean; |
| 21 | + // Values to test against. Defining nonsense values to ensure they are applied correctly. |
| 22 | + const settings = { |
| 23 | + borderRadius: '15', |
| 24 | + fontSize: '40', |
| 25 | + lineHeight: '2.3', |
| 26 | + textColor: 'rgb(155, 81, 224)', |
| 27 | + borderColor: 'rgb(252, 185, 0)', |
| 28 | + }; |
| 29 | + |
| 30 | + test.beforeAll( async ( { browser } ) => { |
| 31 | + shopperPage = ( await getShopper( browser ) ).shopperPage; |
| 32 | + merchantPage = ( await getMerchant( browser ) ).merchantPage; |
| 33 | + wasMulticurrencyEnabled = await activateMulticurrency( merchantPage ); |
| 34 | + |
| 35 | + await addMulticurrencyWidget( merchantPage, true ); |
| 36 | + } ); |
| 37 | + |
| 38 | + test.afterAll( async () => { |
| 39 | + await removeMulticurrencyWidget( merchantPage, true ); |
| 40 | + |
| 41 | + if ( ! wasMulticurrencyEnabled ) { |
| 42 | + await deactivateMulticurrency( merchantPage ); |
| 43 | + } |
| 44 | + |
| 45 | + await merchantPage.close(); |
| 46 | + } ); |
| 47 | + |
| 48 | + test( 'displays enabled currencies correctly in the admin', async () => { |
| 49 | + await expect( |
| 50 | + merchantPage |
| 51 | + .locator( 'select[name="currency"]' ) |
| 52 | + .getByRole( 'option' ) |
| 53 | + ).toHaveCount( 3 ); |
| 54 | + await expect( |
| 55 | + merchantPage |
| 56 | + .locator( 'select[name="currency"]' ) |
| 57 | + .getByRole( 'option', { name: 'USD' } ) |
| 58 | + ).toBeAttached(); |
| 59 | + await expect( |
| 60 | + merchantPage |
| 61 | + .locator( 'select[name="currency"]' ) |
| 62 | + .getByRole( 'option', { name: 'EUR' } ) |
| 63 | + ).toBeAttached(); |
| 64 | + await expect( |
| 65 | + merchantPage |
| 66 | + .locator( 'select[name="currency"]' ) |
| 67 | + .getByRole( 'option', { name: 'GBP' } ) |
| 68 | + ).toBeAttached(); |
| 69 | + } ); |
| 70 | + |
| 71 | + test( 'can update widget properties', async () => { |
| 72 | + await test.step( 'opens widget settings', async () => { |
| 73 | + await merchantPage |
| 74 | + .getByRole( 'button', { name: 'Settings' } ) |
| 75 | + .click(); |
| 76 | + await merchantPage |
| 77 | + .locator( '[data-title="Currency Switcher Block"]' ) |
| 78 | + .click(); |
| 79 | + } ); |
| 80 | + |
| 81 | + await test.step( 'checks display flags', async () => { |
| 82 | + await merchantPage |
| 83 | + .getByRole( 'checkbox', { name: 'Display flags' } ) |
| 84 | + .check(); |
| 85 | + await expect( |
| 86 | + await merchantPage |
| 87 | + .getByRole( 'checkbox', { name: 'Display flags' } ) |
| 88 | + .isChecked() |
| 89 | + ).toBeTruthy(); |
| 90 | + } ); |
| 91 | + |
| 92 | + await test.step( 'checks display currency symbols', async () => { |
| 93 | + await merchantPage |
| 94 | + .getByRole( 'checkbox', { name: 'Display currency symbols' } ) |
| 95 | + .check(); |
| 96 | + await expect( |
| 97 | + await merchantPage |
| 98 | + .getByRole( 'checkbox', { |
| 99 | + name: 'Display currency symbols', |
| 100 | + } ) |
| 101 | + .isChecked() |
| 102 | + ).toBeTruthy(); |
| 103 | + } ); |
| 104 | + |
| 105 | + await test.step( 'checks border', async () => { |
| 106 | + await merchantPage |
| 107 | + .getByRole( 'checkbox', { name: 'Border' } ) |
| 108 | + .check(); |
| 109 | + await expect( |
| 110 | + await merchantPage |
| 111 | + .getByRole( 'checkbox', { name: 'Border' } ) |
| 112 | + .isChecked() |
| 113 | + ).toBeTruthy(); |
| 114 | + } ); |
| 115 | + |
| 116 | + await test.step( 'updates border radius', async () => { |
| 117 | + await merchantPage |
| 118 | + .getByRole( 'spinbutton', { name: 'Border radius' } ) |
| 119 | + .fill( settings.borderRadius ); |
| 120 | + } ); |
| 121 | + |
| 122 | + await test.step( 'updates font size', async () => { |
| 123 | + await merchantPage |
| 124 | + .getByRole( 'spinbutton', { name: 'Size' } ) |
| 125 | + .fill( settings.fontSize ); |
| 126 | + } ); |
| 127 | + |
| 128 | + await test.step( 'updates line height', async () => { |
| 129 | + await merchantPage |
| 130 | + .getByRole( 'spinbutton', { name: 'Line height' } ) |
| 131 | + .fill( settings.lineHeight ); |
| 132 | + } ); |
| 133 | + |
| 134 | + await test.step( 'updates text color', async () => { |
| 135 | + await merchantPage |
| 136 | + .locator( 'fieldset', { hasText: 'Text' } ) |
| 137 | + .getByRole( 'listbox', { name: 'Custom color picker' } ) |
| 138 | + .getByRole( 'option', { name: 'Vivid purple' } ) |
| 139 | + .click(); |
| 140 | + } ); |
| 141 | + |
| 142 | + await test.step( 'updates border color', async () => { |
| 143 | + await merchantPage |
| 144 | + .locator( 'fieldset', { hasText: 'Border' } ) |
| 145 | + .getByRole( 'listbox', { name: 'Custom color picker' } ) |
| 146 | + .getByRole( 'option', { name: 'Luminous vivid amber' } ) |
| 147 | + .click(); |
| 148 | + } ); |
| 149 | + |
| 150 | + await test.step( 'saves changes', async () => { |
| 151 | + await expect( |
| 152 | + merchantPage.getByRole( 'button', { name: 'Update' } ) |
| 153 | + ).toBeEnabled(); |
| 154 | + await merchantPage |
| 155 | + .getByRole( 'button', { name: 'Update' } ) |
| 156 | + .click(); |
| 157 | + await expect( |
| 158 | + merchantPage.getByLabel( 'Dismiss this notice' ) |
| 159 | + ).toBeVisible( { |
| 160 | + timeout: 10000, |
| 161 | + } ); |
| 162 | + } ); |
| 163 | + } ); |
| 164 | + |
| 165 | + test( 'displays enabled currencies correctly in the frontend', async () => { |
| 166 | + await navigation.goToShop( shopperPage ); |
| 167 | + |
| 168 | + await expect( |
| 169 | + await shopperPage.locator( '.currency-switcher-holder' ) |
| 170 | + ).toBeVisible(); |
| 171 | + await expect( |
| 172 | + shopperPage |
| 173 | + .locator( '.currency-switcher-holder' ) |
| 174 | + .getByRole( 'option' ) |
| 175 | + ).toHaveCount( 3 ); |
| 176 | + await expect( |
| 177 | + shopperPage |
| 178 | + .locator( '.currency-switcher-holder' ) |
| 179 | + .getByRole( 'option', { name: 'USD' } ) |
| 180 | + ).toBeAttached(); |
| 181 | + await expect( |
| 182 | + shopperPage |
| 183 | + .locator( '.currency-switcher-holder' ) |
| 184 | + .getByRole( 'option', { name: 'EUR' } ) |
| 185 | + ).toBeAttached(); |
| 186 | + await expect( |
| 187 | + shopperPage |
| 188 | + .locator( '.currency-switcher-holder' ) |
| 189 | + .getByRole( 'option', { name: 'GBP' } ) |
| 190 | + ).toBeAttached(); |
| 191 | + } ); |
| 192 | + |
| 193 | + test( 'widget settings are applied in the frontend', async () => { |
| 194 | + await navigation.goToShop( shopperPage ); |
| 195 | + |
| 196 | + // Asserts flags are displayed. |
| 197 | + await expect( |
| 198 | + await shopperPage.locator( '.currency-switcher-holder select' ) |
| 199 | + ).toContainText( '🇺🇸' ); |
| 200 | + // Asserts currency symbols are displayed. |
| 201 | + await expect( |
| 202 | + await shopperPage.locator( '.currency-switcher-holder select' ) |
| 203 | + ).toContainText( '$' ); |
| 204 | + // Asserts border is set. |
| 205 | + await expect( |
| 206 | + await shopperPage.locator( '.currency-switcher-holder select' ) |
| 207 | + ).toHaveCSS( 'border-top-width', '1px' ); |
| 208 | + // Asserts border radius is set. |
| 209 | + await expect( |
| 210 | + await shopperPage.locator( '.currency-switcher-holder select' ) |
| 211 | + ).toHaveCSS( 'border-top-left-radius', `${ settings.borderRadius }px` ); |
| 212 | + await expect( |
| 213 | + await shopperPage.locator( '.currency-switcher-holder select' ) |
| 214 | + ).toHaveCSS( 'font-size', `${ settings.fontSize }px` ); |
| 215 | + await expect( |
| 216 | + await shopperPage.locator( '.currency-switcher-holder' ) |
| 217 | + ).toHaveAttribute( 'style', `line-height: ${ settings.lineHeight }; ` ); // Trailing space is expected. |
| 218 | + await expect( |
| 219 | + await shopperPage.locator( '.currency-switcher-holder select' ) |
| 220 | + ).toHaveCSS( 'color', settings.textColor ); |
| 221 | + // Asserts border color is set. |
| 222 | + await expect( |
| 223 | + await shopperPage.locator( '.currency-switcher-holder select' ) |
| 224 | + ).toHaveCSS( 'border-top-color', settings.borderColor ); |
| 225 | + } ); |
| 226 | +} ); |
0 commit comments