X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/34399d176adae18bd42d70129c0a51f740afeb8e..936aa32e065b7f672e27b95262720c2ce8258bf6:/src/store/search-bar/search-bar-actions.test.ts diff --git a/src/store/search-bar/search-bar-actions.test.ts b/src/store/search-bar/search-bar-actions.test.ts index 30b05157..aa6e4759 100644 --- a/src/store/search-bar/search-bar-actions.test.ts +++ b/src/store/search-bar/search-bar-actions.test.ts @@ -2,47 +2,136 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { parseQuery } from "~/store/search-bar/search-bar-actions"; +import { getAdvancedDataFromQuery, getQueryFromAdvancedData, parseSearchQuery } from "~/store/search-bar/search-bar-actions"; +import { ResourceKind } from "~/models/resource"; +import { ClusterObjectType } from "~/models/search-bar"; 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('parseSearchQuery', () => { + it('should correctly parse query #1', () => { + const q = 'val0 is:trashed val1'; + const r = parseSearchQuery(q); + expect(r.hasKeywords).toBeTruthy(); + expect(r.values).toEqual(['val0', 'val1']); + expect(r.properties).toEqual({ + is: ['trashed'] + }); + }); + + it('should correctly parse query #2 (value with keyword should be ignored)', () => { + const q = 'val0 is:from:trashed val1'; + const r = parseSearchQuery(q); + expect(r.hasKeywords).toBeTruthy(); + expect(r.values).toEqual(['val0', 'val1']); + expect(r.properties).toEqual({ + from: ['trashed'] + }); }); - }); - 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 = parseSearchQuery(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 parse query #4 (no duplicated values)', () => { + const q = 'val0 is:trashed val2 val2 val0'; + const r = parseSearchQuery(q); + expect(r.hasKeywords).toBeTruthy(); + expect(r.values).toEqual(['val0', 'val2']); + expect(r.properties).toEqual({ + is: ['trashed'] + }); + }); + + it('should correctly parse query #5 (properties)', () => { + const q = 'val0 has:filesize:100mb val2 val2 val0'; + const r = parseSearchQuery(q); + expect(r.hasKeywords).toBeTruthy(); + expect(r.values).toEqual(['val0', 'val2']); + expect(r.properties).toEqual({ + 'has': ['filesize:100mb'] + }); + }); + + it('should correctly parse query #6 (multiple properties, multiple is)', () => { + const q = 'val0 has:filesize:100mb val2 has:user:daniel is:starred val2 val0 is:trashed'; + const r = parseSearchQuery(q); + expect(r.hasKeywords).toBeTruthy(); + expect(r.values).toEqual(['val0', 'val2']); + expect(r.properties).toEqual({ + 'has': ['filesize:100mb', 'user:daniel'], + 'is': ['starred', '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' + describe('getAdvancedDataFromQuery', () => { + it('should correctly build advanced data record from query #1', () => { + const r = getAdvancedDataFromQuery('val0 has:filesize: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: undefined, + dateTo: undefined, + properties: [{ + key: 'filesize', + value: '100mb' + }, { + key: 'user', + value: 'daniel' + }], + saveQuery: false, + queryName: '' + }); + }); + + 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:indianapolis'); + expect(r).toEqual({ + searchValue: 'document pdf', + type: ResourceKind.COLLECTION, + cluster: ClusterObjectType.INDIANAPOLIS, + projectUuid: undefined, + inTrash: true, + dateFrom: '2017-08-01', + dateTo: undefined, + 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: ClusterObjectType.INDIANAPOLIS, + projectUuid: undefined, + inTrash: true, + dateFrom: '2017-08-01', + dateTo: '', + properties: [{ + key: 'filesize', + value: '101mb' + }], + saveQuery: false, + queryName: '' + }); + expect(q).toBe('document pdf type:arvados#collection cluster:indianapolis is:trashed from:2017-08-01 has:filesize:101mb'); }); }); });