-
Notifications
You must be signed in to change notification settings - Fork 4
chore(toggle): added screenshot tests (#DS-4293) #1088
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fadfb67
feat(toggle): added KbqHovered directive to host and screenshot tests…
artembelik 32913ca
test: auto-updated e2e screenshots
artembelik 259a1fb
refactor: api
artembelik 39f00a8
refactor: review
artembelik 47862df
refactor: review, updated screenshot, added new tests
artembelik 82f1ebd
test: auto-updated e2e screenshots
artembelik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file added
BIN
+19.5 KB
...components/__screenshots__/KbqToggleModule-DevToggleStateAndStyle-default-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+19.9 KB
...__screenshots__/KbqToggleModule-DevToggleStateAndStyle-default-dark-theme-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+14.4 KB
...ents/__screenshots__/KbqToggleModule-DevToggleStateAndStyle-indeterminate-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12 KB
...omponents/__screenshots__/KbqToggleModule-DevToggleWithTextAndCaption-big-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.4 KB
...nents/__screenshots__/KbqToggleModule-DevToggleWithTextAndCaption-default-1.png
|
artembelik marked this conversation as resolved.
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.8 KB
...eenshots__/KbqToggleModule-DevToggleWithTextAndCaption-default-dark-theme-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 72 additions & 0 deletions
72
packages/components-dev/e2e/components/toggle.playwright-spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { expect, Locator, Page, test } from '@playwright/test'; | ||
| import { devEnableDarkTheme, devGoToRootPage } from '../utils'; | ||
|
|
||
| test.describe('KbqToggleModule', () => { | ||
| const getScreenshotTarget = (locator: Locator): Locator => locator.getByTestId('e2eScreenshotTarget'); | ||
| const getIndeterminateToggle = (locator: Locator): Locator => locator.getByTestId('e2eIndeterminateToggle'); | ||
| const getBigToggle = (locator: Locator): Locator => locator.getByTestId('e2eBigToggle'); | ||
|
|
||
| test.describe('DevToggleStateAndStyle', () => { | ||
| const getComponent = (page: Page): Locator => page.getByTestId('e2eToggleStateAndStyle'); | ||
| const getFirstToggle = (locator: Locator): Locator => locator.locator('kbq-toggle').first(); | ||
|
|
||
| test('default', async ({ page }) => { | ||
| await devGoToRootPage(page); | ||
| await expect(getScreenshotTarget(getComponent(page))).toHaveScreenshot(); | ||
| }); | ||
|
|
||
| test('default (dark theme)', async ({ page }) => { | ||
| await devGoToRootPage(page); | ||
| await devEnableDarkTheme(page); | ||
| await expect(getScreenshotTarget(getComponent(page))).toHaveScreenshot(); | ||
| }); | ||
|
|
||
| test('should have correct size', async ({ page }) => { | ||
| await devGoToRootPage(page); | ||
|
|
||
| const component = getComponent(page); | ||
| const { width, height } = (await getFirstToggle(component).boundingBox()) ?? {}; | ||
|
|
||
| expect(width).toBe(28); | ||
| expect(height).toBe(16); | ||
|
|
||
| await getBigToggle(component).click(); | ||
|
|
||
| expect(width).toBe(28); | ||
| expect(height).toBe(16); | ||
| }); | ||
|
|
||
| test('indeterminate', async ({ page }) => { | ||
| await devGoToRootPage(page); | ||
|
|
||
| const component = getComponent(page); | ||
|
|
||
| await getIndeterminateToggle(component).click(); | ||
| await expect(getScreenshotTarget(component)).toHaveScreenshot(); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('DevToggleWithTextAndCaption', () => { | ||
| const getComponent = (page: Page): Locator => page.getByTestId('e2eToggleWithTextAndCaption'); | ||
|
|
||
| test('default', async ({ page }) => { | ||
| await devGoToRootPage(page); | ||
| await expect(getScreenshotTarget(getComponent(page))).toHaveScreenshot(); | ||
| }); | ||
|
|
||
| test('default (dark theme)', async ({ page }) => { | ||
| await devGoToRootPage(page); | ||
| await devEnableDarkTheme(page); | ||
| await expect(getScreenshotTarget(getComponent(page))).toHaveScreenshot(); | ||
| }); | ||
|
|
||
| test('big', async ({ page }) => { | ||
| await devGoToRootPage(page); | ||
|
|
||
| const component = getComponent(page); | ||
|
|
||
| await getBigToggle(component).click(); | ||
| await expect(getScreenshotTarget(component)).toHaveScreenshot(); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import { ChangeDetectionStrategy, Component, model } from '@angular/core'; | ||
| import { FormsModule } from '@angular/forms'; | ||
| import { KbqComponentColors } from '@koobiq/components/core'; | ||
| import { KbqFormFieldModule } from '@koobiq/components/form-field'; | ||
| import { KbqToggleModule } from '@koobiq/components/toggle'; | ||
|
|
||
| @Component({ | ||
| standalone: true, | ||
| imports: [KbqToggleModule, FormsModule], | ||
| selector: 'dev-toggle-state-and-style', | ||
| host: { | ||
| 'data-testid': 'e2eToggleStateAndStyle' | ||
| }, | ||
| template: ` | ||
| <input type="checkbox" data-testid="e2eIndeterminateToggle" [(ngModel)]="indeterminate" /> | ||
| <input type="checkbox" data-testid="e2eBigToggle" [(ngModel)]="big" /> | ||
|
|
||
| <table data-testid="e2eScreenshotTarget"> | ||
| <tbody> | ||
| @for (color of colors; track color) { | ||
| <tr> | ||
| @for (state of states; track state) { | ||
| <td> | ||
| <div> | ||
| @for (type of types; track type) { | ||
| <kbq-toggle | ||
| [color]="color" | ||
| [disabled]="state === 'disabled'" | ||
| [indeterminate]="indeterminate()" | ||
| [class.kbq-hovered]="state === 'hovered'" | ||
| [class.cdk-keyboard-focused]="state === 'focused'" | ||
| [checked]="type === 'checked'" | ||
| [loading]="state === 'loading'" | ||
| [big]="big()" | ||
| /> | ||
| } | ||
| </div> | ||
| </td> | ||
| } | ||
| </tr> | ||
| } | ||
| </tbody> | ||
| </table> | ||
| `, | ||
| styles: ` | ||
| td { | ||
| padding: var(--kbq-size-xs); | ||
| width: 1px; | ||
| } | ||
|
|
||
| div { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: var(--kbq-size-xxs); | ||
| } | ||
| `, | ||
| changeDetection: ChangeDetectionStrategy.OnPush | ||
| }) | ||
| export class DevToggleStateAndStyle { | ||
| readonly states = ['normal', 'hovered', 'focused', 'disabled', 'loading'] as const; | ||
| readonly colors = [KbqComponentColors.Theme, KbqComponentColors.Error]; | ||
| readonly types = ['default', 'checked'] as const; | ||
|
|
||
| readonly indeterminate = model(false); | ||
| readonly big = model(false); | ||
| } | ||
|
|
||
| @Component({ | ||
| standalone: true, | ||
| imports: [KbqToggleModule, KbqFormFieldModule, FormsModule], | ||
| selector: 'dev-toggle-with-text-and-caption', | ||
| host: { | ||
| 'data-testid': 'e2eToggleWithTextAndCaption' | ||
| }, | ||
| template: ` | ||
| <input type="checkbox" data-testid="e2eBigToggle" [(ngModel)]="big" /> | ||
|
|
||
| <table data-testid="e2eScreenshotTarget"> | ||
| <tbody> | ||
| @for (state of states; track state) { | ||
| <tr> | ||
| @for (position of positions; track position) { | ||
| <td> | ||
| <div> | ||
| <kbq-toggle | ||
| [disabled]="state === 'disabled'" | ||
| [labelPosition]="position" | ||
| [big]="big()" | ||
| > | ||
| Text | ||
| <kbq-hint>Caption</kbq-hint> | ||
| </kbq-toggle> | ||
| </div> | ||
| </td> | ||
| } | ||
| </tr> | ||
| } | ||
| </tbody> | ||
| </table> | ||
| `, | ||
| styles: ` | ||
| td { | ||
| padding: var(--kbq-size-xs); | ||
| width: 1px; | ||
| } | ||
|
|
||
| div { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: var(--kbq-size-m); | ||
| } | ||
| `, | ||
| changeDetection: ChangeDetectionStrategy.OnPush | ||
| }) | ||
| export class DevToggleWithTextAndCaption { | ||
| readonly states = ['normal', 'disabled'] as const; | ||
| readonly positions = ['left', 'right'] as const; | ||
|
|
||
| readonly big = model(false); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.