Skip to content

Commit

Permalink
fix(react-components): add snapshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
corteggiano committed May 9, 2024
1 parent e512db5 commit 49504a6
Show file tree
Hide file tree
Showing 47 changed files with 439 additions and 585 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ test.describe('Data Stream Maxes', () => {
.getByTestId(MAX_TABLE_CELL)
.first()
.innerText();
console.log('value', updatedMaxValueString);
expect(getDecimalPlaces(updatedMaxValueString)).toBe(1);
});
});
11 changes: 11 additions & 0 deletions packages/react-components/e2e/tests/chart/chart.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { test, expect } from '@playwright/test';

const TEST_PAGE = '/iframe.html?id=widgets-base-chart--default-base-chart';

test('line chart default settings', async ({ page }) => {
await page.goto(TEST_PAGE);
const LineChart = page.getByTestId('base-chart-container');

// screenshot comparison with everything showing
await expect(LineChart).toHaveScreenshot('line-chart-default-settings.png');
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 0 additions & 46 deletions packages/react-components/e2e/tests/charts/charts.spec.ts

This file was deleted.

83 changes: 21 additions & 62 deletions packages/react-components/e2e/tests/gauge/gauge.spec.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,28 @@
import { test, expect } from '@playwright/test';

const TEST_IFRAME = '#storybook-preview-iframe';
const TEST_PAGE = '/?path=/story/widgets-gauge-gauge-base--main';
const TEST_DATA_ID = 'gauge-base-component';
const TEST_PAGE = '/iframe.html?id=widgets-gauge--default-gauge';
const TEST_PAGE_HIDDEN_SETTINGS =
'/iframe.html?id=widgets-gauge--hidden-settings-gauge';
const THRESHOLD_TEST_PAGE = '/iframe.html?id=widgets-gauge--threshold-gauge';

test('guage', async ({ page }) => {
test('default guage', async ({ page }) => {
await page.goto(TEST_PAGE);
await page.evaluate(() => document.fonts.ready);
const frame = page.frameLocator(TEST_IFRAME); // Need to go into frame otherwise the `locator` won't locate the selection.
const GaugeComponent = frame.getByTestId('gauge-base-component');
const GaugeError = frame.getByTestId('gauge-base-component-error');

// Gauge component should be visible
await expect(GaugeComponent).toBeVisible();

// Gauge should displays 'Uncertain Quality' for 'UNCERTAIN' quality
await page.goto(`${TEST_PAGE}&args=propertyPoint.quality:UNCERTAIN`);
await expect(GaugeComponent).toContainText('Uncertain Quality');

// Gauge should displays 'Bad Quality' for 'BAD' quality
await page.goto(`${TEST_PAGE}&args=propertyPoint.quality:BAD`);
await expect(GaugeComponent).toContainText('Bad Quality');

// Gauge should display error text when error is provided
const errorMsg = 'No Network';
await page.goto(`${TEST_PAGE}&args=error:${errorMsg}`);
await expect(GaugeError).toContainText(errorMsg);

// Gauge default settings
const gaugeValueElement = GaugeComponent.getByText('82');
const gaugeUnitElement = GaugeComponent.getByText('%');
const gaugeOutsideArcLabelelement = GaugeComponent.getByText('100');
await page.goto(`${TEST_PAGE}`);
await expect(GaugeComponent).not.toContainText('Windmill');
await expect(GaugeComponent).toContainText('%');
await expect(gaugeValueElement).toHaveCSS('font-size', '40px');
await expect(gaugeUnitElement).toHaveCSS('font-size', '16px');
await expect(gaugeOutsideArcLabelelement).toHaveCSS('font-size', '12px');
await expect(GaugeComponent).toContainText('0');
await expect(GaugeComponent).toContainText('100');

// Gauge settings should display name when showName is true
await page.goto(`${TEST_PAGE}&args=settings.showName:true`);
await expect(GaugeComponent).toContainText('Windmill');

// Gauge settings should not display unit when showUnit is false
await page.goto(`${TEST_PAGE}&args=settings.showUnit:false`);
await expect(GaugeComponent).not.toContainText('%');

// Gauge settings should disaplay the font size of 50 for value text
await page.goto(`${TEST_PAGE}&args=settings.fontSize:50`);
await expect(gaugeValueElement).toHaveCSS('font-size', '50px');

// Gauge settings should disaplay the unit size of 20 for unit text
await page.goto(`${TEST_PAGE}&args=settings.unitFontSize:20`);
await expect(gaugeUnitElement).toHaveCSS('font-size', '20px');

// Gauge settings should disaplay the labelFontSize size of 16 for label text
await page.goto(`${TEST_PAGE}&args=settings.labelFontSize:16`);
await expect(gaugeOutsideArcLabelelement).toHaveCSS('font-size', '16px');
const chart = page.getByTestId(TEST_DATA_ID);
// screenshot comparison
await expect(chart).toHaveScreenshot('gauge-default-settings.png');
});

// Gauge settings should change the yMin value to 15
await page.goto(`${TEST_PAGE}&args=settings.yMin:15`);
await expect(GaugeComponent).toContainText('15');
test('hidden guage settings', async ({ page }) => {
await page.goto(TEST_PAGE_HIDDEN_SETTINGS);
const chart = page.getByTestId(TEST_DATA_ID);
// screenshot comparison
await expect(chart).toHaveScreenshot('gauge-hidden-settings.png');
});

// Gauge settings should change the yMax value to 200
await page.goto(`${TEST_PAGE}&args=settings.yMax:200`);
await expect(GaugeComponent).toContainText('200');
test('guage with threshold', async ({ page }) => {
await page.goto(THRESHOLD_TEST_PAGE);
const chart = page.getByTestId(TEST_DATA_ID);
// screenshot comparison
await expect(chart).toHaveScreenshot('gauge-with-thresholds.png');
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 19 additions & 27 deletions packages/react-components/e2e/tests/kpi/kpi.spec.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
import { test, expect } from '@playwright/test';

const TEST_PAGE = '/?path=/story/widgets-kpi-kpi-base--main';
const TEST_IFRAME = '#storybook-preview-iframe';
const TEST_PAGE = '/iframe.html?id=widgets-kpi--default-kpi';
const TEST_PAGE_HIDDEN_SETTINGS =
'/iframe.html?id=widgets-kpi--kpi-hidden-settings';
const TEST_PAGE_THRESHOLD = '/iframe.html?id=widgets-kpi--kpi-thresholds';

test('kpi', async ({ page }) => {
await page.goto(TEST_PAGE);
await page.evaluate(() => document.fonts.ready);
const frame = page.frameLocator(TEST_IFRAME); // Need to go into frame otherwise the `locator` won't locate the selection.
const KPIComponent = frame.getByTestId('kpi-base-component');
const KPIError = frame.getByTestId('kpi-error-component');
const KPIComponent = page.getByTestId('kpi-base-component');

// KPI will always show value
await expect(KPIComponent).toContainText('100');

// unit will display
const unit = 'mph';
await page.goto(`${TEST_PAGE}&args=unit:${unit}`);
await expect(KPIComponent).toContainText(unit);
// screenshot comparison with everything showing
await expect(KPIComponent).toHaveScreenshot('kpi-default-settings.png');
});

// name will display
const name = 'windmill-name';
await page.goto(`${TEST_PAGE}&args=name:${name}`);
await expect(KPIComponent).toContainText(name);
test('kpi hidden settings', async ({ page }) => {
await page.goto(TEST_PAGE_HIDDEN_SETTINGS);
const KPIComponent = page.getByTestId('kpi-base-component');

// displays as loading
await page.goto(`${TEST_PAGE}&args=isLoading:true`);
await expect(KPIComponent).toContainText('-');
// screenshot comparison with everything hidden
await expect(KPIComponent).toHaveScreenshot('kpi-hidden-settings.png');
});

// error will display
const errorMsg = 'my-custom-error-msg';
await page.goto(`${TEST_PAGE}&args=error:${errorMsg}`);
await expect(KPIError).toContainText(errorMsg);
test('kpi with thresholds', async ({ page }) => {
await page.goto(TEST_PAGE_THRESHOLD);
const AllKPIs = page.getByTestId('mock-data-kpi-story');

// displays empty state
await page.goto(`${TEST_PAGE}&args=propertyPoint:!null`);
await expect(KPIComponent).toContainText('-');
// screenshot comparison
await expect(AllKPIs).toHaveScreenshot('kpi-with-thresholds.png');
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { test, expect } from '@playwright/test';

const COMPONENT_SELECTOR = '#story-container';
const TEST_PAGE_LINE_CHART =
'/iframe.html?id=widgets-webgl-charts--line-chart-example';
const TEST_PAGE_BAR_CHART =
'/iframe.html?id=widgets-webgl-charts--bar-chart-example';
const TEST_PAGE_SCATTER_CHART =
'/iframe.html?id=widgets-webgl-charts--scatter-chart-example';
const TEST_PAGE_STATUS_TIMELINE =
'/iframe.html?id=widgets-webgl-charts--status-timeline-example';

test('webgl-line-chart', async ({ page }) => {
await page.goto(TEST_PAGE_LINE_CHART);
const chart = page.locator(COMPONENT_SELECTOR);
await expect(chart).toContainText('2000');
await expect(chart).toHaveScreenshot('line-chart.png');
});

test('webgl-bar-chart', async ({ page }) => {
await page.goto(TEST_PAGE_BAR_CHART);
const chart = page.locator(COMPONENT_SELECTOR);
await expect(chart).toContainText('2000');
await expect(chart).toHaveScreenshot('bar-chart.png');
});

test('webgl-scatter-chart', async ({ page }) => {
await page.goto(TEST_PAGE_SCATTER_CHART);
const chart = page.locator(COMPONENT_SELECTOR);
await expect(chart).toContainText('2000');
await expect(chart).toHaveScreenshot('scatter-chart.png');
});

test('webgl-status-timeline', async ({ page }) => {
await page.goto(TEST_PAGE_STATUS_TIMELINE);
const chart = page.locator(COMPONENT_SELECTOR);
await expect(chart).toContainText('2000');
await expect(chart).toHaveScreenshot('status-timeline.png');
});
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ const BaseChart = ({
return (
<div
className={`base-chart-container ${options.legend?.position}-position`}
data-testid='base-chart-container'
>
<div className='base-chart-container-element'>
<Resizable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export const DEFAULT_GAUGE_PROGRESS_SETTINGS_WITH_THRESHOLDS = {

export const DEFAULT_GAUGE_STYLES = {
gaugeThickness: 30,
showName: false,
showName: true,
showUnit: true,
fontSize: 40,
labelFontSize: 12,
Expand Down

This file was deleted.

Loading

0 comments on commit 49504a6

Please sign in to comment.