Skip to content

Commit

Permalink
HARMONY-1978: Add some tests for label creation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
vinnyinverso committed Jan 21, 2025
1 parent 2ea5726 commit 015140b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions services/harmony/public/js/workflow-ui/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ labelsModule = {
showAllLabels,
toggleLabelNavVisibility,
insertNewLabelAlphabetically,
handleLabelsResponse,
};

export default labelsModule;
12 changes: 8 additions & 4 deletions services/harmony/public/js/workflow-ui/toasts.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,20 @@ export default {
* @param {string} text - the text for the toast
*/
showUpper(text) {
setToastText(upperToastId, text);
toastObj[upperToastId].show();
if (Object.keys(toastObj).length) {
setToastText(upperToastId, text);
toastObj[upperToastId].show();
}
},

/**
* Set the text of the lower toast and show it.
* @param {string} text - the text for the toast
*/
showLower(text) {
setToastText(lowerToastId, text);
toastObj[lowerToastId].show();
if (Object.keys(toastObj).length) {
setToastText(lowerToastId, text);
toastObj[lowerToastId].show();
}
},
};
20 changes: 20 additions & 0 deletions services/harmony/test/workflow-ui/labels-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ beforeEach(async () => {
});

describe('labels.js', () => {
describe('handleLabelsResponse', () => {
it('inserts a new label when insertNew is true', async () => {
await Labels.handleLabelsResponse({ status: 201 }, 'a new one', true, 'it worked!');
const labelsListElement = document.getElementById('labels-list');
expect(labelsListElement.querySelector('a[name="a new one"]')).to.not.be.undefined;
});
});
describe('insertNewLabelAlphabetically', () => {
it('inserts a new label alphabetically, in the proper position', async () => {
await Labels.insertNewLabelAlphabetically('purple');
const labelsListElement = document.getElementById('labels-list');
const labelItems = Array.from(labelsListElement.getElementsByClassName('label-li'));
const insertIndex = labelItems.findIndex((item) => {
const itemText = item.querySelector('a').getAttribute('data-value')
.toLowerCase();
return itemText === 'purple';
});
expect(insertIndex).to.equal(2);
});
});
describe('promoteLabels', () => {
it('promotes the given list of labels', () => {
const labelsListElement = document.getElementById('labels-list');
Expand Down

0 comments on commit 015140b

Please sign in to comment.