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";
8 describe('search-bar-actions', () => {
9 describe('parseSearchQuery', () => {
10 it('should correctly parse query #1', () => {
11 const q = 'val0 is:trashed val1';
12 const r = parseSearchQuery(q);
13 expect(r.hasKeywords).toBeTruthy();
14 expect(r.values).toEqual(['val0', 'val1']);
15 expect(r.properties).toEqual({
20 it('should correctly parse query #2 (value with keyword should be ignored)', () => {
21 const q = 'val0 is:from:trashed val1';
22 const r = parseSearchQuery(q);
23 expect(r.hasKeywords).toBeTruthy();
24 expect(r.values).toEqual(['val0', 'val1']);
25 expect(r.properties).toEqual({
30 it('should correctly parse query #3 (many keywords)', () => {
31 const q = 'val0 is:trashed val2 from:2017-04-01 val1';
32 const r = parseSearchQuery(q);
33 expect(r.hasKeywords).toBeTruthy();
34 expect(r.values).toEqual(['val0', 'val2', 'val1']);
35 expect(r.properties).toEqual({
41 it('should correctly parse query #4 (no duplicated values)', () => {
42 const q = 'val0 is:trashed val2 val2 val0';
43 const r = parseSearchQuery(q);
44 expect(r.hasKeywords).toBeTruthy();
45 expect(r.values).toEqual(['val0', 'val2']);
46 expect(r.properties).toEqual({
51 it('should correctly parse query #5 (properties)', () => {
52 const q = 'val0 has:filesize:100mb val2 val2 val0';
53 const r = parseSearchQuery(q);
54 expect(r.hasKeywords).toBeTruthy();
55 expect(r.values).toEqual(['val0', 'val2']);
56 expect(r.properties).toEqual({
57 'has': ['filesize:100mb']
61 it('should correctly parse query #6 (multiple properties, multiple is)', () => {
62 const q = 'val0 has:filesize:100mb val2 has:user:daniel is:starred val2 val0 is:trashed';
63 const r = parseSearchQuery(q);
64 expect(r.hasKeywords).toBeTruthy();
65 expect(r.values).toEqual(['val0', 'val2']);
66 expect(r.properties).toEqual({
67 'has': ['filesize:100mb', 'user:daniel'],
68 'is': ['starred', 'trashed']
73 describe('getAdvancedDataFromQuery', () => {
74 it('should correctly build advanced data record from query #1', () => {
75 const r = getAdvancedDataFromQuery('val0 has:filesize:100mb val2 has:user:daniel is:starred val2 val0 is:trashed');
77 searchValue: 'val0 val2',
80 projectUuid: undefined,
96 it('should correctly build advanced data record from query #2', () => {
97 const r = getAdvancedDataFromQuery('document from:2017-08-01 pdf has:filesize:101mb is:trashed type:arvados#collection cluster:c97qx');
99 searchValue: 'document pdf',
100 type: ResourceKind.COLLECTION,
102 projectUuid: undefined,
104 dateFrom: '2017-08-01',
116 describe('getQueryFromAdvancedData', () => {
117 it('should build query from advanced data', () => {
118 const q = getQueryFromAdvancedData({
119 searchValue: 'document pdf',
120 type: ResourceKind.COLLECTION,
122 projectUuid: undefined,
124 dateFrom: '2017-08-01',
133 expect(q).toBe('document pdf type:arvados#collection cluster:c97qx is:trashed from:2017-08-01 has:filesize:101mb');