From 68d32d614f8686d54a95dd9c72c3e40eeb1b4863 Mon Sep 17 00:00:00 2001 From: Gabriel Duete Date: Wed, 12 Feb 2025 14:35:05 -0300 Subject: [PATCH] test(rich-tooltip): create tests --- .../rich-tooltip/rich-tooltip.spec.ts | 50 ++++++++++++++++++- .../src/components/tooltip/tooltip.spec.ts | 31 +++++------- 2 files changed, 60 insertions(+), 21 deletions(-) diff --git a/packages/core/src/components/rich-tooltip/rich-tooltip.spec.ts b/packages/core/src/components/rich-tooltip/rich-tooltip.spec.ts index 446c64922..0d5950615 100644 --- a/packages/core/src/components/rich-tooltip/rich-tooltip.spec.ts +++ b/packages/core/src/components/rich-tooltip/rich-tooltip.spec.ts @@ -1,3 +1,49 @@ -describe('RichTooltip', () => { - it.todo('test') +import { newSpecPage } from '@stencil/core/testing' + +import { AtomRichTooltip } from './rich-tooltip' + +describe('AtomRichTooltip', () => { + it('should render correctly', async () => { + const page = await newSpecPage({ + components: [AtomRichTooltip], + html: `Tooltip content`, + }) + + expect(page.root).toEqualHtml(` + + + +
+

Test Title

+

+ +

+
+
+
+ Tooltip content +
+ `) + }) + + it('should display action text when action is click', async () => { + const page = await newSpecPage({ + components: [AtomRichTooltip], + html: `Tooltip content`, + }) + + expect(page.root?.shadowRoot?.querySelector('.action')).not.toBeNull() + expect(page.root?.shadowRoot?.querySelector('.action')?.textContent).toBe( + 'Click me' + ) + }) + + it('should not display action text when action is hover', async () => { + const page = await newSpecPage({ + components: [AtomRichTooltip], + html: `Tooltip content`, + }) + + expect(page.root?.shadowRoot?.querySelector('.action')).toBeNull() + }) }) diff --git a/packages/core/src/components/tooltip/tooltip.spec.ts b/packages/core/src/components/tooltip/tooltip.spec.ts index 587cc96aa..18010d9af 100644 --- a/packages/core/src/components/tooltip/tooltip.spec.ts +++ b/packages/core/src/components/tooltip/tooltip.spec.ts @@ -9,7 +9,7 @@ describe('AtomTooltip', () => { open = false ) => ` - John Doe + John Doe ` const hoverTooltip = createTooltip('hover') @@ -23,17 +23,17 @@ describe('AtomTooltip', () => { }) expect(page.root).toEqualHtml(` - - -
-
- + + +
+
+ +
+
-
-
- - John Doe - + + John Doe + `) const element = page.body.querySelector('#hover') @@ -49,7 +49,7 @@ describe('AtomTooltip', () => { ) it.each(['mouseleave', 'blur'])( - 'should close tooptip when %s from target element', + 'should close tooltip when %s from target element', async (event) => { const page = await newSpecPage({ components: [AtomTooltip], @@ -62,17 +62,10 @@ describe('AtomTooltip', () => { await page.waitForChanges() - expect( - page.root?.shadowRoot?.querySelector('.atom-tooltip') - ).toHaveAttribute('data-show') - element?.dispatchEvent(new Event(event)) await page.waitForChanges() - expect( - page.root?.shadowRoot?.querySelector('.atom-tooltip') - ).not.toHaveAttribute('data-show') expect( page.root?.shadowRoot?.querySelector('.atom-tooltip') ).toHaveAttribute('data-hide')