diff --git a/tools/visual-regression-testing/diff-app/src/components/overview/overview.ts b/tools/visual-regression-testing/diff-app/src/components/overview/overview.ts index 8e1a9032e7..cf835c5219 100644 --- a/tools/visual-regression-testing/diff-app/src/components/overview/overview.ts +++ b/tools/visual-regression-testing/diff-app/src/components/overview/overview.ts @@ -1,7 +1,7 @@ import { LitElement, html, type TemplateResult, type CSSResultGroup } from 'lit'; import { customElement } from 'lit/decorators.js'; -import { screenshotService } from '../../screenshots.js'; +import { screenshots } from '../../screenshots.js'; import style from './overview.scss?lit&inline'; @@ -27,20 +27,18 @@ export class Overview extends LitElement { Lyne visual regression comparison
- ${screenshotService.screenshots.stats} + ${screenshots.stats} Start comparing - ${screenshotService.screenshots.components.map( + ${screenshots.components.map( (screenshotComponent) => html` - + ${screenshotComponent.name} (${screenshotComponent.stats}) diff --git a/tools/visual-regression-testing/diff-app/src/components/test-case/test-case.ts b/tools/visual-regression-testing/diff-app/src/components/test-case/test-case.ts index 79ae973a20..000ecb9984 100644 --- a/tools/visual-regression-testing/diff-app/src/components/test-case/test-case.ts +++ b/tools/visual-regression-testing/diff-app/src/components/test-case/test-case.ts @@ -1,13 +1,13 @@ import { - LitElement, - html, - type TemplateResult, type CSSResultGroup, + html, + LitElement, type PropertyValues, + type TemplateResult, } from 'lit'; import { customElement, property, state } from 'lit/decorators.js'; -import { screenshotService, type ScreenshotTestCase } from '../../screenshots.js'; +import { screenshots, type ScreenshotTestCase } from '../../screenshots.js'; import '../../../../../../src/components/button/secondary-button-link.js'; import '../../../../../../src/components/chip.js'; @@ -38,21 +38,40 @@ export class TestCase extends LitElement { @property() public params?: { componentName: string; testCaseName: string }; @state() private _testCase?: ScreenshotTestCase; + @state() private _testCaseIndex: number = -1; @state() private _filter: Filter = {}; protected override willUpdate(changedProperties: PropertyValues): void { super.willUpdate(changedProperties); if (changedProperties.has('params')) { + // Reset this._filter = {}; this.shadowRoot!.querySelector('app-test-case-filter')?.reset(); - this._testCase = screenshotService.setCurrentTestCase( + + // Get test case + this._testCaseIndex = screenshots.indexOfTestCase( this.params!.componentName!, this.params!.testCaseName!, ); + if (this._testCaseIndex >= 0) { + this._testCase = screenshots.getByTestCaseIndex(this._testCaseIndex); + } } } + private _progressFraction(): number { + return (this._testCaseIndex + 1) / screenshots.testCaseCount; + } + + private _next(): ScreenshotTestCase | undefined { + return screenshots.getByTestCaseIndex(this._testCaseIndex + 1); + } + + private _previous(): ScreenshotTestCase | undefined { + return screenshots.getByTestCaseIndex(this._testCaseIndex - 1); + } + private _viewportFilterChanged(event: CustomEvent): void { this._filter = { ...this._filter, @@ -70,10 +89,7 @@ export class TestCase extends LitElement { public override render(): TemplateResult { return html` -
+
${this.params?.componentName} @@ -84,16 +100,16 @@ export class TestCase extends LitElement {
Overview
diff --git a/tools/visual-regression-testing/diff-app/src/screenshots.ts b/tools/visual-regression-testing/diff-app/src/screenshots.ts index 71c49eb205..f14f1415b5 100644 --- a/tools/visual-regression-testing/diff-app/src/screenshots.ts +++ b/tools/visual-regression-testing/diff-app/src/screenshots.ts @@ -174,45 +174,4 @@ export class Screenshots { } } -export class ScreenshotService { - public readonly screenshots; - private _currentIndex: number = -1; - - public get progressFraction(): number { - return (this._currentIndex + 1) / this.screenshots.testCaseCount; - } - - public get current(): ScreenshotTestCase | undefined { - return this._current; - } - private _current?: ScreenshotTestCase; - - public constructor(screenshots: Screenshots) { - this.screenshots = screenshots; - this._currentIndex = 0; - this._current = screenshots.getByTestCaseIndex(this._currentIndex); - } - - public get next(): ScreenshotTestCase | undefined { - return this.screenshots.getByTestCaseIndex(this._currentIndex + 1); - } - - public get previous(): ScreenshotTestCase | undefined { - return this.screenshots.getByTestCaseIndex(this._currentIndex - 1); - } - - public setCurrentTestCase( - componentName: string, - testCaseName: string, - ): ScreenshotTestCase | undefined { - const testCaseIndex = this.screenshots.indexOfTestCase(componentName, testCaseName); - - this._currentIndex = testCaseIndex; - if (testCaseIndex >= 0) { - this._current = this.screenshots.getByTestCaseIndex(testCaseIndex); - return this._current; - } - } -} - -export const screenshotService = new ScreenshotService(new Screenshots(screenshotsRaw)); +export const screenshots = new Screenshots(screenshotsRaw);