Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mwpw 162709 tooltip unit tests #3612

Merged
Merged
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 52 additions & 2 deletions test/features/icons/icons.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ document.body.innerHTML = await readFile({ path: './mocks/body.html' });

let icons;

describe('Icon Suppprt', () => {
describe('Icon Support', () => {
let paramsGetStub;

before(() => {
Expand Down Expand Up @@ -47,7 +47,7 @@ describe('Icon Suppprt', () => {
expect(svgs.length).to.equal(1);
});

it('Creates default tooltip', async () => {
it('Creates default tooltip ', async () => {
const tooltip = document.querySelector('.milo-tooltip.right');
expect(tooltip).to.exist;
expect(tooltip.dataset.tooltip).to.equal('This is my tooltip text.');
Expand All @@ -58,3 +58,53 @@ describe('Icon Suppprt', () => {
expect(tooltip).to.exist;
});
});

describe('Tooltip Integration with loadIcons', () => {
let iconTooltip;
let wrapper;
let normalIcon;

beforeEach(() => {
iconTooltip = createTag('span', { class: 'icon icon-tooltip' });
wrapper = createTag('em', {}, 'top|This is a tooltip text.');
wrapper.appendChild(iconTooltip);
document.body.appendChild(wrapper);

normalIcon = createTag('span', { class: 'icon icon-play' });
document.body.appendChild(normalIcon);
});

afterEach(() => {
document.body.innerHTML = '';
});

it('Should only decorate icons with "icon-tooltip" class', async () => {
await loadIcons([iconTooltip, normalIcon], config);

expect(iconTooltip.dataset.tooltip).to.equal('This is a tooltip text.');
expect(iconTooltip.classList.contains('milo-tooltip')).to.be.true;
expect(normalIcon.dataset.tooltip).to.be.undefined;
expect(normalIcon.classList.contains('milo-tooltip')).to.be.false;
});

it('Tooltip should not be visible by default', async () => {
await loadIcons([iconTooltip], config);

const tooltipContent = document.querySelector('.milo-tooltip[data-tooltip]');
expect(tooltipContent).to.exist;
expect(tooltipContent.style.display).to.equal('');
expect(tooltipContent.style.visibility).to.equal('');
});

it('Should replace wrapper with icon', async () => {
await loadIcons([iconTooltip], config);
expect(document.body.contains(wrapper)).to.be.false;
expect(document.body.contains(iconTooltip)).to.be.true;
});

it('Should assign correct default icon class and name', async () => {
await loadIcons([iconTooltip], config);
expect(iconTooltip.classList.contains('icon-info')).to.be.true;
expect(iconTooltip.dataset.name).to.be.undefined;
});
});
Loading