Skip to content
Snippets Groups Projects
Commit 62cf7e93 authored by Hélène Jonin's avatar Hélène Jonin
Browse files

Refactor Permalinks box

parent ba351e0d
No related branches found
No related tags found
1 merge request!1315Refactor Permalinks box
Pipeline #10722 passed
......@@ -259,4 +259,34 @@ describe('SWHIDs Tests', function() {
});
});
it('should update copy buttons after clicking on them', function() {
cy.get('.ui-slideouttab-handle')
.click();
for (const td of testsData) {
cy.get(`a[href="#swhid-tab-${td.objectType}"]`)
.click();
cy.get(`#swhid-tab-${td.objectType}`)
.should('be.visible');
cy.get(`#swhid-tab-${td.objectType} .btn-swhid-copy`)
.should('contain.text', 'Copy identifier')
.should('not.contain.text', 'Copied!')
.click()
.should('have.text', 'Copied!')
.wait(1001)
.should('not.contain.text', 'Copied!')
.should('contain.text', 'Copy identifier');
cy.get(`#swhid-tab-${td.objectType} .btn-swhid-url-copy`)
.should('contain.text', 'Copy permalink')
.should('not.contain.text', 'Copied!')
.click()
.should('have.text', 'Copied!')
.wait(1001)
.should('not.contain.text', 'Copied!')
.should('contain.text', 'Copy permalink');
}
});
});
......@@ -96,11 +96,26 @@ function updateSWHIDsTabSize() {
}
$(document).ready(() => {
const toggleButtonText = (button, text) => {
const currentLabel = button.innerHTML;
if (currentLabel === text) {
return;
}
button.innerHTML = text;
setTimeout(function() {
button.innerHTML = currentLabel;
}, 1000);
};
new ClipboardJS('.btn-swhid-copy', {
text: trigger => {
const swhId = $(trigger).closest('.swhid-ui').find('.swhid').text();
return swhId.replace(/;\n/g, ';');
}
}).on('success', function(e) {
toggleButtonText(e.trigger, 'Copied!');
});
new ClipboardJS('.btn-swhid-url-copy', {
......@@ -108,6 +123,8 @@ $(document).ready(() => {
const swhIdUrl = $(trigger).closest('.swhid-ui').find('.swhid').attr('href');
return window.location.origin + swhIdUrl;
}
}).on('success', function(e) {
toggleButtonText(e.trigger, 'Copied!');
});
// prevent automatic closing of SWHIDs tab during guided tour
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment