From 67fb70c2632351d70082a7c1d71e14a160b33613 Mon Sep 17 00:00:00 2001 From: Taylor Grafft Date: Thu, 30 Nov 2023 16:06:52 -0600 Subject: [PATCH] task/WP-304: Fixed the placeholder text for search to be more accurately represented (#905) * Fixed the placeholder text for search to be more accurately represented * adding tests for placeholder text --------- Co-authored-by: Taylor Grafft Co-authored-by: Taylor Grafft Co-authored-by: edmondsgarrett <43251554+edmondsgarrett@users.noreply.github.com> --- .../DataFilesListing/DataFilesListing.jsx | 22 +++++++- .../DataFilesListing/DataFilesListing.test.js | 56 +++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/client/src/components/DataFiles/DataFilesListing/DataFilesListing.jsx b/client/src/components/DataFiles/DataFilesListing/DataFilesListing.jsx index f291bde7ff..2abd8e6a00 100644 --- a/client/src/components/DataFiles/DataFilesListing/DataFilesListing.jsx +++ b/client/src/components/DataFiles/DataFilesListing/DataFilesListing.jsx @@ -2,7 +2,12 @@ import React, { useCallback, useLayoutEffect, useMemo } from 'react'; import PropTypes from 'prop-types'; import { useSelector, shallowEqual } from 'react-redux'; import { useLocation } from 'react-router-dom'; -import { useSelectedFiles, useFileListing } from 'hooks/datafiles'; +import { + useSelectedFiles, + useFileListing, + useSystems, + useSystemDisplayName, +} from 'hooks/datafiles'; import { CheckboxCell, CheckboxHeaderCell, @@ -14,6 +19,7 @@ import { } from './DataFilesListingCells'; import DataFilesTable from '../DataFilesTable/DataFilesTable'; import Searchbar from '_common/Searchbar'; +import { getCurrentDirectory } from '../DataFilesModals/DataFilesModalTables/DataFilesModalListingTable'; const fileTypes = [ 'Audio', @@ -142,6 +148,19 @@ const DataFilesListing = ({ api, scheme, system, path, isPublic }) => { return cells; }, [api, showViewPath, fileNavCellCallback]); + const { fetchSelectedSystem } = useSystems(); + const selectedSystem = fetchSelectedSystem({ scheme, system, path }); + const systemDisplayName = useSystemDisplayName({ scheme, system, path }); + const homeDir = selectedSystem?.homeDir; + + // Check if the current path is the home directory itself + const isAtHomeDir = path.replace(/^\/+/, '') === homeDir?.replace(/^\/+/, ''); + + // Determine the sectionName based on the path (if homeDir, use systemDisplayName--else use current dir) + const sectionName = isAtHomeDir + ? systemDisplayName + : getCurrentDirectory(path); + return ( <> {!hideSearchBar && ( @@ -149,6 +168,7 @@ const DataFilesListing = ({ api, scheme, system, path, isPublic }) => { api={api} scheme={scheme} system={system} + sectionName={sectionName} path={path} resultCount={files.length} dataType="Files" diff --git a/client/src/components/DataFiles/DataFilesListing/DataFilesListing.test.js b/client/src/components/DataFiles/DataFilesListing/DataFilesListing.test.js index 3d26c53f61..98863e3d97 100644 --- a/client/src/components/DataFiles/DataFilesListing/DataFilesListing.test.js +++ b/client/src/components/DataFiles/DataFilesListing/DataFilesListing.test.js @@ -7,6 +7,7 @@ import { render } from '@testing-library/react'; import '@testing-library/jest-dom'; import renderComponent from 'utils/testing'; import DataFilesListing from './DataFilesListing'; +import * as DataFilesModalListingTable from '../DataFilesModals/DataFilesModalTables/DataFilesModalListingTable'; import { CheckboxCell, FileNavCell } from './DataFilesListingCells'; import systemsFixture from '../fixtures/DataFiles.systems.fixture'; import filesFixture from '../fixtures/DataFiles.files.fixture'; @@ -250,3 +251,58 @@ describe('DataFilesListing', () => { expect(queryByText(/Search/)).toBeNull(); }); }); + +describe('DataFilesListing - Section Name Determination', () => { + const mockStore = configureStore(); + const store = mockStore(initialMockState); + + beforeEach(() => { + // Clear all mocks before each test + jest.clearAllMocks(); + }); + + it('sets sectionName to systemDisplayName when path is homeDir', () => { + jest + .spyOn(DataFilesModalListingTable, 'getCurrentDirectory') + .mockImplementationOnce(() => 'Mock System Name'); + + const { getByPlaceholderText } = render( + + + + + + ); + + expect(getByPlaceholderText('Search Mock System Name')).toBeInTheDocument(); + }); + + it('sets sectionName to current directory name when path is not homeDir', () => { + const currentDirName = 'Current Directory Name'; + jest + .spyOn(DataFilesModalListingTable, 'getCurrentDirectory') + .mockImplementationOnce(() => currentDirName); + + const { getByPlaceholderText } = render( + + + + + + ); + + expect( + getByPlaceholderText(`Search ${currentDirName}`) + ).toBeInTheDocument(); + }); +});