سامانه صدور فاکتور و حسابداری

Add QA workflow with Playwright tests

davoodmehraban89 committed Oct 1, 2026 at 11:05 UTC 7c0656fe8d3525eef1ffb83113a5d9b1f832468a
1 file changed +209
.github/workflows/qa.yml new
+209
@@ -0,0 +1,209 @@
1 +name: Finora QA (manual)
2 +
3 +on:
4 + workflow_dispatch:
5 + inputs:
6 + base_url:
7 + description: "Site address"
8 + default: "https://factoreasy.ir"
9 + suite:
10 + description: "Which tests"
11 + type: choice
12 + default: public
13 + options:
14 + - public
15 + - live
16 + - all
17 +
18 +jobs:
19 + qa:
20 + runs-on: ubuntu-latest
21 + timeout-minutes: 30
22 + steps:
23 + - uses: actions/setup-node@v4
24 + with:
25 + node-version: 20
26 +
27 + - name: Write test project
28 + run: |
29 + mkdir -p qa/tests
30 + cd qa
31 +
32 + cat > package.json <<'EOF'
33 + {
34 + "name": "finora-qa",
35 + "private": true,
36 + "devDependencies": { "@playwright/test": "^1.48.0" }
37 + }
38 + EOF
39 +
40 + cat > playwright.config.js <<'EOF'
41 + const { defineConfig } = require('@playwright/test');
42 + module.exports = defineConfig({
43 + testDir: './tests',
44 + timeout: 120000,
45 + retries: 0,
46 + workers: 1,
47 + reporter: [['list'], ['json', { outputFile: 'results.json' }], ['html', { open: 'never' }]],
48 + use: {
49 + baseURL: process.env.BASE_URL || 'https://factoreasy.ir',
50 + locale: 'fa-IR',
51 + screenshot: 'on',
52 + trace: 'retain-on-failure',
53 + },
54 + });
55 + EOF
56 +
57 + cat > tests/public-smoke.spec.js <<'EOF'
58 + const { test, expect } = require('@playwright/test');
59 +
60 + test('F-066 / F-067 / F-150: index.html and response headers', async ({ request }) => {
61 + const res = await request.get('/');
62 + expect(res.status()).toBe(200);
63 + const html = await res.text();
64 + const headers = res.headers();
65 + expect.soft(
66 + headers['content-security-policy'] || headers['x-frame-options'],
67 + 'F-150: no anti-clickjacking HTTP header (CSP frame-ancestors or X-Frame-Options)'
68 + ).toBeTruthy();
69 + const cspMeta = (html.match(/Content-Security-Policy[^>]*content="([^"]*)"/i) || [])[1] || '';
70 + expect.soft(/script-src[^;]*'unsafe-inline'/.test(cspMeta), "F-066: script-src contains unsafe-inline").toBeFalsy();
71 + const cdnScripts = html.match(/<script[^>]*cdn\.jsdelivr[^>]*>/gi) || [];
72 + const noSri = cdnScripts.filter((s) => !/integrity=/i.test(s));
73 + expect.soft(noSri, 'F-067: CDN script tags without integrity attribute').toEqual([]);
74 + });
75 +
76 + test('F-068: diag.html must not be publicly reachable', async ({ request }) => {
77 + const res = await request.get('/diag.html');
78 + expect.soft(res.status(), 'F-068: /diag.html is publicly served').toBe(404);
79 + });
80 +
81 + test('page load: no console or page errors', async ({ page }) => {
82 + const errors = [];
83 + page.on('pageerror', (e) => errors.push('pageerror: ' + e.message));
84 + page.on('console', (m) => { if (m.type() === 'error') errors.push('console: ' + m.text()); });
85 + await page.goto('/');
86 + await page.waitForLoadState('networkidle');
87 + expect.soft(errors, 'errors on initial load').toEqual([]);
88 + });
89 +
90 + test('F-270: parseFormattedNumber with Persian/Arabic separators', async ({ page }) => {
91 + await page.goto('/');
92 + await page.waitForLoadState('networkidle');
93 + const available = await page.evaluate(() => typeof window.parseFormattedNumber === 'function');
94 + test.skip(!available, 'parseFormattedNumber is not a global function');
95 + const cases = [['۱۲٫۵', 12.5], ['۱٬۲۳۴٫۵۶', 1234.56], ['١٢٫٥', 12.5], ['12.5', 12.5]];
96 + for (const [input, expected] of cases) {
97 + const got = await page.evaluate((v) => window.parseFormattedNumber(v), input);
98 + expect.soft(got, 'F-270: parseFormattedNumber("' + input + '")').toBe(expected);
99 + }
100 + });
101 +
102 + test('errata: FinoraHealth.version should be 1.0', async ({ page }) => {
103 + await page.goto('/');
104 + await page.waitForLoadState('networkidle');
105 + const v = await page.evaluate(() => (window.FinoraHealth ? window.FinoraHealth.version : null));
106 + expect.soft(v).toBe('1.0');
107 + });
108 + EOF
109 +
110 + cat > tests/logged-in.spec.js <<'EOF'
111 + const fs = require('fs');
112 + const { test, expect } = require('@playwright/test');
113 + const EMAIL = process.env.TEST_EMAIL;
114 + const PASS = process.env.TEST_PASSWORD;
115 + const NAV_SELECTOR = process.env.NAV_SELECTOR || 'nav a, nav button, aside a, aside button, [data-view], [onclick*="show"]';
116 + const SKIP = /حذف|پاک|خروج|delete|remove|logout|sign out/i;
117 + test.skip(!EMAIL || !PASS, 'TEST_EMAIL / TEST_PASSWORD secrets are not set');
118 +
119 + async function login(page) {
120 + await page.goto('/');
121 + await page.locator('input[type="email"], input[name="email"]').first().fill(EMAIL);
122 + await page.locator('input[type="password"]').first().fill(PASS);
123 + await page.getByRole('button', { name: /ورود|login|sign in/i }).first().click();
124 + await page.waitForLoadState('networkidle');
125 + }
126 +
127 + test('read-only crawl of every visible menu item', async ({ page }) => {
128 + fs.mkdirSync('evidence', { recursive: true });
129 + const errors = [];
130 + page.on('pageerror', (e) => errors.push({ type: 'pageerror', msg: e.message }));
131 + page.on('console', (m) => { if (m.type() === 'error') errors.push({ type: 'console', msg: m.text() }); });
132 + page.on('response', (r) => {
133 + if (r.status() >= 400 && /supabase|factoreasy/.test(r.url())) errors.push({ type: 'http', msg: r.status() + ' ' + r.url() });
134 + });
135 + await login(page);
136 + const items = page.locator(NAV_SELECTOR);
137 + const count = await items.count();
138 + const results = [];
139 + for (let i = 0; i < count; i++) {
140 + const el = items.nth(i);
141 + if (!(await el.isVisible().catch(() => false))) continue;
142 + const label = ((await el.innerText().catch(() => '')) || '').trim().slice(0, 60);
143 + if (!label || SKIP.test(label)) continue;
144 + const before = errors.length;
145 + await el.click({ timeout: 5000 }).catch(() => {});
146 + await page.waitForTimeout(800);
147 + await page.screenshot({ path: 'evidence/menu-' + String(i).padStart(3, '0') + '.png' });
148 + results.push({ index: i, label, newErrors: errors.slice(before) });
149 + await page.keyboard.press('Escape').catch(() => {});
150 + }
151 + fs.writeFileSync('evidence/crawl.json', JSON.stringify(results, null, 2));
152 + expect.soft(results.filter((r) => r.newErrors.length), 'menu items that produced errors').toEqual([]);
153 + });
154 + EOF
155 +
156 + cat > summary.js <<'EOF'
157 + const r = require('./results.json');
158 + const strip = (s) => String(s).replace(/\u001b\[[0-9;]*m/g, '');
159 + const out = ['# Finora QA results', ''];
160 + (function walk(s) {
161 + (s.specs || []).forEach((sp) => sp.tests.forEach((t) => t.results.forEach((res) => {
162 + if (res.status === 'passed') out.push('- PASS: ' + sp.title);
163 + else if (res.status === 'skipped') out.push('- SKIPPED: ' + sp.title);
164 + else {
165 + out.push('- FAIL: ' + sp.title);
166 + (res.errors || []).forEach((e) => out.push(' - ' + strip(e.message).split('\n')[0]));
167 + }
168 + })));
169 + (s.suites || []).forEach(walk);
170 + })({ suites: r.suites });
171 + console.log(out.join('\n'));
172 + EOF
173 +
174 + - name: Install Playwright
175 + working-directory: qa
176 + run: |
177 + npm install
178 + npx playwright install --with-deps chromium
179 +
180 + - name: Run tests
181 + working-directory: qa
182 + continue-on-error: true
183 + env:
184 + BASE_URL: ${{ inputs.base_url }}
185 + TEST_EMAIL: ${{ secrets.TEST_EMAIL }}
186 + TEST_PASSWORD: ${{ secrets.TEST_PASSWORD }}
187 + run: |
188 + case "${{ inputs.suite }}" in
189 + public) npx playwright test public-smoke ;;
190 + live) npx playwright test logged-in ;;
191 + *) npx playwright test ;;
192 + esac
193 +
194 + - name: Summary
195 + if: always()
196 + working-directory: qa
197 + run: node summary.js >> "$GITHUB_STEP_SUMMARY" || echo "no results.json produced" >> "$GITHUB_STEP_SUMMARY"
198 +
199 + - name: Upload evidence
200 + if: always()
201 + uses: actions/upload-artifact@v4
202 + with:
203 + name: qa-results
204 + path: |
205 + qa/playwright-report
206 + qa/evidence
207 + qa/test-results
208 + qa/results.json
209 + if-no-files-found: ignore