Skip to content

Commit

Permalink
test(tooltip): move non-screenshot tests to not run for all style con…
Browse files Browse the repository at this point in the history
…figurations
  • Loading branch information
max-umain committed Jan 14, 2025
1 parent 14c7cbe commit 61829c0
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 50 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 37 additions & 31 deletions packages/core/src/components/tooltip/test/click/tooltip.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,6 @@ testConfigurations.basic.forEach((config) => {
await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
});

test('Should not appear on hover', async ({ page }) => {
// Select the button that triggers the tooltip on click
const button = page.locator('tds-button#button-3');

await button.hover();

const tooltipText = page.locator('text=Text inside Tooltip');

// Assert that the tooltip is visible after clicking the button
await expect(tooltipText).toBeHidden();
});

test('Should appears on button click', async ({ page }) => {
// Select the button that triggers the tooltip on click
const button = page.locator('tds-button#button-3');
Expand All @@ -44,32 +32,50 @@ testConfigurations.basic.forEach((config) => {

await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
});
});
});

test('Should contain correct HTML content on click', async ({ page }) => {
// Hover over the button to trigger the tooltip
const button = page.locator('tds-button#button-3');
await button.click();
test.describe.parallel(componentName, () => {
test.beforeEach(async ({ page }) => {
await page.goto(componentTestPath);
});

const tooltipParagraph = page.locator('.tooltip-paragraph');
test('Should not appear on hover', async ({ page }) => {
// Select the button that triggers the tooltip on click
const button = page.locator('tds-button#button-3');

// Verify the paragraph is visible as part of the tooltip
await expect(tooltipParagraph).toBeVisible();
await button.hover();

// Fetch the inner HTML of the tooltip paragraph
let innerHtml = await tooltipParagraph.innerHTML();
const tooltipText = page.locator('text=Text inside Tooltip');

// Remove class attributes from the inner HTML for comparison
innerHtml = innerHtml.replace(/ class="[^"]*"/g, '').trim();
// Assert that the tooltip is visible after clicking the button
await expect(tooltipText).toBeHidden();
});

// Normalize whitespace in the inner HTML for comparison
innerHtml = innerHtml.replace(/\s+/g, ' ').trim();
test('Should contain correct HTML content on click', async ({ page }) => {
// Hover over the button to trigger the tooltip
const button = page.locator('tds-button#button-3');
await button.click();

// Define the expected HTML content, ensuring to trim any potential whitespace for a precise match
const expectedHtmlContent =
'Paragraph tag inside of Tooltip with <b>bold</b> and <i>italic</i> tags too.';
const tooltipParagraph = page.locator('.tooltip-paragraph');

// Perform the comparison to verify the tooltip's content
expect(innerHtml).toEqual(expectedHtmlContent);
});
// Verify the paragraph is visible as part of the tooltip
await expect(tooltipParagraph).toBeVisible();

// Fetch the inner HTML of the tooltip paragraph
let innerHtml = await tooltipParagraph.innerHTML();

// Remove class attributes from the inner HTML for comparison
innerHtml = innerHtml.replace(/ class="[^"]*"/g, '').trim();

// Normalize whitespace in the inner HTML for comparison
innerHtml = innerHtml.replace(/\s+/g, ' ').trim();

// Define the expected HTML content, ensuring to trim any potential whitespace for a precise match
const expectedHtmlContent =
'Paragraph tag inside of Tooltip with <b>bold</b> and <i>italic</i> tags too.';

// Perform the comparison to verify the tooltip's content
expect(innerHtml).toEqual(expectedHtmlContent);
});
});
44 changes: 25 additions & 19 deletions packages/core/src/components/tooltip/test/default/tooltip.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,38 @@ testConfigurations.basic.forEach((config) => {

await expect(page).toHaveScreenshot({ maxDiffPixels: 0 });
});
});
});

test('tooltip contains correct HTML content on hover', async ({ page }) => {
// Hover over the button to trigger the tooltip
const button = page.locator('tds-button#button-1');
await button.hover();
test.describe.parallel(componentName, () => {
test.beforeEach(async ({ page }) => {
await page.goto(componentTestPath);
});

const tooltipParagraph = page.locator('.tooltip-paragraph');
test('tooltip contains correct HTML content on hover', async ({ page }) => {
// Hover over the button to trigger the tooltip
const button = page.locator('tds-button#button-1');
await button.hover();

// Verify the paragraph is visible as part of the tooltip
await expect(tooltipParagraph).toBeVisible();
const tooltipParagraph = page.locator('.tooltip-paragraph');

// Fetch the inner HTML of the tooltip paragraph
let innerHtml = await tooltipParagraph.innerHTML();
// Verify the paragraph is visible as part of the tooltip
await expect(tooltipParagraph).toBeVisible();

// Normalize whitespace in the inner HTML for comparison
innerHtml = innerHtml.replace(/\s+/g, ' ').trim();
// Fetch the inner HTML of the tooltip paragraph
let innerHtml = await tooltipParagraph.innerHTML();

// Remove class attributes from the inner HTML
innerHtml = innerHtml.replace(/ class="[^"]*"/g, '');
// Normalize whitespace in the inner HTML for comparison
innerHtml = innerHtml.replace(/\s+/g, ' ').trim();

// Define the expected HTML content, ensuring to trim any potential whitespace for a precise match
const expectedHtmlContent =
'Paragraph tag inside of Tooltip with <b>bold</b> and <i>italic</i> tags too.';
// Remove class attributes from the inner HTML
innerHtml = innerHtml.replace(/ class="[^"]*"/g, '');

// Perform the comparison to verify the tooltip's content
expect(innerHtml).toEqual(expectedHtmlContent);
});
// Define the expected HTML content, ensuring to trim any potential whitespace for a precise match
const expectedHtmlContent =
'Paragraph tag inside of Tooltip with <b>bold</b> and <i>italic</i> tags too.';

// Perform the comparison to verify the tooltip's content
expect(innerHtml).toEqual(expectedHtmlContent);
});
});

0 comments on commit 61829c0

Please sign in to comment.