Skip to content

Commit

Permalink
MWPW-157987: Missing tests and card id copy message (#3024)
Browse files Browse the repository at this point in the history
* MWPW-157987: Missing tests and card id copy message

* MWPW-157987: add missing import

* MWPW-157987: Removed comment
  • Loading branch information
shkhan91 authored Nov 8, 2024
1 parent a7f61d1 commit 35a3102
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 3 additions & 1 deletion libs/blocks/caas-config/caas-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -966,13 +966,15 @@ const getPanels = (tagsData) => [
];

/* c8 ignore next 15 */
const addIdOverlays = () => {
export const addIdOverlays = () => {
document.querySelectorAll('.consonant-Card').forEach((card) => {
if (!card.querySelector('.cardid')) {
const idBtn = document.createElement('button');
idBtn.classList.add('cardid');
idBtn.innerText = card.id;

idBtn.title = 'Click to copy this ID';

idBtn.addEventListener('click', (e) => {
const id = e.target.textContent;
navigator.clipboard?.writeText(id);
Expand Down
24 changes: 23 additions & 1 deletion test/blocks/caas-config/caas-config.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import { runTests } from '@web/test-runner-mocha';
import { expect } from '@esm-bundle/chai';
import { stub } from 'sinon';
import { default as init, cloneObj, updateObj, getHashConfig } from '../../../libs/blocks/caas-config/caas-config.js';
import { default as init, cloneObj, updateObj, getHashConfig, addIdOverlays } from '../../../libs/blocks/caas-config/caas-config.js';
import {
findByLabel,
tagSelectorDropdownChoose,
Expand Down Expand Up @@ -352,6 +352,28 @@
expect(hashConfig.cardStyle).to.equal('full-card');
});

it('adds a button with a title attribute that shows hover message', async () => {
// Simulate a caas-config element with a .consonant-Card element
const cardElement = document.createElement('div');
cardElement.classList.add('consonant-Card');
cardElement.id = 'test-card-id';
document.body.appendChild(cardElement);

// Call the addIdOverlays function to add the button
addIdOverlays();

// Find the newly created button
const idButton = cardElement.querySelector('.cardid');

// Verify the button exists and the title is correctly set
expect(idButton).to.not.be.null;
expect(idButton.innerText).to.equal('test-card-id');
expect(idButton.title).to.equal('Click to copy this ID');

// Clean up after the test
document.body.removeChild(cardElement);
});

});
</script>
</html>

0 comments on commit 35a3102

Please sign in to comment.