Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Add tests for shipping estimates #769

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export const ShippingInfo = ({
<FieldLabel>{t('country')}</FieldLabel>
<FieldControl asChild>
<Select
aria-label={t('countryAriaLabel')}
avattipalli marked this conversation as resolved.
Show resolved Hide resolved
autoComplete="country"
onValueChange={(value: string) => {
const countryId = value.split('-')[1];
Expand Down Expand Up @@ -174,6 +175,7 @@ export const ShippingInfo = ({
<FieldControl asChild>
{formValues.states !== null ? (
<Select
aria-label={t('stateAriaLabel')}
disabled={formValues.states.length === 0}
onValueChange={(value) => setFormValues({ state: value })}
placeholder={t('statePlaceholder')}
Expand Down Expand Up @@ -204,6 +206,7 @@ export const ShippingInfo = ({
<FieldLabel htmlFor="city-field">{t('city')}</FieldLabel>
<FieldControl asChild>
<Input
aria-label={t('cityAriaLabel')}
autoComplete="address-level2"
id="city-field"
onChange={(e) => setFormValues({ city: e.target.value })}
Expand All @@ -217,6 +220,7 @@ export const ShippingInfo = ({
<FieldLabel htmlFor="zip-field">{t('postcode')}</FieldLabel>
<FieldControl asChild>
<Input
aria-label={t('postcodeAriaLabel')}
avattipalli marked this conversation as resolved.
Show resolved Hide resolved
autoComplete="postal-code"
id="zip-field"
onChange={(e) => setFormValues({ postcode: e.target.value })}
Expand Down
12 changes: 8 additions & 4 deletions apps/core/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,17 @@
},
"ShippingInfo": {
"country": "Country",
"countryPlaceholder": "Select county",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected a typo and added a few aria-label attributes.

"countryAriaLabel": "Country",
"countryPlaceholder": "Select country",
"state": "State/province",
"statePlaceholder": "State/province...",
"stateAriaLabel": "State",
"statePlaceholder": "Select state",
"city": "Suburb/city",
"cityPlaceholder": "State/province...",
"cityAriaLabel": "City",
"cityPlaceholder": "City...",
"postcode": "Zip/Postcode",
"postcodePlaceholder": "State/province...",
"postcodeAriaLabel": "Postcode",
"postcodePlaceholder": "Postal code...",
"errorMessage": "Something went wrong, please try again."
},
"SubmitShippingInfo": {
Expand Down
26 changes: 26 additions & 0 deletions packages/functional/actions/cart-actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Page } from '@playwright/test';

export async function addEstimatedShippingCosts(
page: Page,
country: string,
state: string,
city: string,
zip: string,
): Promise<void> {
await page.getByRole('combobox', { name: 'Country' }).click();
await page.getByLabel(country).click();

await page
.getByRole('combobox', { name: 'State' })
.filter({ hasNotText: 'Select state' })
avattipalli marked this conversation as resolved.
Show resolved Hide resolved
.click();
await page.getByLabel(state).click();

await page.getByLabel('City').fill(city);
await page.getByLabel('Postcode').fill(zip);
avattipalli marked this conversation as resolved.
Show resolved Hide resolved

await page.getByRole('button', { name: 'Estimate shipping' }).click();
await page.getByRole('button', { name: 'Update shipping costs' }).click();
}

export * as CartActions from './cart-actions';
61 changes: 61 additions & 0 deletions packages/functional/tests/ui/desktop/e2e/shipping.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { expect, test } from '@playwright/test';

import { CartActions } from '../../../../actions/cart-actions';
import { ProductActions } from '../../../../actions/product-actions';

const sampleProduct = '[Sample] Able Brewing System';

test.beforeEach(async ({ page }) => {
await page.goto('/');
await page.getByLabel('Main').getByRole('link', { name: 'Kitchen' }).click();
await expect(page.getByRole('heading', { level: 3, name: sampleProduct })).toBeVisible();

await ProductActions.addProductToCart(page, sampleProduct);

await page.getByRole('link', { name: 'Cart Items 1' }).click();

await expect(page.getByRole('heading', { level: 1, name: 'Your cart' })).toBeVisible();
await expect(page.getByText(sampleProduct, { exact: true })).toBeVisible();
});

test('Add shipping estimates', async ({ page }) => {
await expect(page.getByText('Shipping cost')).toBeVisible();
await page.getByRole('button', { name: 'Add' }).first().click();

await CartActions.addEstimatedShippingCosts(page, 'United States', 'Texas', 'Austin', '76267');
await expect(page.getByRole('button', { name: 'Change' })).toBeVisible();
});

test('Update shipping estimates', async ({ page }) => {
await expect(page.getByText('Shipping cost')).toBeVisible();
await page.getByRole('button', { name: 'Add' }).first().click();

await CartActions.addEstimatedShippingCosts(page, 'United States', 'Texas', 'Austin', '76267');

await expect(page.getByRole('button', { name: 'Change' })).toBeVisible();
await page.getByRole('button', { name: 'Change' }).click();

await CartActions.addEstimatedShippingCosts(
page,
'United States',
'Massachusetts',
'Boston',
'01762',
);

await expect(page.getByRole('button', { name: 'Change' })).toBeVisible();
});

test('Add shipping estimates for Canada', async ({ page }) => {
await expect(page.getByText('Shipping cost')).toBeVisible();
await page.getByRole('button', { name: 'Add' }).first().click();

await CartActions.addEstimatedShippingCosts(
page,
'Canada',
'British Columbia',
'Vancouver',
'98617',
);
await expect(page.getByRole('button', { name: 'Change' })).toBeVisible();
});
Loading