Skip to content

Commit 4100a79

Browse files
author
Natalia Kazakova (DevExpress)
committed
add tests
1 parent 7740b5d commit 4100a79

File tree

4 files changed

+187
-0
lines changed

4 files changed

+187
-0
lines changed

.github/workflows/test.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Example Tests
2+
# This workflow runs tests for the DevExpress Angular Report Designer frontend.
3+
4+
on:
5+
push:
6+
branches:
7+
- '[0-9]+.[0-9]+.[0-9]+\+' # Matches xx.x.x+ pattern
8+
pull_request:
9+
branches:
10+
- '[0-9]+.[0-9]+.[0-9]+\+' # Matches xx.x.x+ pattern
11+
workflow_dispatch: # Allows manual triggering
12+
13+
env:
14+
NODE_VERSION: '18'
15+
DOTNET_VERSION: '8.0.x'
16+
17+
jobs:
18+
test:
19+
runs-on: windows-latest
20+
timeout-minutes: 25
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
- name: Setup .NET
27+
uses: actions/setup-dotnet@v4
28+
with:
29+
dotnet-version: ${{ env.DOTNET_VERSION }}
30+
31+
- name: Setup Node.js
32+
uses: actions/setup-node@v4
33+
with:
34+
node-version: ${{ env.NODE_VERSION }}
35+
cache: 'npm'
36+
cache-dependency-path: |
37+
package-lock.json
38+
39+
- name: Setup Chrome
40+
uses: browser-actions/setup-chrome@v1
41+
with:
42+
chrome-version: stable
43+
44+
- name: Run Tests
45+
run: |
46+
$exitCode = pwsh -ExecutionPolicy Bypass -File test/main-test.ps1
47+
Write-Host "Test script exit code: $exitCode"
48+
if ($exitCode -ne 0) {
49+
Write-Error "❌ Tests failed with exit code: $exitCode"
50+
exit $exitCode
51+
}
52+
Write-Host "✅ Tests passed successfully"
53+
timeout-minutes: 5

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "reporting-angular-test",
3+
"version": "1.0.0",
4+
"description": "smoke tests",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"@devexpress/reporting-testcafe-helpers": "^24.2.3",
14+
"testcafe": "^3.5.0"
15+
}
16+
}

test/main-test.ps1

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Requires -Version 7
2+
3+
Set-StrictMode -Version latest
4+
$ErrorActionPreference = 'Stop'
5+
6+
function CheckLastExitCode() {
7+
if ($LastExitCode -ne 0) {
8+
Write-Error -ErrorAction Stop "Last exit code: $LastExitCode"
9+
}
10+
}
11+
12+
function InstallNpmPackages() {
13+
if(-Not(Test-Path .\node_modules\*)) {
14+
npm ci | Out-Host
15+
CheckLastExitCode
16+
}
17+
}
18+
19+
function LaunchBackend([Parameter(Mandatory)][string]$path) {
20+
Push-Location $path
21+
try {
22+
Write-Host "Starting backend server..."
23+
$process = Start-Process dotnet -ArgumentList ('run') -PassThru
24+
Start-Sleep -Seconds 15 # Give backend time to start (increased from 5 to match frontend timing)
25+
return $process
26+
} finally {
27+
Pop-Location
28+
}
29+
}
30+
31+
function LaunchFrontend([Parameter(Mandatory)][string]$path) {
32+
Push-Location $path
33+
try {
34+
InstallNpmPackages
35+
Write-Host "Starting frontend server..."
36+
$process = Start-Process cmd -ArgumentList ('/c', 'npm', 'start') -PassThru
37+
Write-Host "Waiting for frontend to be ready..."
38+
Start-Sleep -Seconds 5 # Give frontend time to build and start
39+
return $process
40+
} finally {
41+
Pop-Location
42+
}
43+
}
44+
45+
function RunTestCafeTests() {
46+
$browserList = if ($env:BROWSER) { $env:BROWSER } else { 'chrome' }
47+
$fileOrGlob = './test/testcafe-test.ts'
48+
49+
$arguments = @(
50+
'/c'
51+
'npx.cmd'
52+
'testcafe'
53+
$browserList
54+
$fileOrGlob
55+
'--base-url http://localhost:4200'
56+
'--selector-timeout 1000'
57+
'--assertion-timeout 1000'
58+
)
59+
60+
$process = Start-Process 'cmd' -ArgumentList $arguments -NoNewWindow -Wait -ErrorAction Stop -PassThru
61+
$exitCode = $process.ExitCode
62+
63+
Write-Host "TestCafe exit code: $exitCode"
64+
return $exitCode
65+
}
66+
67+
function Main() {
68+
InstallNpmPackages
69+
Write-Host "Launching backend..."
70+
$backendProcess = LaunchBackend ./ServerApp
71+
try {
72+
Write-Host "Launching frontend..."
73+
$frontendProcess = LaunchFrontend ./angular-report-designer
74+
try {
75+
Write-Host "Running TestCafe tests..."
76+
return RunTestCafeTests
77+
} finally {
78+
Write-Host "Stopping frontend process..."
79+
taskkill.exe /F /T /PID $frontendProcess.Id | Out-Host
80+
Write-Host "Frontend process is stopped"
81+
}
82+
} finally {
83+
Stop-Process $backendProcess | Out-Host
84+
Write-Host "Backend process is stopped"
85+
}
86+
}
87+
88+
try {
89+
Exit [int](Main)
90+
} catch {
91+
Write-Host -ForegroundColor Red $_.Exception
92+
$_.ScriptStackTrace -split [System.Environment]::NewLine | ForEach-Object { Write-Host -ForegroundColor Red " $_" }
93+
Exit -1
94+
}

test/testcafe-test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Selector } from 'testcafe';
2+
import { assertUntilCondition, designerMenuButton, getMenuItemByText, getToolbarButtonByText } from '@devexpress/reporting-testcafe-helpers/units';
3+
import { checkPreviewPage } from '@devexpress/reporting-testcafe-helpers/preview';
4+
5+
fixture('Maximize window')
6+
.beforeEach(async t => {
7+
await t.maximizeWindow();
8+
});
9+
10+
11+
test('Check whether Report Designer is rendered', async t => {
12+
const reportDesigner = Selector('app-root div dx-report-designer');
13+
await t.expect(reportDesigner.exists).ok('DevExpress Report Designer should exist');
14+
});
15+
test('Check simple UI actions in Report Designer', async t => {
16+
await assertUntilCondition(t, () => getToolbarButtonByText('preview').exists, 'Wait for designer loading');
17+
await t
18+
.dispatchEvent(getToolbarButtonByText('preview'), 'click');
19+
await checkPreviewPage(t, 15);
20+
await t
21+
.dispatchEvent(getToolbarButtonByText('design'), 'click')
22+
.click(designerMenuButton)
23+
.click(getMenuItemByText('Exit'));
24+
});

0 commit comments

Comments
 (0)