Skip to content

Commit

Permalink
Merge branch 'develop' into fix/7588-woopay-subscription-variation
Browse files Browse the repository at this point in the history
  • Loading branch information
mdmoore authored Dec 18, 2023
2 parents 7e815cb + dfd571b commit 9f789ab
Show file tree
Hide file tree
Showing 5 changed files with 363 additions and 1 deletion.
4 changes: 4 additions & 0 deletions changelog/e2e-7382-spec-merchant-multi-currency-setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

E2E test - Merchant facing: Multi-currency setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
/**
* External dependencies
*/
const { merchant } = require( '@woocommerce/e2e-utils' );
/**
* Internal dependencies
*/
import {
getProductPriceFromProductPage,
merchantWCP,
shopperWCP,
} from '../../../utils';

let wasMulticurrencyEnabled;

describe( 'Merchant Multi-Currency Settings', () => {
beforeAll( async () => {
await merchant.login();
// Get initial multi-currency feature status.
await merchantWCP.openWCPSettings();
await page.waitForSelector( "[data-testid='multi-currency-toggle']" );
wasMulticurrencyEnabled = await page.evaluate( () => {
const checkbox = document.querySelector(
"[data-testid='multi-currency-toggle']"
);
return checkbox ? checkbox.checked : false;
} );
} );

afterAll( async () => {
// Disable multi-currency if it was not initially enabled.
if ( ! wasMulticurrencyEnabled ) {
await merchant.login();
await merchantWCP.deactivateMulticurrency();
}
await merchant.logout();
} );

it( 'can enable multi-currency feature', async () => {
// Assertions are in the merchantWCP.wcpSettingsSaveChanges() flow.
await merchantWCP.activateMulticurrency();
} );

it( 'can disable multi-currency feature', async () => {
// Assertions are in the merchantWCP.wcpSettingsSaveChanges() flow.
await merchantWCP.deactivateMulticurrency();
} );

describe( 'Currency Management', () => {
const testCurrency = 'CHF';

beforeAll( async () => {
await merchantWCP.activateMulticurrency();
} );

it( 'can add a new currency', async () => {
await merchantWCP.addCurrency( testCurrency );
} );

it( 'can remove a currency', async () => {
await merchantWCP.removeCurrency( testCurrency );
} );
} );

describe( 'Currency Settings', () => {
const testData = {
currencyCode: 'CHF',
rate: '1.25',
charmPricing: '-0.01',
rounding: '0.50',
currencyPrecision: 2,
};

let beanieRegularPrice;

beforeAll( async () => {
await merchantWCP.activateMulticurrency();

await shopperWCP.goToShopWithCurrency( 'USD' );
await shopperWCP.goToProductPageBySlug( 'beanie' );
beanieRegularPrice = await getProductPriceFromProductPage();
} );

beforeEach( async () => {
await merchantWCP.openMultiCurrency();
await merchantWCP.addCurrency( testData.currencyCode );
} );

afterEach( async () => {
await merchantWCP.openMultiCurrency();
await merchantWCP.removeCurrency( testData.currencyCode );
} );

it( 'can change the currency rate manually', async () => {
await merchantWCP.setCurrencyRate(
testData.currencyCode,
testData.rate
);
await merchantWCP.setCurrencyPriceRounding(
testData.currencyCode,
'0'
);

await shopperWCP.goToShopWithCurrency( testData.currencyCode );
await shopperWCP.goToProductPageBySlug( 'beanie' );
const beaniePriceOnCurrency = await getProductPriceFromProductPage();

expect(
parseFloat( beaniePriceOnCurrency ).toFixed(
testData.currencyPrecision
)
).toBe(
( parseFloat( beanieRegularPrice ) * testData.rate ).toFixed(
testData.currencyPrecision
)
);
} );

it( 'can change the charm price manually', async () => {
await merchantWCP.setCurrencyRate( testData.currencyCode, '1.00' );
await merchantWCP.setCurrencyPriceRounding(
testData.currencyCode,
'0'
);
await merchantWCP.setCurrencyCharmPricing(
testData.currencyCode,
testData.charmPricing
);

await shopperWCP.goToShopWithCurrency( testData.currencyCode );
await shopperWCP.goToProductPageBySlug( 'beanie' );
const beaniePriceOnCurrency = await getProductPriceFromProductPage();

expect(
parseFloat( beaniePriceOnCurrency ).toFixed(
testData.currencyPrecision
)
).toBe(
(
parseFloat( beanieRegularPrice ) +
parseFloat( testData.charmPricing )
).toFixed( testData.currencyPrecision )
);
} );

it( 'can change the rounding precision manually', async () => {
const rateForTest = 1.2;

await merchantWCP.setCurrencyRate(
testData.currencyCode,
rateForTest.toString()
);
await merchantWCP.setCurrencyPriceRounding(
testData.currencyCode,
testData.rounding
);

await shopperWCP.goToShopWithCurrency( testData.currencyCode );
await shopperWCP.goToProductPageBySlug( 'beanie' );
const beaniePriceOnCurrency = await getProductPriceFromProductPage();

expect(
parseFloat( beaniePriceOnCurrency ).toFixed(
testData.currencyPrecision
)
).toBe(
(
Math.ceil(
parseFloat( beanieRegularPrice ) *
rateForTest *
( 1 / testData.rounding )
) * testData.rounding
).toFixed( testData.currencyPrecision )
);
} );
} );

describe( 'Currency decimal points', () => {
const currencyDecimalMap = {
JPY: 0,
GBP: 2,
};

beforeAll( async () => {
await merchantWCP.activateMulticurrency();

for ( const currency of Object.keys( currencyDecimalMap ) ) {
await merchantWCP.addCurrency( currency );
}
} );

it.each( Object.keys( currencyDecimalMap ) )(
'sees the correct decimal points for %s',
async ( currency ) => {
await shopperWCP.goToShopWithCurrency( currency );
await shopperWCP.goToProductPageBySlug( 'beanie' );
const priceOnCurrency = await getProductPriceFromProductPage();

const decimalPart = priceOnCurrency.split( '.' )[ 1 ] || '';
expect( decimalPart.length ).toBe(
currencyDecimalMap[ currency ]
);
}
);
} );
} );
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ let orderAmount;

describe( 'Order > Full refund', () => {
beforeAll( async () => {
// Disable multi-currency in the merchant settings. This step is important because local environment setups
// might have multi-currency enabled. We need to ensure a consistent
// environment for the test.
await merchant.login();
await merchantWCP.deactivateMulticurrency();
await merchant.logout();

await shopper.login();
// Place an order to refund later
await setupProductCheckout(
config.get( 'addresses.customer.billing' )
Expand Down
98 changes: 97 additions & 1 deletion tests/e2e/utils/flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,14 @@ export const shopperWCP = {
} );
},

addToCartBySlug: async ( productSlug ) => {
goToProductPageBySlug: async ( productSlug ) => {
await page.goto( config.get( 'url' ) + `product/${ productSlug }`, {
waitUntil: 'networkidle0',
} );
},

addToCartBySlug: async ( productSlug ) => {
await shopperWCP.goToProductPageBySlug( productSlug );
await shopper.addToCart();
},
};
Expand Down Expand Up @@ -473,13 +477,38 @@ export const merchantWCP = {
{ text: 'Update selected' }
);

const snackbar = '.components-snackbar';
await expect( page ).toMatchElement( snackbar, {
text: 'Enabled currencies updated.',
timeout: 60000,
} );

const selector = `li.enabled-currency.${ currencyCode.toLowerCase() }`;
await page.waitForSelector( selector );
const element = await page.$( selector );

expect( element ).not.toBeNull();
},

removeCurrency: async ( currencyCode ) => {
const currencyItemSelector = `li.enabled-currency.${ currencyCode.toLowerCase() }`;
await page.waitForSelector( currencyItemSelector, { timeout: 10000 } );
await page.click(
`${ currencyItemSelector } .enabled-currency__action.delete`
);

const snackbar = '.components-snackbar';
await expect( page ).toMatchElement( snackbar, {
text: 'Enabled currencies updated.',
timeout: 60000,
} );

await page.waitForSelector( currencyItemSelector, {
hidden: true,
timeout: 15000,
} );
},

openConnectPage: async () => {
await page.goto( WCPAY_CONNECT, {
waitUntil: 'networkidle0',
Expand Down Expand Up @@ -573,6 +602,9 @@ export const merchantWCP = {
},

setCheckboxByTestId: async ( testId ) => {
await page.waitForSelector( `[data-testid="${ testId }"]`, {
timeout: 5000,
} );
const checkbox = await page.$( `[data-testid="${ testId }"]` );
const checkboxStatus = await (
await checkbox.getProperty( 'checked' )
Expand All @@ -583,6 +615,9 @@ export const merchantWCP = {
},

unsetCheckboxByTestId: async ( testId ) => {
await page.waitForSelector( `[data-testid="${ testId }"]`, {
timeout: 5000,
} );
const checkbox = await page.$( `[data-testid="${ testId }"]` );
const checkboxStatus = await (
await checkbox.getProperty( 'checked' )
Expand Down Expand Up @@ -656,6 +691,67 @@ export const merchantWCP = {
return wasInitiallyEnabled;
},

editCurrency: async ( currencyCode ) => {
await merchantWCP.openMultiCurrency();

const currencyItemSelector = `li.enabled-currency.${ currencyCode.toLowerCase() }`;
await page.waitForSelector( currencyItemSelector, { timeout: 10000 } );
await page.click(
`${ currencyItemSelector } .enabled-currency__action.edit`
);
},

saveCurrencySettings: async () => {
await page.click(
'.single-currency-settings-save-settings-section button'
);
await page.waitForSelector( '.components-snackbar', {
text: 'Currency settings updated.',
timeout: 15000,
} );
},

setCurrencyRate: async ( currencyCode, rate ) => {
await merchantWCP.editCurrency( currencyCode );

await page.waitForSelector(
'#single-currency-settings__manual_rate_radio'
);
await page.click( '#single-currency-settings__manual_rate_radio' );

await page.waitForSelector( '[data-testid="manual_rate_input"]', {
timeout: 5000,
} );
await clearAndFillInput(
'[data-testid="manual_rate_input"]',
rate.toString()
);

await merchantWCP.saveCurrencySettings();
},

setCurrencyPriceRounding: async ( currencyCode, rounding ) => {
await merchantWCP.editCurrency( currencyCode );

await page.waitForSelector( '[data-testid="price_rounding"]', {
timeout: 5000,
} );
await page.select( '[data-testid="price_rounding"]', rounding );

await merchantWCP.saveCurrencySettings();
},

setCurrencyCharmPricing: async ( currencyCode, charmPricing ) => {
await merchantWCP.editCurrency( currencyCode );

await page.waitForSelector( '[data-testid="price_charm"]', {
timeout: 5000,
} );
await page.select( '[data-testid="price_charm"]', charmPricing );

await merchantWCP.saveCurrencySettings();
},

addMulticurrencyWidget: async () => {
await page.goto( `${ WP_ADMIN_DASHBOARD }widgets.php`, {
waitUntil: 'networkidle0',
Expand Down
Loading

0 comments on commit 9f789ab

Please sign in to comment.