سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 13:00 UTC
test(phase0): add dark/light contrast and shell readability browser gates
davoodmehraban89 committed
Oct 12, 2026 at 10:55 UTC
38a852c7bc5694e2ec5c3395b035ccda77363d75
1 file changed
+74
scripts/phase0-dark-theme-contrast.spec.js
new
+74
@@ -0,0 +1,74 @@
1
+const {test,expect}=require('@playwright/test');
2
+const BASE=process.env.FINORA_TEST_BASE_URL||'http://127.0.0.1:4173/index.html';
3
+
4
+async function setup(page){
5
+ await page.goto(BASE,{waitUntil:'domcontentloaded'});
6
+ await page.waitForFunction(()=>typeof finoraApplyTheme==='function'&&!!document.getElementById('finora-theme-r2-css'));
7
+ await page.evaluate(()=>{
8
+ const fixture=document.createElement('section');
9
+ fixture.id='f0-dark-contract-fixture';
10
+ fixture.innerHTML=`
11
+ <section class="accordion-item" id="f0-theme-accordion">
12
+ <div class="accordion-header">تنظیمات حسابداری</div>
13
+ <div class="accordion-body">جزئیات حسابداری</div>
14
+ </section>
15
+ <button type="button" class="btn btn-secondary" id="f0-theme-secondary">انصراف</button>
16
+ <label for="f0-theme-field" id="f0-theme-label">شرح سند</label>
17
+ <input id="f0-theme-field" class="form-control" placeholder="توضیحات" value="اطلاعات آزمایشی">
18
+ <aside class="module-panel" id="f0-theme-shell">
19
+ <div class="module-panel-head"><h3>ماژولها</h3></div>
20
+ <button type="button" class="module-link" id="f0-theme-nav">حسابداری</button>
21
+ </aside>`;
22
+ document.body.appendChild(fixture);
23
+ document.body.classList.add('finora-theme-dark');
24
+ });
25
+}
26
+
27
+async function sample(page){
28
+ return await page.evaluate(()=>{
29
+ const color=s=>String(s).match(/[\d.]+/g)?.slice(0,3).map(Number)||[];
30
+ const lum=s=>{
31
+ const cs=color(s);if(cs.length!==3)return null;
32
+ return cs.map(v=>{const x=v/255;return x<=0.04045?x/12.92:((x+0.055)/1.055)**2.4})
33
+ .reduce((acc,v,i)=>acc+v*[.2126,.7152,.0722][i],0);
34
+ };
35
+ const get=id=>{
36
+ const c=getComputedStyle(document.getElementById(id));
37
+ const a=lum(c.color),b=lum(c.backgroundColor);
38
+ return {fg:c.color,bg:c.backgroundColor,contrast:a===null||b===null?0:(Math.max(a,b)+0.05)/(Math.min(a,b)+0.05),backgroundLuminance:b};
39
+ };
40
+ return {
41
+ accordion:get('f0-theme-accordion'),
42
+ button:get('f0-theme-secondary'),
43
+ input:get('f0-theme-field'),
44
+ label:get('f0-theme-label'),
45
+ shell:get('f0-theme-shell'),
46
+ nav:get('f0-theme-nav'),
47
+ rootDark:document.body.classList.contains('finora-theme-dark')
48
+ };
49
+ });
50
+}
51
+
52
+test('F0-06 dark mode maintains readable accounting panels, controls and shell',async({page})=>{
53
+ await setup(page);
54
+ const s=await sample(page);
55
+ expect(s.rootDark).toBe(true);
56
+ for(const part of ['accordion','button','input','shell'])
57
+ expect(s[part].contrast,part+' '+JSON.stringify(s[part])).toBeGreaterThanOrEqual(4.5);
58
+ for(const part of ['accordion','button','input','shell'])
59
+ expect(s[part].backgroundLuminance,part+' dark surface').toBeLessThan(0.18);
60
+ // The shell's transparent navigation controls inherit their own dark parent.
61
+ expect(s.nav.fg).not.toBe('rgb(51, 65, 85)');
62
+});
63
+
64
+test('F0-06 light mode remains legible after switching out of dark mode',async({page})=>{
65
+ await setup(page);
66
+ await page.evaluate(()=>document.body.classList.remove('finora-theme-dark'));
67
+ const s=await sample(page);
68
+ expect(s.rootDark).toBe(false);
69
+ expect(s.accordion.contrast).toBeGreaterThanOrEqual(4.5);
70
+ expect(s.button.contrast).toBeGreaterThanOrEqual(4.5);
71
+ expect(s.input.contrast).toBeGreaterThanOrEqual(4.5);
72
+ expect(s.accordion.backgroundLuminance).toBeGreaterThan(0.5);
73
+ expect(s.button.backgroundLuminance).toBeGreaterThan(0.5);
74
+});