Skip to content

Commit

Permalink
Prevent special characters from breaking notes search
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Ladyman committed Jan 11, 2025
1 parent 6dbb679 commit 555ebc8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
1 change: 1 addition & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'cross-fetch/polyfill';
import server from './test-integration/mocks/server';

window.HTMLElement.prototype.scrollIntoView = () => {};
window.scrollTo = () => {};

beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dnd-battle-tracker",
"version": "5.117.1",
"version": "5.117.2",
"private": true,
"dependencies": {
"@apollo/client": "^3.12.4",
Expand Down
5 changes: 1 addition & 4 deletions src/components/creature/toolbar/tools/NotesTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ export default function NotesTool({
}) {
const [value, setValue] = useState('');

const notes = allNotes.filter((note) => {
const noteRegex = new RegExp(value);
return noteRegex.test(note.text);
});
const notes = allNotes.filter((note) => note.text.toLowerCase().includes(value.toLowerCase()));

const notesDropdownId = `notes-dropdown-${id}`;
const notesAriaLabel = `${name} notes`;
Expand Down
5 changes: 3 additions & 2 deletions src/components/view/ViewSwitcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ export default function ViewSwitcher({ views }) {
<nav className="navigation">
<ul className="navigation-options">
{views.map((view, i) => {
const { id, title } = view;
const activeClass = i === viewIndex ? 'navigation-option__active' : '';
return (
<li>
<button className={`navigation-option ${activeClass}`} type="button" onClick={() => setViewIndex(i)}>{view.title}</button>
<li key={id}>
<button className={`navigation-option ${activeClass}`} type="button" onClick={() => setViewIndex(i)}>{title}</button>
</li>
);
})}
Expand Down
27 changes: 27 additions & 0 deletions test-integration/creature-toolbar/notes-tool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,33 @@ describe('Creature note tool', () => {
dmApp.creatureToolbar.assertCreatureNotesLength('goblin', 1);
});

it('ignores case of note when searching notes', async () => {
const dmApp = new DmApp();
await dmApp.createCreatureForm.addCreature('goblin');
await dmApp.creatureToolbar.selectTool('goblin', 'Notes');
await dmApp.creatureToolbar.addNote('goblin', 'One');
await dmApp.creatureToolbar.typeNote('goblin', 'o');
await dmApp.creatureToolbar.assertCreatureNoteExists('goblin', 'One');
});

it('ignores case of search term when searching notes', async () => {
const dmApp = new DmApp();
await dmApp.createCreatureForm.addCreature('goblin');
await dmApp.creatureToolbar.selectTool('goblin', 'Notes');
await dmApp.creatureToolbar.addNote('goblin', 'one');
await dmApp.creatureToolbar.typeNote('goblin', 'O');
await dmApp.creatureToolbar.assertCreatureNoteExists('goblin', 'one');
});

it('allows a note to be searched with special characters', async () => {
const dmApp = new DmApp();
await dmApp.createCreatureForm.addCreature('goblin');
await dmApp.creatureToolbar.selectTool('goblin', 'Notes');
await dmApp.creatureToolbar.addNote('goblin', 'one \\');
await dmApp.creatureToolbar.typeNote('goblin', '\\');
await dmApp.creatureToolbar.assertCreatureNoteExists('goblin', 'one \\');
});

it('selects the last note when navigating up from a closed note tool', async () => {
const dmApp = new DmApp();
await dmApp.createCreatureForm.addCreature('goblin');
Expand Down

0 comments on commit 555ebc8

Please sign in to comment.