Address tag selector tests race conditions. Addresses #1659

This commit is contained in:
Adomas Venčkauskas 2019-03-06 13:13:40 +02:00
parent ce1fc66351
commit e8f186479f
2 changed files with 9 additions and 8 deletions

View file

@ -68,10 +68,10 @@ Zotero.TagSelector = class TagSelectorContainer extends React.Component {
default: default:
return; return;
} }
return this.setState({tags: await this.getTags()});
} }
// Ignore item events other than 'trash' if (type == 'item' || type == 'item-tag') {
if (type == 'item' && (event == 'trash')) {
return this.setState({tags: await this.getTags()}); return this.setState({tags: await this.getTags()});
} }
@ -90,8 +90,6 @@ Zotero.TagSelector = class TagSelectorContainer extends React.Component {
} }
return; return;
} }
this.setState({tags: await this.getTags()});
} }
async getTags(tagsInScope, tagColors) { async getTags(tagsInScope, tagColors) {

View file

@ -418,8 +418,8 @@ describe("Tag Selector", function () {
var promise = waitForTagSelector(win); var promise = waitForTagSelector(win);
var item1 = await createDataObject('item', { tags: [{ tag: 'A' }] }); await createDataObject('item', { tags: [{ tag: 'A' }] });
var item2 = await createDataObject('item', { tags: [{ tag: 'B' }] }); await createDataObject('item', { tags: [{ tag: 'B' }] });
await promise; await promise;
tagSelector.handleTagSelected('A'); tagSelector.handleTagSelected('A');
@ -433,15 +433,18 @@ describe("Tag Selector", function () {
// Remove tag from library // Remove tag from library
promise = waitForTagSelector(win); promise = waitForTagSelector(win);
await Zotero.Tags.removeFromLibrary(libraryID, Zotero.Tags.getID('A')); await Zotero.Tags.removeFromLibrary(libraryID, Zotero.Tags.getID('A'));
// notify item-tag remove
await promise; await promise;
// notify tag delete which triggers #onSelected, which eventually triggers #onItemViewChanged
await waitForTagSelector(win);
// Deleted tag should no longer be shown or selected // Deleted tag should no longer be shown or selected
assert.notInclude(getRegularTags(), 'A'); assert.notInclude(getRegularTags(), 'A');
assert.notInclude(Array.from(tagSelector.getTagSelection()), 'A'); assert.notInclude(Array.from(tagSelector.getTagSelection()), 'A');
// Other tags should be shown again // Other tags should be shown again
assert.include(getRegularTags(), 'B'); assert.include(getRegularTags(), 'B');
}) });
}) });
describe("#openRenamePrompt", function () { describe("#openRenamePrompt", function () {
it("should rename a tag and update the tag selector", function* () { it("should rename a tag and update the tag selector", function* () {