15530: Link account page has link to home cluster
[arvados.git] / src / store / search-bar / search-bar-actions.test.ts
index 30b05157580af066a71031099afafc8904c3e1f5..51a73cc39b7a3e4e7680457fa522311c4697eefe 100644 (file)
@@ -2,47 +2,71 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { parseQuery } from "~/store/search-bar/search-bar-actions";
+import { getAdvancedDataFromQuery, getQueryFromAdvancedData } from "~/store/search-bar/search-bar-actions";
+import { ResourceKind } from "~/models/resource";
 
 describe('search-bar-actions', () => {
-    it('should correctly parse query #1', () => {
-        const q = 'val0 is:trashed val1';
-        const r = parseQuery(q);
-        expect(r.hasKeywords).toBeTruthy();
-        expect(r.values).toEqual(['val0', 'val1']);
-        expect(r.properties).toEqual({
-            is: 'trashed'
+    describe('getAdvancedDataFromQuery', () => {
+        it('should correctly build advanced data record from query #1', () => {
+            const r = getAdvancedDataFromQuery('val0 has:"file size":"100mb" val2 has:"user":"daniel" is:starred val2 val0 is:trashed');
+            expect(r).toEqual({
+                searchValue: 'val0 val2',
+                type: undefined,
+                cluster: undefined,
+                projectUuid: undefined,
+                inTrash: true,
+                dateFrom: '',
+                dateTo: '',
+                properties: [{
+                    key: 'file size',
+                    value: '100mb'
+                }, {
+                    key: 'user',
+                    value: 'daniel'
+                }],
+                saveQuery: false,
+                queryName: ''
+            });
         });
-    });
-
-    it('should correctly parse query #2 (value with keyword should be ignored)', () => {
-        const q = 'val0 is:from:trashed val1';
-        const r = parseQuery(q);
-        expect(r.hasKeywords).toBeTruthy();
-        expect(r.values).toEqual(['val0', 'val1']);
-        expect(r.properties).toEqual({
-            from: 'trashed'
-        });
-    });
 
-    it('should correctly parse query #3 (many keywords)', () => {
-        const q = 'val0 is:trashed val2 from:2017-04-01 val1';
-        const r = parseQuery(q);
-        expect(r.hasKeywords).toBeTruthy();
-        expect(r.values).toEqual(['val0', 'val2', 'val1']);
-        expect(r.properties).toEqual({
-            is: 'trashed',
-            from: '2017-04-01'
+        it('should correctly build advanced data record from query #2', () => {
+            const r = getAdvancedDataFromQuery('document from:2017-08-01 pdf has:"filesize":"101mb" is:trashed type:arvados#collection cluster:c97qx');
+            expect(r).toEqual({
+                searchValue: 'document pdf',
+                type: ResourceKind.COLLECTION,
+                cluster: 'c97qx',
+                projectUuid: undefined,
+                inTrash: true,
+                dateFrom: '2017-08-01',
+                dateTo: '',
+                properties: [{
+                    key: 'filesize',
+                    value: '101mb'
+                }],
+                saveQuery: false,
+                queryName: ''
+            });
         });
     });
 
-    it('should correctly parse query #4 (no duplicated values)', () => {
-        const q = 'val0 is:trashed val2 val2 val0';
-        const r = parseQuery(q);
-        expect(r.hasKeywords).toBeTruthy();
-        expect(r.values).toEqual(['val0', 'val2']);
-        expect(r.properties).toEqual({
-            is: 'trashed'
+    describe('getQueryFromAdvancedData', () => {
+        it('should build query from advanced data', () => {
+            const q = getQueryFromAdvancedData({
+                searchValue: 'document pdf',
+                type: ResourceKind.COLLECTION,
+                cluster: 'c97qx',
+                projectUuid: undefined,
+                inTrash: true,
+                dateFrom: '2017-08-01',
+                dateTo: '',
+                properties: [{
+                    key: 'file size',
+                    value: '101mb'
+                }],
+                saveQuery: false,
+                queryName: ''
+            });
+            expect(q).toBe('document pdf type:arvados#collection cluster:c97qx is:trashed from:2017-08-01 has:"file size":"101mb"');
         });
     });
 });