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

fix(atomic): remove carousel arrows when only one page of Recommendations exists #4647

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 7 additions & 1 deletion packages/atomic/playwright-utils/base-page-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,16 @@ export class BasePageObject<
}

async noRecommendations() {
return this.nRecommendations(0);
}

async nRecommendations(numberOfRecommendations?: number) {
await this.page.route('**/commerce/v2/recommendations', async (route) => {
const response = await route.fetch();
const body = await response.json();
body.products = [];
if (numberOfRecommendations !== undefined) {
body['products'] = body['products'].slice(0, numberOfRecommendations);
}
await route.fulfill({
response,
json: body,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export class AtomicCommerceRecommendationList
}

private get hasPagination() {
return !!this.productsPerPage;
return this.numberOfPages > 1;
}

private get shouldRenderPagination() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ test.describe('with a carousel', () => {
});
});

test.describe('when there are no enough recommendations for multiple pages', () => {
test.beforeEach(async ({recommendationList, page}) => {
await recommendationList.nRecommendations(1);
await recommendationList.load({story: 'as-carousel'});
await page.waitForLoadState('networkidle');
});

test('should not display forward and backward buttons', async ({
recommendationList,
}) => {
await expect(recommendationList.nextButton).not.toBeVisible();
await expect(recommendationList.prevButton).not.toBeVisible();
await expect(recommendationList.indicators.first()).not.toBeVisible();
});
});

test('with no recommendations returned by the API, should render placeholders', async ({
recommendationList,
}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ export class AtomicRecsList implements InitializableComponent<RecsBindings> {
}

private get hasPagination() {
return !!this.numberOfRecommendationsPerPage;
return this.numberOfPages > 1;
}

private get shouldRenderPagination() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ test.describe('with a carousel', () => {
});
});

test.describe('when there are no enough recommendations for multiple pages', () => {
test.beforeEach(async ({recsList, page}) => {
await recsList.nRecommendations(3);
await recsList.load({story: 'recs-as-carousel'});
await page.waitForLoadState('networkidle');
});

test('should not display forward and backward buttons', async ({
recsList,
}) => {
await expect(recsList.nextButton).not.toBeVisible();
await expect(recsList.prevButton).not.toBeVisible();
await expect(recsList.indicators.first()).not.toBeVisible();
});
});

test('with no recommendations returned by the API, should render placeholders', async ({
recsList,
page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ export class AtomicCommerceRecsListPageObject extends BasePageObject<'atomic-rec
return this.page.getByLabel('Previous');
}

async noRecommendations() {
async nRecommendations(numberOfRecommendations?: number) {
await this.page.route(
'**/search/v2?organizationId=searchuisamples',
async (route) => {
const response = await route.fetch();
const body = await response.json();
body.results = [];
if (numberOfRecommendations !== undefined) {
body['results'] = body['results'].slice(0, numberOfRecommendations);
}
await route.fulfill({
response,
json: body,
Expand All @@ -44,4 +46,8 @@ export class AtomicCommerceRecsListPageObject extends BasePageObject<'atomic-rec

return this;
}

async noRecommendations() {
return this.nRecommendations(0);
}
}
Loading