|
|
@@ -8,10 +8,11 @@ import {
|
|
|
} from '@vendure/core';
|
|
|
import { createTestEnvironment, E2E_DEFAULT_CHANNEL_TOKEN, SimpleGraphQLClient } from '@vendure/testing';
|
|
|
import gql from 'graphql-tag';
|
|
|
+import so from 'i18next-icu/locale-data/so';
|
|
|
import path from 'path';
|
|
|
|
|
|
import { initialData } from '../../../e2e-common/e2e-initial-data';
|
|
|
-import { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-config';
|
|
|
+import { TEST_SETUP_TIMEOUT_MS, testConfig } from '../../../e2e-common/test-config';
|
|
|
|
|
|
import {
|
|
|
AssignProductsToChannel,
|
|
|
@@ -29,6 +30,7 @@ import {
|
|
|
SearchGetAssets,
|
|
|
SearchGetPrices,
|
|
|
SearchInput,
|
|
|
+ SearchResultSortParameter,
|
|
|
SortOrder,
|
|
|
UpdateAsset,
|
|
|
UpdateCollection,
|
|
|
@@ -103,6 +105,52 @@ describe('Default search plugin', () => {
|
|
|
expect(result.search.totalItems).toBe(34);
|
|
|
}
|
|
|
|
|
|
+ async function testSortingWithGrouping(
|
|
|
+ client: SimpleGraphQLClient,
|
|
|
+ sortBy: keyof SearchResultSortParameter,
|
|
|
+ ) {
|
|
|
+ const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
|
|
|
+ SEARCH_PRODUCTS_SHOP,
|
|
|
+ {
|
|
|
+ input: {
|
|
|
+ groupByProduct: true,
|
|
|
+ sort: {
|
|
|
+ [sortBy]: SortOrder.ASC,
|
|
|
+ },
|
|
|
+ take: 3,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ );
|
|
|
+ const expected =
|
|
|
+ sortBy === 'name'
|
|
|
+ ? ['Bonsai Tree', 'Boxing Gloves', 'Camera Lens']
|
|
|
+ : ['Skipping Rope', 'Tripod', 'Spiky Cactus'];
|
|
|
+ expect(result.search.items.map(i => i.productName)).toEqual(expected);
|
|
|
+ }
|
|
|
+
|
|
|
+ async function testSortingNoGrouping(
|
|
|
+ client: SimpleGraphQLClient,
|
|
|
+ sortBy: keyof SearchResultSortParameter,
|
|
|
+ ) {
|
|
|
+ const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
|
|
|
+ SEARCH_PRODUCTS_SHOP,
|
|
|
+ {
|
|
|
+ input: {
|
|
|
+ groupByProduct: false,
|
|
|
+ sort: {
|
|
|
+ [sortBy]: SortOrder.DESC,
|
|
|
+ },
|
|
|
+ take: 3,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ );
|
|
|
+ const expected =
|
|
|
+ sortBy === 'name'
|
|
|
+ ? ['USB Cable', 'Tripod', 'Tent']
|
|
|
+ : ['Road Bike', 'Laptop 15 inch 16GB', 'Laptop 13 inch 16GB'];
|
|
|
+ expect(result.search.items.map(i => i.productVariantName)).toEqual(expected);
|
|
|
+ }
|
|
|
+
|
|
|
async function testMatchSearchTerm(client: SimpleGraphQLClient) {
|
|
|
const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
|
|
|
SEARCH_PRODUCTS_SHOP,
|
|
|
@@ -376,6 +424,14 @@ describe('Default search plugin', () => {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+ it('sort name with grouping', () => testSortingWithGrouping(shopClient, 'name'));
|
|
|
+
|
|
|
+ it('sort price with grouping', () => testSortingWithGrouping(shopClient, 'price'));
|
|
|
+
|
|
|
+ it('sort name without grouping', () => testSortingNoGrouping(shopClient, 'name'));
|
|
|
+
|
|
|
+ it('sort price without grouping', () => testSortingNoGrouping(shopClient, 'price'));
|
|
|
+
|
|
|
it('omits results for disabled ProductVariants', async () => {
|
|
|
await adminClient.query<UpdateProductVariants.Mutation, UpdateProductVariants.Variables>(
|
|
|
UPDATE_PRODUCT_VARIANTS,
|
|
|
@@ -431,6 +487,14 @@ describe('Default search plugin', () => {
|
|
|
|
|
|
it('price ranges', () => testPriceRanges(adminClient));
|
|
|
|
|
|
+ it('sort name with grouping', () => testSortingWithGrouping(adminClient, 'name'));
|
|
|
+
|
|
|
+ it('sort price with grouping', () => testSortingWithGrouping(adminClient, 'price'));
|
|
|
+
|
|
|
+ it('sort name without grouping', () => testSortingNoGrouping(adminClient, 'name'));
|
|
|
+
|
|
|
+ it('sort price without grouping', () => testSortingNoGrouping(adminClient, 'price'));
|
|
|
+
|
|
|
describe('updating the index', () => {
|
|
|
it('updates index when ProductVariants are changed', async () => {
|
|
|
await awaitRunningJobs(adminClient);
|