Skip to content

Commit

Permalink
Fix: don't select work in MergeUI when 'want to read' is clicked
Browse files Browse the repository at this point in the history
Stop selecting works in the MergeUI want clicking 'want to read' or any other button in that dropdown.
  • Loading branch information
Billa05 authored Dec 3, 2023
1 parent 308a35d commit 9e7f5ba
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default class SelectionManager {
processClick(clickEvent) {
// If there is text selection or the click is on a link that isn't a select handle, don't do anything
if ((!clickEvent.shiftKey && window.getSelection()?.toString() !== '') ||
($(clickEvent.target).closest('a').is('a') &&
($(clickEvent.target).closest('a, button').length > 0 &&
$(clickEvent.target).not('.ile-select-handle').length > 0)) return;

const el = clickEvent.currentTarget;
Expand Down
58 changes: 58 additions & 0 deletions tests/unit/js/SelectionManager.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
import SelectionManager from '../../../openlibrary/plugins/openlibrary/js/ile/utils/SelectionManager/SelectionManager.js';

function createTestElementsForProcessClick() {
const listItem = document.createElement('li');
listItem.classList.add('searchResultItem', 'ile-selectable');

const link = document.createElement('a');
listItem.appendChild(link);

const bookTitle = document.createElement('div');
bookTitle.classList.add('booktitle');
const bookLink = document.createElement('a');
bookLink.href = 'OL12345W'; // Mock href value
bookTitle.appendChild(bookLink);

listItem.appendChild(bookTitle);

return {listItem,link};
}

function setupSelectionManager() {
const sm = new SelectionManager(null, '/search');
sm.ile = { $statusImages: { append: jest.fn() } };
sm.selectedItems = { work: [] };
sm.updateToolbar = jest.fn();
return sm;
}

describe('SelectionManager', () => {
afterEach(() => {
Expand All @@ -26,4 +51,37 @@ describe('SelectionManager', () => {
author: [],
});
});


test('processClick - clicking on a link or button', () => {
const sm = setupSelectionManager();
const { listItem,link } = createTestElementsForProcessClick();

link.addEventListener('click', () => {
sm.processClick({ target: link, currentTarget: listItem });
});

expect(listItem.classList.contains('ile-selected')).toBe(false);
link.click();
expect(listItem.classList.contains('ile-selected')).toBe(false);

jest.clearAllMocks();
});

test('processClick - clicking on listItem', () => {
const sm = setupSelectionManager();
const { listItem } = createTestElementsForProcessClick();

listItem.addEventListener('click', () => {
sm.processClick({ target: listItem, currentTarget: listItem });
});

expect(listItem.classList.contains('ile-selected')).toBe(false);
listItem.click();
expect(listItem.classList.contains('ile-selected')).toBe(true);
listItem.click();
expect(listItem.classList.contains('ile-selected')).toBe(false);

jest.clearAllMocks();
});
});

0 comments on commit 9e7f5ba

Please sign in to comment.