From e8f186479f083696c8ada55a485c70c0b9bf0b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Wed, 6 Mar 2019 13:13:40 +0200 Subject: [PATCH] Address tag selector tests race conditions. Addresses #1659 --- chrome/content/zotero/containers/tagSelector.jsx | 6 ++---- test/tests/tagSelectorTest.js | 11 +++++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/chrome/content/zotero/containers/tagSelector.jsx b/chrome/content/zotero/containers/tagSelector.jsx index 39b709637c..118c67fcf2 100644 --- a/chrome/content/zotero/containers/tagSelector.jsx +++ b/chrome/content/zotero/containers/tagSelector.jsx @@ -68,10 +68,10 @@ Zotero.TagSelector = class TagSelectorContainer extends React.Component { default: return; } + return this.setState({tags: await this.getTags()}); } - // Ignore item events other than 'trash' - if (type == 'item' && (event == 'trash')) { + if (type == 'item' || type == 'item-tag') { return this.setState({tags: await this.getTags()}); } @@ -90,8 +90,6 @@ Zotero.TagSelector = class TagSelectorContainer extends React.Component { } return; } - - this.setState({tags: await this.getTags()}); } async getTags(tagsInScope, tagColors) { diff --git a/test/tests/tagSelectorTest.js b/test/tests/tagSelectorTest.js index b75121848d..11acaa575f 100644 --- a/test/tests/tagSelectorTest.js +++ b/test/tests/tagSelectorTest.js @@ -418,8 +418,8 @@ describe("Tag Selector", function () { var promise = waitForTagSelector(win); - var item1 = await createDataObject('item', { tags: [{ tag: 'A' }] }); - var item2 = await createDataObject('item', { tags: [{ tag: 'B' }] }); + await createDataObject('item', { tags: [{ tag: 'A' }] }); + await createDataObject('item', { tags: [{ tag: 'B' }] }); await promise; tagSelector.handleTagSelected('A'); @@ -433,15 +433,18 @@ describe("Tag Selector", function () { // Remove tag from library promise = waitForTagSelector(win); await Zotero.Tags.removeFromLibrary(libraryID, Zotero.Tags.getID('A')); + // notify item-tag remove await promise; + // notify tag delete which triggers #onSelected, which eventually triggers #onItemViewChanged + await waitForTagSelector(win); // Deleted tag should no longer be shown or selected assert.notInclude(getRegularTags(), 'A'); assert.notInclude(Array.from(tagSelector.getTagSelection()), 'A'); // Other tags should be shown again assert.include(getRegularTags(), 'B'); - }) - }) + }); + }); describe("#openRenamePrompt", function () { it("should rename a tag and update the tag selector", function* () {