1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { getAdvancedDataFromQuery, getQueryFromAdvancedData } from "~/store/search-bar/search-bar-actions";
6 import { ResourceKind } from "~/models/resource";
8 describe('search-bar-actions', () => {
9 describe('getAdvancedDataFromQuery', () => {
10 it('should correctly build advanced data record from query #1', () => {
11 const r = getAdvancedDataFromQuery('val0 has:"file size":"100mb" val2 has:"user":"daniel" is:starred val2 val0');
13 searchValue: 'val0 val2',
16 projectUuid: undefined,
33 it('should correctly build advanced data record from query #2', () => {
34 const r = getAdvancedDataFromQuery('document from:2017-08-01 pdf has:"filesize":"101mb" is:trashed type:arvados#collection cluster:c97qx is:pastVersion');
36 searchValue: 'document pdf',
37 type: ResourceKind.COLLECTION,
39 projectUuid: undefined,
42 dateFrom: '2017-08-01',
54 describe('getQueryFromAdvancedData', () => {
55 it('should build query from advanced data', () => {
56 const q = getQueryFromAdvancedData({
57 searchValue: 'document pdf',
58 type: ResourceKind.COLLECTION,
60 projectUuid: undefined,
63 dateFrom: '2017-08-01',
66 { key: 'file size', value: '101mb' },
67 { key: 'Species', value: 'Human' },
68 { key: 'Species', value: 'Canine' },
73 expect(q).toBe('document pdf type:arvados#collection cluster:c97qx is:trashed from:2017-08-01 has:"file size":"101mb" has:"Species":"Human" has:"Species":"Canine"');
76 it('should build query from advanced data #2', () => {
77 const q = getQueryFromAdvancedData({
78 searchValue: 'document pdf',
79 type: ResourceKind.COLLECTION,
81 projectUuid: undefined,
84 dateFrom: '2017-08-01',
87 { key: 'file size', value: '101mb' },
88 { key: 'Species', value: 'Human' },
89 { key: 'Species', value: 'Canine' },
94 expect(q).toBe('document pdf type:arvados#collection cluster:c97qx is:pastVersion from:2017-08-01 has:"file size":"101mb" has:"Species":"Human" has:"Species":"Canine"');
97 it('should add has:"key":"value" expression to query from same property key', () => {
98 const searchValue = 'document pdf has:"file size":"101mb" has:"Species":"Canine"';
103 projectUuid: undefined,
109 { key: 'file size', value: '101mb' },
110 { key: 'Species', value: 'Canine' },
118 { key: 'file size', value: '101mb' },
119 { key: 'Species', value: 'Canine' },
120 { key: 'Species', value: 'Human' },
123 const q = getQueryFromAdvancedData(currData, prevData);
124 expect(q).toBe('document pdf has:"file size":"101mb" has:"Species":"Canine" has:"Species":"Human"');
127 it('should add has:"keyID":"valueID" expression to query when necessary', () => {
128 const searchValue = 'document pdf has:"file size":"101mb"';
133 projectUuid: undefined,
139 { key: 'file size', value: '101mb' },
147 { key: 'file size', value: '101mb' },
148 { key: 'Species', keyID: 'IDTAGSPECIES', value: 'Human', valueID: 'IDVALHUMAN'},
151 const q = getQueryFromAdvancedData(currData, prevData);
152 expect(q).toBe('document pdf has:"file size":"101mb" has:"IDTAGSPECIES":"IDVALHUMAN"');
155 it('should remove has:"key":"value" expression from query', () => {
156 const searchValue = 'document pdf has:"file size":"101mb" has:"Species":"Human" has:"Species":"Canine"';
161 projectUuid: undefined,
167 { key: 'file size', value: '101mb' },
168 { key: 'Species', value: 'Canine' },
169 { key: 'Species', value: 'Human' },
177 { key: 'file size', value: '101mb' },
178 { key: 'Species', value: 'Canine' },
181 const q = getQueryFromAdvancedData(currData, prevData);
182 expect(q).toBe('document pdf has:"file size":"101mb" has:"Species":"Canine"');