1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { getAdvancedDataFromQuery, getQueryFromAdvancedData, parseSearchQuery } from "~/store/search-bar/search-bar-actions";
6 import { ResourceKind } from "~/models/resource";
7 import { ClusterObjectType } from "~/models/search-bar";
9 describe('search-bar-actions', () => {
10 describe('parseSearchQuery', () => {
11 it('should correctly parse query #1', () => {
12 const q = 'val0 is:trashed val1';
13 const r = parseSearchQuery(q);
14 expect(r.hasKeywords).toBeTruthy();
15 expect(r.values).toEqual(['val0', 'val1']);
16 expect(r.properties).toEqual({
21 it('should correctly parse query #2 (value with keyword should be ignored)', () => {
22 const q = 'val0 is:from:trashed val1';
23 const r = parseSearchQuery(q);
24 expect(r.hasKeywords).toBeTruthy();
25 expect(r.values).toEqual(['val0', 'val1']);
26 expect(r.properties).toEqual({
31 it('should correctly parse query #3 (many keywords)', () => {
32 const q = 'val0 is:trashed val2 from:2017-04-01 val1';
33 const r = parseSearchQuery(q);
34 expect(r.hasKeywords).toBeTruthy();
35 expect(r.values).toEqual(['val0', 'val2', 'val1']);
36 expect(r.properties).toEqual({
42 it('should correctly parse query #4 (no duplicated values)', () => {
43 const q = 'val0 is:trashed val2 val2 val0';
44 const r = parseSearchQuery(q);
45 expect(r.hasKeywords).toBeTruthy();
46 expect(r.values).toEqual(['val0', 'val2']);
47 expect(r.properties).toEqual({
52 it('should correctly parse query #5 (properties)', () => {
53 const q = 'val0 has:filesize:100mb val2 val2 val0';
54 const r = parseSearchQuery(q);
55 expect(r.hasKeywords).toBeTruthy();
56 expect(r.values).toEqual(['val0', 'val2']);
57 expect(r.properties).toEqual({
58 'has': ['filesize:100mb']
62 it('should correctly parse query #6 (multiple properties, multiple is)', () => {
63 const q = 'val0 has:filesize:100mb val2 has:user:daniel is:starred val2 val0 is:trashed';
64 const r = parseSearchQuery(q);
65 expect(r.hasKeywords).toBeTruthy();
66 expect(r.values).toEqual(['val0', 'val2']);
67 expect(r.properties).toEqual({
68 'has': ['filesize:100mb', 'user:daniel'],
69 'is': ['starred', 'trashed']
74 describe('getAdvancedDataFromQuery', () => {
75 it('should correctly build advanced data record from query #1', () => {
76 const r = getAdvancedDataFromQuery('val0 has:filesize:100mb val2 has:user:daniel is:starred val2 val0 is:trashed');
78 searchValue: 'val0 val2',
81 projectUuid: undefined,
97 it('should correctly build advanced data record from query #2', () => {
98 const r = getAdvancedDataFromQuery('document from:2017-08-01 pdf has:filesize:101mb is:trashed type:arvados#collection cluster:indianapolis');
100 searchValue: 'document pdf',
101 type: ResourceKind.COLLECTION,
102 cluster: ClusterObjectType.INDIANAPOLIS,
103 projectUuid: undefined,
105 dateFrom: '2017-08-01',
117 describe('getQueryFromAdvancedData', () => {
118 it('should build query from advanced data', () => {
119 const q = getQueryFromAdvancedData({
120 searchValue: 'document pdf',
121 type: ResourceKind.COLLECTION,
122 cluster: ClusterObjectType.INDIANAPOLIS,
123 projectUuid: undefined,
125 dateFrom: '2017-08-01',
134 expect(q).toBe('document pdf type:arvados#collection cluster:indianapolis is:trashed from:2017-08-01 has:filesize:101mb');