TagSpaces is an offline, open source, document manager with tagging support
add TST0624 TST0625 and fix SearchPopover
Stanimir04952dbaa4d2
diff --git a/app/components/FolderContainer.tsx b/app/components/FolderContainer.tsxindex 12feee446..00df7c3f7 100644--- a/app/components/FolderContainer.tsx+++ b/app/components/FolderContainer.tsx@@ -549,7 +549,10 @@ function FolderContainer(props: Props) {)}{props.isSearchMode ? (/* todo rethink if open props is needed */- <SearchBox open={props.isSearchMode} />+ <SearchBox+ open={props.isSearchMode}+ textQuery={props.searchQuery.textQuery}+ />) : (<><divdiff --git a/app/components/SearchAutocomplete.tsx b/app/components/SearchAutocomplete.tsxindex bce137946..db66bafc8 100644--- a/app/components/SearchAutocomplete.tsx+++ b/app/components/SearchAutocomplete.tsx@@ -102,6 +102,8 @@ interface Props {searches: Array<TS.SearchQuery>;switchLocationTypeByID: (locationId: string) => Promise<string | null>;// editedEntryPaths: Array<TS.EditedEntryPath>;+ getTextQuery: () => string;+ setTextQuery: (value: string) => void;}const useStyles = makeStyles(theme => ({@@ -140,7 +142,7 @@ function SearchAutocomplete(props: Props) {const actionValues = useRef<Array<SearchOptionType>>([] //parseSearchQuery(textQueryMask.current));- const inputValue = useRef<string>(props.searchQuery.textQuery || ''); //getInputValue());+ // const inputValue = useRef<string>(props.searchQuery.textQuery || ''); //getInputValue());// const searchBoxing = useRef<'location' | 'folder' | 'global'>(// props.searchQuery.searchBoxing ? props.searchQuery.searchBoxing : 'location'@@ -247,15 +249,15 @@ function SearchAutocomplete(props: Props) {// inputValue.current = getInputValue();if (props.searchQuery.textQuery) {- inputValue.current = props.searchQuery.textQuery;+ props.setTextQuery(props.searchQuery.textQuery);emptySearch = false;- } else if (inputValue.current) {+ } else if (props.getTextQuery()) {emptySearch = false;}const searchQuery = {...props.searchQuery,- textQuery: inputValue.current+ textQuery: props.getTextQuery()};/*if (mainSearchField.current) {@@ -414,7 +416,10 @@ function SearchAutocomplete(props: Props) {forceUpdate();}} else if (event.key === 'Backspace' || event.keyCode === 8) {- if (inputValue.current.length === 0 && actionValues.current.length > 0) {+ if (+ props.getTextQuery().length === 0 &&+ actionValues.current.length > 0+ ) {actionValues.current = actionValues.current.slice(0, -1);resetActions(actionValues.current);isOpen.current = true;@@ -426,7 +431,7 @@ function SearchAutocomplete(props: Props) {};function resetValues(exceptions: Array<SearchOptionType>) {- inputValue.current = '';+ props.setTextQuery('');if (!exceptions.some(action =>isAction(action.action, SearchQueryComposition.SCOPE)@@ -594,7 +599,7 @@ function SearchAutocomplete(props: Props) {// don't execute search on search filterreturn;}- let query = inputValue.current;+ let query = props.getTextQuery();if (query.startsWith('ts:?ts') ||query.startsWith(AppConfig.tsProtocol + '?ts')@@ -1190,7 +1195,7 @@ function SearchAutocomplete(props: Props) {// executeSearch();} else if (option.action === undefined) {// text query- inputValue.current = option.label;+ props.setTextQuery(option.label);const pAction = actions[actions.length - 1];if (pAction && isAction(pAction.action, SearchActions.FILTER)) {@@ -1241,7 +1246,7 @@ function SearchAutocomplete(props: Props) {const inputArr = valueArr.filter(action => !actionValues.current.some(v => v.label === action));- inputValue.current = inputArr.join(' ');+ props.setTextQuery(inputArr.join(' '));//textQuery.current += ' ' + inputValue.current;forceUpdate();} else if (reason === 'clear') {@@ -1249,7 +1254,7 @@ function SearchAutocomplete(props: Props) {} else if (reason === 'reset') {if (event.type === 'keydown' || event.type === 'click') {// textQuery.current += ' ' + inputValue.current;- inputValue.current = '';+ props.setTextQuery('');} else if (event.type === 'blur') {}// executeSearch();@@ -1466,7 +1471,7 @@ function SearchAutocomplete(props: Props) {v.fullName ? v.fullName : v.label)}onChange={handleChange}- inputValue={inputValue.current}+ inputValue={props.getTextQuery()}onInputChange={handleInputChange}open={isOpen.current}/*onOpen={handleOpen}diff --git a/app/components/SearchBox.tsx b/app/components/SearchBox.tsxindex ef2205e5c..3d5d62459 100644--- a/app/components/SearchBox.tsx+++ b/app/components/SearchBox.tsx@@ -16,7 +16,7 @@**/-import React, { useState } from 'react';+import React, { useState, useRef } from 'react';import Tooltip from '-/components/Tooltip';import IconButton from '@mui/material/IconButton';import i18n from '-/services/i18n';@@ -28,12 +28,22 @@ import SearchAutocomplete from '-/components/SearchAutocomplete';interface Props {open: boolean;+ textQuery: string;}function SearchBox(props: Props) {const [anchorSearch, setAnchorSearch] = useState<HTMLButtonElement | null>(null);+ const textQuery = useRef<string>(props.textQuery || '');++ function getTextQuery() {+ return textQuery.current;+ }++ function setTextQuery(value) {+ textQuery.current = value;+ }// const searchInlineRef = React.useRef<HTMLDivElement | null>(null);/* useEffect(() => {@@ -44,7 +54,11 @@ function SearchBox(props: Props) {return (<>- <SearchAutocomplete open={props.open} />+ <SearchAutocomplete+ open={props.open}+ getTextQuery={getTextQuery}+ setTextQuery={setTextQuery}+ />{/*<SearchInline open={props.open} />*/}{props.open && (<>@@ -79,7 +93,11 @@ function SearchBox(props: Props) {horizontal: 'right'}}>- <SearchPopover onClose={() => setAnchorSearch(null)} />+ <SearchPopover+ onClose={() => setAnchorSearch(null)}+ getTextQuery={getTextQuery}+ setTextQuery={setTextQuery}+ /></Popover></>)}diff --git a/app/components/SearchPopover.tsx b/app/components/SearchPopover.tsxindex 361783bee..a6f46254c 100644--- a/app/components/SearchPopover.tsx+++ b/app/components/SearchPopover.tsx@@ -104,6 +104,8 @@ interface Props {showUnixHiddenEntries: boolean;// openSearchPanel: () => void;onClose: () => void;+ getTextQuery: () => string;+ setTextQuery: (value: string) => void;}const useStyles = makeStyles<Theme, StyleProps>(styles);@@ -112,7 +114,7 @@ function SearchPopover(props: Props) {// @ts-ignoreconst classes: PropsClasses = useStyles({} as StyleProps);const [, forceUpdate] = useReducer(x => x + 1, 0);- const textQuery = useRef<string>(props.searchQuery.textQuery);+ // const textQuery = useRef<string>(props.searchQuery.textQuery);// const tagsAND = useRef<Array<TS.Tag>>(props.searchQuery.tagsAND);const fileTypes = useRef<Array<string>>(props.searchQuery.fileTypes@@ -154,33 +156,9 @@ function SearchPopover(props: Props) {props.searchQuery.fileSize ? props.searchQuery.fileSize : '');- useEffect(() => {- textQuery.current = props.searchQuery.textQuery;- /* if (props.searchQuery.fileTypes) {- fileTypes.current = props.searchQuery.fileTypes;- }- if (props.searchQuery.searchBoxing) {- searchBoxing.current = props.searchQuery.searchBoxing;- }- if (props.searchQuery.searchType) {- searchType.current = props.searchQuery.searchType;- }- if (props.searchQuery.lastModified) {- lastModified.current = props.searchQuery.lastModified;- }- if (props.searchQuery.tagTimePeriodFrom) {- tagTimePeriodFrom.current = props.searchQuery.tagTimePeriodFrom;- }- if (props.searchQuery.tagTimePeriodTo) {- tagTimePeriodTo.current = props.searchQuery.tagTimePeriodTo;- }- if (props.searchQuery.forceIndexing) {- forceIndexing.current = props.searchQuery.forceIndexing;- }- if (props.searchQuery.fileSize) {- fileSize.current = props.searchQuery.fileSize;- } */- }, [props.searchQuery]);+ /* useEffect(() => {+ props.setTextQuery(props.searchQuery.textQuery);+ }, [props.searchQuery]);*/const handleFileTypeChange = (event: React.ChangeEvent<HTMLInputElement>) => {const { target } = event;@@ -244,7 +222,7 @@ function SearchPopover(props: Props) {if (!savedSearch) {return true;}- textQuery.current = savedSearch.textQuery;+ props.setTextQuery(savedSearch.textQuery);fileTypes.current = savedSearch.fileTypes;lastModified.current = savedSearch.lastModified;fileSize.current = savedSearch.fileSize;@@ -391,7 +369,7 @@ function SearchPopover(props: Props) {}const clearSearch = () => {- textQuery.current = '';+ props.setTextQuery('');searchBoxing.current = 'location';searchType.current = 'fuzzy';fileTypes.current = FileTypeGroups.any;@@ -415,24 +393,24 @@ function SearchPopover(props: Props) {const saveSearch = (isNew = true) => {const tagsAND = mergeWithExtractedTags(- textQuery.current,+ props.getTextQuery(),props.searchQuery.tagsAND,'+');const tagsOR = mergeWithExtractedTags(- textQuery.current,+ props.getTextQuery(),props.searchQuery.tagsOR,'|');const tagsNOT = mergeWithExtractedTags(- textQuery.current,+ props.getTextQuery(),props.searchQuery.tagsNOT,'-');setSaveSearchDialogOpened({uuid: isNew ? undefined : props.searchQuery.uuid,title: props.searchQuery.title,- textQuery: textQuery.current,+ textQuery: props.getTextQuery(),tagsAND,tagsOR,tagsNOT,@@ -474,22 +452,22 @@ function SearchPopover(props: Props) {const executeSearch = () => {const tagsAND = mergeWithExtractedTags(- textQuery.current,+ props.getTextQuery(),props.searchQuery.tagsAND,'+');const tagsOR = mergeWithExtractedTags(- textQuery.current,+ props.getTextQuery(),props.searchQuery.tagsOR,'|');const tagsNOT = mergeWithExtractedTags(- textQuery.current,+ props.getTextQuery(),props.searchQuery.tagsNOT,'-');const searchQuery: TS.SearchQuery = {- textQuery: textQuery.current,+ textQuery: props.getTextQuery(),tagsAND,tagsOR,tagsNOT,diff --git a/app/components/dialogs/OnboardingDialog.tsx b/app/components/dialogs/OnboardingDialog.tsxindex b724c4553..4a9d5a1f6 100644--- a/app/components/dialogs/OnboardingDialog.tsx+++ b/app/components/dialogs/OnboardingDialog.tsx@@ -124,7 +124,7 @@ function OnboardingDialog(props: Props) {src={NewLook}alt=""/>- <Typography variant="h6">Try our our dark theme!</Typography>+ <Typography variant="h6">Try our dark theme!</Typography><Typography variant="h6"> </Typography><ToggleButtonGroupvalue={props.currentTheme}diff --git a/tests/e2e/search.pw.e2e.js b/tests/e2e/search.pw.e2e.jsindex d1c6d52d5..c36c62109 100644--- a/tests/e2e/search.pw.e2e.js+++ b/tests/e2e/search.pw.e2e.js@@ -21,7 +21,8 @@ import {emptyFolderName,searchEngine,testFilename,- addRemoveTagsInSearchResults+ addRemoveTagsInSearchResults,+ createSavedSearch} from './search.helpers';import { init } from './welcome.helpers';import { openContextEntryMenu } from './test-utils';@@ -150,6 +151,45 @@ test.describe('TST06 - Test Search in file structure:', () => {);});+ test('TST0624 - Search actions - bookmarks [web,electron]', async () => {+ const bookmarkFileTitle = 'sample.txt';+ await openContextEntryMenu(+ '[data-tid="fsEntryName_' + bookmarkFileTitle + '"]',+ 'fileMenuOpenFile'+ );++ // Create+ await clickOn('[data-tid=toggleBookmarkTID]');+ await clickOn('[data-tid=fileContainerCloseOpenedFile]');++ await searchEngine('b:', {}, false);+ await clickOn('#textQuery-option-0');+ await expectElementExist(+ '[data-tid=OpenedTID' + dataTidFormat(bookmarkFileTitle) + ']',+ true+ );+ });++ test('TST0625 - Search actions - execute query from stored searches [web,electron]', async () => {+ const storedSearchTitle = 'jpgSearch';+ await createSavedSearch({ title: storedSearchTitle, textQuery: 'jpg' });++ await searchEngine('q:', {}, false);+ await clickOn('#textQuery-option-0');+ // expect to not exist other than jpg files extensions like txt+ await expectElementExist(getGridFileSelector('sample.txt'), false, 5000);+ });++ test('TST0626 - Search actions - execute query from search history [web,electron]', async () => {+ await searchEngine('txt');+ await clickOn('#clearSearchID');++ await searchEngine('s:', {}, false);+ await clickOn('#textQuery-option-0');+ // expect to not exist other than txt files extensions like jpg+ await expectElementExist(getGridFileSelector('sample.jpg'), false, 5000);+ });+test('TST0639 - Add/Remove sidecar tags in search results [web,electron]', async () => {await setSettings('[data-tid=settingsSetPersistTagsInSidecarFile]', true);await addRemoveTagsInSearchResults(['sidecar-tag5', 'sidecar-tag6']);