Skip to content

Commit

Permalink
applied improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonMilord committed Feb 19, 2025
1 parent 3f5e0e0 commit ee0eea3
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<c-quantic-timeframe unit="year"></c-quantic-timeframe>
</c-quantic-timeframe-facet>
<c-quantic-facet engine-id={engineId} field="objecttype" label="Type"></c-quantic-facet>
<div slot="itemTemplate" class="slds-m-around_xx-large"></div>
</c-quantic-facet-manager>
</c-example-use-case>
</c-example-layout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ export class FacetManagerObject {
}

get facetManagerItems(): Locator {
return this.facetManager.locator('.facet-manager__item');
return this.facetManager.getByTestId('facet-manager__item');
}

getFacetManagerItemByIndex(index: number): Locator {
return this.facetManagerItems.nth(index);
get itemTemplateSlot(): Locator {
return this.facetManager.locator('slot[name="itemTemplate"]');
}

getAllFacetManagerItems(): Promise<Locator[]> {
return this.facetManager.locator('.facet-manager__item').all();
getFacetManagerItemByIndex(index: number): Locator {
return this.facetManagerItems.nth(index);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,18 @@ useCaseTestCases.forEach((useCase) => {
await search.performSearch();

const searchResponse = await searchResponsePromise;
const searchResponseBody = await searchResponse.json();
expect(searchResponseBody).not.toBeNull();
const {facets} = await searchResponse.json();
expect(facets).not.toBeNull();

searchResponseBody?.facets?.forEach(
async (facet: any, index: number) => {
const facetManagerItem =
facetManager.getFacetManagerItemByIndex(index);
expect(
await facetManagerItem.getAttribute('data-facet-id')
).toEqual(facet.facetId);
}
);
facets?.forEach(async (facet: any, index: number) => {
const facetManagerItem =
facetManager.getFacetManagerItemByIndex(index);
expect(await facetManagerItem.getAttribute('data-facet-id')).toEqual(
facet.facetId
);
});

[exampleFacetsOrder.length - 1].forEach(async (index: number) => {
exampleFacetsOrder.forEach(async (facetId: string, index: number) => {
const facetManagerItem =
facetManager.getFacetManagerItemByIndex(index);
expect(await facetManagerItem.getAttribute('data-facet-id')).toEqual(
Expand All @@ -74,5 +72,19 @@ useCaseTestCases.forEach((useCase) => {
});
});
});

test.describe('when an itemTemplate slot is provided', () => {
test('should customize the element that wraps each facet according to the itemTemplate slot', async ({
facetManager,
}) => {
const expectedClass = 'slds-m-around_xx-large';
expect(facetManager.itemTemplateSlot).not.toBeNull();

const facetManagerItems = await facetManager.facetManagerItems.all();
facetManagerItems.forEach(async (item: any) => {
expect(await item.getAttribute('class')).toContain(expectedClass);
});
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export default class QuanticFacetManager extends LightningElement {
// @ts-ignore
wrapper.setAttribute('data-facet-id', facet.facetId ?? facet.field);
wrapper.classList.add('facet-manager__item');
wrapper.setAttribute('data-testid', 'facet-manager__item');

wrapper.appendChild(facet);
this.host.appendChild(wrapper);
Expand Down
5 changes: 3 additions & 2 deletions packages/quantic/playwright/page-object/searchObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ export class SearchObject {
const reorderedFacets: unknown[] = [];

facetIds.forEach((facetId, idx) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const facet = facets.find((f: any) => f.facetId === facetId);
const facet = facets.find(
(f: {facetId: string}) => f.facetId === facetId
);
if (facet) {
reorderedFacets.push({
...facet,
Expand Down

0 comments on commit ee0eea3

Please sign in to comment.