mirror of
https://github.com/sasjs/adapter.git
synced 2026-04-19 04:03:13 +00:00
feat(sasjs-tests): update tests, use vite and minimal deps
This commit is contained in:
80
sasjs-tests/src/components/TestSuite.ts
Normal file
80
sasjs-tests/src/components/TestSuite.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import type { CompletedTestSuite } from '../core/TestRunner'
|
||||
import { TestCard } from './TestCard'
|
||||
|
||||
export class TestSuiteElement extends HTMLElement {
|
||||
private shadow: ShadowRoot
|
||||
private _suiteData: CompletedTestSuite | null = null
|
||||
private _suiteIndex: number = 0
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
this.shadow = this.attachShadow({ mode: 'open' })
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
this.render()
|
||||
}
|
||||
|
||||
set suiteData(data: CompletedTestSuite) {
|
||||
this._suiteData = data
|
||||
this.render()
|
||||
}
|
||||
|
||||
get suiteData(): CompletedTestSuite | null {
|
||||
return this._suiteData
|
||||
}
|
||||
|
||||
set suiteIndex(index: number) {
|
||||
this._suiteIndex = index
|
||||
}
|
||||
|
||||
get suiteIndex(): number {
|
||||
return this._suiteIndex
|
||||
}
|
||||
|
||||
render() {
|
||||
if (!this._suiteData) return
|
||||
|
||||
const { name, completedTests } = this._suiteData
|
||||
const passed = completedTests.filter((t) => t.status === 'passed').length
|
||||
const failed = completedTests.filter((t) => t.status === 'failed').length
|
||||
const running = completedTests.filter((t) => t.status === 'running').length
|
||||
|
||||
this.shadow.innerHTML = `
|
||||
<link rel="stylesheet" href="${new URL(
|
||||
'./TestSuite.css',
|
||||
import.meta.url
|
||||
)}">
|
||||
<div class="header">
|
||||
<h2>${name}</h2>
|
||||
<div class="stats">Passed: ${passed} | Failed: ${failed} | Running: ${running}</div>
|
||||
</div>
|
||||
<div class="tests" id="tests-container"></div>
|
||||
`
|
||||
|
||||
const testsContainer = this.shadow.getElementById('tests-container')
|
||||
if (testsContainer) {
|
||||
completedTests.forEach((completedTest, testIndex) => {
|
||||
const card = document.createElement('test-card') as TestCard
|
||||
card.testData = completedTest
|
||||
|
||||
card.addEventListener('rerun', () => {
|
||||
this.dispatchEvent(
|
||||
new CustomEvent('rerun-test', {
|
||||
bubbles: true,
|
||||
composed: true,
|
||||
detail: {
|
||||
suiteIndex: this._suiteIndex,
|
||||
testIndex
|
||||
}
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
testsContainer.appendChild(card)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define('test-suite', TestSuiteElement)
|
||||
Reference in New Issue
Block a user