Skip to content

Commit

Permalink
adding tests for placeholder text
Browse files Browse the repository at this point in the history
  • Loading branch information
Taylor Grafft committed Nov 27, 2023
1 parent 67605a7 commit 74eff1c
Showing 1 changed file with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
<Provider store={store}>
<BrowserRouter>
<DataFilesListing
api="tapis"
scheme="private"
system="test.system"
path="/home/user" // Same as homeDir
/>
</BrowserRouter>
</Provider>
);

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(
<Provider store={store}>
<BrowserRouter>
<DataFilesListing
api="tapis"
scheme="private"
system="test.system"
path="/home/user/some/other/dir" // Different from homeDir
/>
</BrowserRouter>
</Provider>
);

expect(
getByPlaceholderText(`Search ${currentDirName}`)
).toBeInTheDocument();
});
});

0 comments on commit 74eff1c

Please sign in to comment.