-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FI-1015 feat: add locators to HTML report for testing locator utils
- Loading branch information
Showing
14 changed files
with
182 additions
and
37 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export type {RootLocator as ReportRootLocator} from './rootLocator'; | ||
/** @internal */ | ||
export {renderReportToHtml} from './renderReportToHtml'; |
This file contains 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,19 @@ | ||
import {createSafeHtmlWithoutSanitize} from '../client'; | ||
|
||
import type {Attributes} from 'create-locator'; | ||
|
||
import type {SafeHtml} from '../../../types/internal'; | ||
|
||
/** | ||
* Renders attributes object to safe HTML string. | ||
* @internal | ||
*/ | ||
export const renderAttributes = (attributes: object): SafeHtml => { | ||
const parts: string[] = []; | ||
|
||
for (const key of Object.keys(attributes)) { | ||
parts.push(`${key}="${(attributes as Attributes)[key]}"`); | ||
} | ||
|
||
return createSafeHtmlWithoutSanitize`${parts.join(' ')}`; | ||
}; |
This file contains 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 |
---|---|---|
@@ -1,18 +1,31 @@ | ||
import {createLocator, type Locator, type Mark} from 'create-locator'; | ||
|
||
import {sanitizeHtml} from '../client'; | ||
|
||
import {renderAttributes} from './renderAttributes'; | ||
import {renderLogo} from './renderLogo'; | ||
import {renderRetriesButtons} from './renderRetriesButtons'; | ||
import {renderRetriesButtons, type RetriesButtonsLocator} from './renderRetriesButtons'; | ||
|
||
import type {RetryProps, SafeHtml} from '../../../types/internal'; | ||
|
||
type Props = Readonly<{retries: readonly RetryProps[]}> & Mark<NavigationLocator>; | ||
|
||
export type NavigationLocator = Locator<{ | ||
retries: RetriesButtonsLocator; | ||
}>; | ||
|
||
/** | ||
* Renders tag <nav>. | ||
* Renders tag `<nav>`. | ||
* @internal | ||
*/ | ||
export const renderNavigation = (retries: readonly RetryProps[]): SafeHtml => sanitizeHtml` | ||
<nav class="nav"> | ||
export const renderNavigation = ({retries, ...rest}: Props): SafeHtml => { | ||
const locator = createLocator(rest); | ||
|
||
return sanitizeHtml` | ||
<nav class="nav" ${renderAttributes(locator())}> | ||
<header class="header"> | ||
${renderLogo()} | ||
</header> | ||
${renderRetriesButtons(retries)} | ||
${renderRetriesButtons({retries, ...locator.retries()})} | ||
</nav>`; | ||
}; |
This file contains 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 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 |
---|---|---|
@@ -1,15 +1,22 @@ | ||
import {createLocator, type Locator, type Mark} from 'create-locator'; | ||
|
||
import {createSafeHtmlWithoutSanitize} from '../client'; | ||
|
||
import {renderRetry} from './renderRetry'; | ||
import {renderRetry, type RetryLocator} from './renderRetry'; | ||
|
||
import type {RetryProps, SafeHtml} from '../../../types/internal'; | ||
|
||
type Props = Readonly<{retries: readonly RetryProps[]}> & Mark<RetriesLocator>; | ||
|
||
export type RetriesLocator = Locator<{retry: RetryLocator}>; | ||
|
||
/** | ||
* Renders list of retries (with test runs). | ||
* @internal | ||
*/ | ||
export const renderRetries = (retries: readonly RetryProps[]): SafeHtml => { | ||
const retriesHtml = retries.map(renderRetry); | ||
export const renderRetries = ({retries, ...rest}: Props): SafeHtml => { | ||
const locator = createLocator(rest); | ||
const retriesHtml = retries.map((retry) => renderRetry({retry, ...locator.retry()})); | ||
|
||
return createSafeHtmlWithoutSanitize`${retriesHtml.join('')}`; | ||
}; |
This file contains 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 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 |
---|---|---|
@@ -1,20 +1,35 @@ | ||
import {createLocator, type Locator, type Mark} from 'create-locator'; | ||
|
||
import {createSafeHtmlWithoutSanitize} from '../client'; | ||
|
||
import {renderRetryHeader} from './renderRetryHeader'; | ||
import {renderTestRunButton} from './renderTestRunButton'; | ||
import {renderAttributes} from './renderAttributes'; | ||
import {renderRetryHeader, type RetryHeaderLocator} from './renderRetryHeader'; | ||
import {renderTestRunButton, type TestRunButtonLocator} from './renderTestRunButton'; | ||
|
||
import type {RetryProps, SafeHtml} from '../../../types/internal'; | ||
|
||
type Props = Readonly<{retry: RetryProps}> & Mark<RetryLocator>; | ||
|
||
export type RetryLocator = Locator< | ||
{button: TestRunButtonLocator; header: RetryHeaderLocator}, | ||
{index: string} | ||
>; | ||
|
||
/** | ||
* Renders test runs list for one retry. | ||
* @internal | ||
*/ | ||
export const renderRetry = (retryProps: RetryProps): SafeHtml => { | ||
const buttons = retryProps.testRunButtons.map(renderTestRunButton); | ||
export const renderRetry = ({retry, ...rest}: Props): SafeHtml => { | ||
const locator = createLocator(rest); | ||
const buttons = retry.testRunButtons.map((props, index) => | ||
renderTestRunButton({...props, index, ...locator.button()}), | ||
); | ||
|
||
return createSafeHtmlWithoutSanitize` | ||
<article class="retry" id="retry${retryProps.retryIndex}" ${retryProps.hidden ? 'hidden' : ''}> | ||
${renderRetryHeader(retryProps)} | ||
<article class="retry" id="retry${retry.retryIndex}" ${ | ||
retry.hidden ? 'hidden' : '' | ||
} {${renderAttributes(locator({index: String(retry.retryIndex)}))}}> | ||
${renderRetryHeader({...retry, ...locator.header()})} | ||
${buttons.join('')} | ||
</article>`; | ||
}; |
This file contains 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 |
---|---|---|
@@ -1,19 +1,33 @@ | ||
import {createLocator, type Locator, type Mark} from 'create-locator'; | ||
|
||
import {sanitizeHtml} from '../client'; | ||
|
||
import {renderAttributes} from './renderAttributes'; | ||
|
||
import type {RetryButtonProps, SafeHtml} from '../../../types/internal'; | ||
|
||
type Props = RetryButtonProps & Mark<RetryButtonLocator>; | ||
|
||
export type RetryButtonLocator = Locator< | ||
void, | ||
{disabled: `${boolean}`; retry: string; selected: `${boolean}`} | ||
>; | ||
|
||
/** | ||
* Renders tag <button> with single retry button. | ||
* @internal | ||
*/ | ||
export const renderRetryButton = ({ | ||
disabled, | ||
retry, | ||
selected, | ||
}: RetryButtonProps): SafeHtml => sanitizeHtml`<button | ||
export const renderRetryButton = ({disabled, retry, selected, ...rest}: Props): SafeHtml => { | ||
const locator = createLocator(rest); | ||
|
||
return sanitizeHtml`<button | ||
aria-controls="retry${retry}" | ||
aria-selected="${String(selected)}" | ||
class="nav-tabs__button" | ||
id="retry${retry}-nav" | ||
role="tab" | ||
${renderAttributes( | ||
locator({disabled: `${disabled}`, retry: String(retry), selected: `${selected}`}), | ||
)} | ||
${disabled ? 'disabled' : ''}>Retry ${retry}</button>`; | ||
}; |
This file contains 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 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 |
---|---|---|
@@ -1,25 +1,51 @@ | ||
import {createLocator, type Locator, type Mark} from 'create-locator'; | ||
|
||
import {renderDuration, sanitizeHtml} from '../client'; | ||
|
||
import type {SafeHtml, TestRunButtonProps} from '../../../types/internal'; | ||
import {renderAttributes} from './renderAttributes'; | ||
|
||
import type {TestRunStatus} from '../../../constants/internal'; | ||
import type {SafeHtml, TestRunButtonProps, Void} from '../../../types/internal'; | ||
|
||
type Props = TestRunButtonProps & Readonly<{index: number}> & Mark<TestRunButtonLocator>; | ||
|
||
export type TestRunButtonLocator = Locator< | ||
{name: Void; order: Void; parameters: Void; time: Void}, | ||
{status: TestRunStatus} | ||
>; | ||
|
||
/** | ||
* Renders single test run button (in test runs list). | ||
* @internal | ||
*/ | ||
export const renderTestRunButton = ( | ||
{endTimeInMs, startTimeInMs, status, mainParams, name, runHash}: TestRunButtonProps, | ||
index: number, | ||
): SafeHtml => { | ||
export const renderTestRunButton = ({ | ||
endTimeInMs, | ||
index, | ||
mainParams, | ||
name, | ||
runHash, | ||
startTimeInMs, | ||
status, | ||
...rest | ||
}: Props): SafeHtml => { | ||
const locator = createLocator(rest); | ||
const durationInMs = endTimeInMs - startTimeInMs; | ||
|
||
return sanitizeHtml`<button | ||
aria-selected="false" | ||
class="test-button test-button_status_${status}" | ||
data-runhash="${runHash}" | ||
role="tab" | ||
${renderAttributes(locator({status}))} | ||
> | ||
<span class="test-button__order">#${index + 1}</span> | ||
<span class="test-button__name">${name}<span class="test-button__parameters">${mainParams}</span></span> | ||
<span class="test-button__time">${renderDuration(durationInMs)}</span> | ||
<span class="test-button__order" ${renderAttributes(locator.order())}>#${index + 1}</span> | ||
<span class="test-button__name" ${renderAttributes( | ||
locator.name(), | ||
)}>${name}<span class="test-button__parameters" ${renderAttributes( | ||
locator.parameters(), | ||
)}>${mainParams}</span></span> | ||
<span class="test-button__time" ${renderAttributes(locator.time())}>${renderDuration( | ||
durationInMs, | ||
)}</span> | ||
</button>`; | ||
}; |
This file contains 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,19 @@ | ||
import {createLocator, type Locator} from 'create-locator'; | ||
|
||
import {e2edEnvironment} from '../../../constants/internal'; | ||
|
||
import type {Void} from '../../../types/internal'; | ||
|
||
import type {NavigationLocator} from './renderNavigation'; | ||
import type {RetriesLocator} from './renderRetries'; | ||
|
||
const isProduction = e2edEnvironment.E2ED_ORIGIN !== 'https://google.com'; | ||
|
||
export const rootLocator = createLocator<RootLocator>('app', {isProduction}); | ||
|
||
export type RootLocator = Locator<{ | ||
column1: Void; | ||
column2: Void; | ||
navigation: NavigationLocator; | ||
retries: RetriesLocator; | ||
}>; |