15672: Adds filtering by name on subprocess panel by using the search field.
[arvados-workbench2.git] / src / store / search-bar / search-bar-actions.test.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { getAdvancedDataFromQuery, getQueryFromAdvancedData } from "~/store/search-bar/search-bar-actions";
6 import { ResourceKind } from "~/models/resource";
7
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 is:trashed');
12             expect(r).toEqual({
13                 searchValue: 'val0 val2',
14                 type: undefined,
15                 cluster: undefined,
16                 projectUuid: undefined,
17                 inTrash: true,
18                 dateFrom: '',
19                 dateTo: '',
20                 properties: [{
21                     key: 'file size',
22                     value: '100mb'
23                 }, {
24                     key: 'user',
25                     value: 'daniel'
26                 }],
27                 saveQuery: false,
28                 queryName: ''
29             });
30         });
31
32         it('should correctly build advanced data record from query #2', () => {
33             const r = getAdvancedDataFromQuery('document from:2017-08-01 pdf has:"filesize":"101mb" is:trashed type:arvados#collection cluster:c97qx');
34             expect(r).toEqual({
35                 searchValue: 'document pdf',
36                 type: ResourceKind.COLLECTION,
37                 cluster: 'c97qx',
38                 projectUuid: undefined,
39                 inTrash: true,
40                 dateFrom: '2017-08-01',
41                 dateTo: '',
42                 properties: [{
43                     key: 'filesize',
44                     value: '101mb'
45                 }],
46                 saveQuery: false,
47                 queryName: ''
48             });
49         });
50     });
51
52     describe('getQueryFromAdvancedData', () => {
53         it('should build query from advanced data', () => {
54             const q = getQueryFromAdvancedData({
55                 searchValue: 'document pdf',
56                 type: ResourceKind.COLLECTION,
57                 cluster: 'c97qx',
58                 projectUuid: undefined,
59                 inTrash: true,
60                 dateFrom: '2017-08-01',
61                 dateTo: '',
62                 properties: [{
63                     key: 'file size',
64                     value: '101mb'
65                 }],
66                 saveQuery: false,
67                 queryName: ''
68             });
69             expect(q).toBe('document pdf type:arvados#collection cluster:c97qx is:trashed from:2017-08-01 has:"file size":"101mb"');
70         });
71     });
72 });