test: comprehensive test suites and quality gates pass across backend, storefront and admin
- Backend (NestJS): 82 suites, 641 tests passing; 0 ESLint errors; 0 tsc errors. Hardened SSL cert/key matching, SSRF IP pinning, and eBank validation. - Admin Panel (Vite/React): 48 suites, 300 tests passing; 0 ESLint errors; 0 tsc errors. Full coverage across all pages and settings. - Storefront (Next.js): 62 suites, 368 tests passing; 0 ESLint errors; 0 tsc errors. - Fixed unmount lifecycle guards, promise error handling, and component edge cases.
This commit is contained in:
1 parent
1e73715169
commit
ddbf1ca026
439 files changed
+32911
-6107
No files matched your search
@@ -0,0 +1,14 @@
|
||||
import React from 'react';
|
||||
import {render,fireEvent,act,cleanup} from '@testing-library/react';
|
||||
import {vi,beforeEach,afterEach,it,expect} from 'vitest';
|
||||
import AnalyticsDeferred from '../AnalyticsDeferred';
|
||||
beforeEach(()=>{vi.useFakeTimers();document.head.innerHTML='';delete window.dataLayer;delete window.clarity;});
|
||||
afterEach(()=>{cleanup();vi.useRealTimers();vi.unstubAllGlobals();});
|
||||
it('defers tags until interaction and loads only once',()=>{render(<AnalyticsDeferred gtmId="GTM-test" gaId="G-test" clarityId="test"/>);expect(document.scripts).toHaveLength(0);fireEvent.scroll(window);fireEvent.keyDown(window);act(()=>vi.advanceTimersByTime(3500));expect(document.scripts).toHaveLength(3);expect(window.dataLayer).toEqual(expect.arrayContaining([['config','G-test',{page_path:'/'}]]));});
|
||||
it.each(['scroll','touchstart','mousemove','keydown'])('loads on %s',event=>{render(<AnalyticsDeferred gtmId="GTM-test"/>);fireEvent(window,new Event(event));expect(document.scripts).toHaveLength(1);});
|
||||
it('loads clarity when no script exists',()=>{render(<AnalyticsDeferred clarityId="solo"/>);fireEvent.scroll(window);expect(document.querySelector('script')?.src).toBe('https://www.clarity.ms/tag/solo');});
|
||||
it('preserves the existing clarity implementation',()=>{const clarity=vi.fn();window.clarity=clarity;render(<AnalyticsDeferred clarityId="existing"/>);fireEvent.scroll(window);expect(window.clarity).toBe(clarity);expect(document.querySelector('script')?.src).toBe('https://www.clarity.ms/tag/existing');});
|
||||
it('queues clarity calls before its script initializes',()=>{render(<AnalyticsDeferred clarityId="queued"/>);fireEvent.scroll(window);window.clarity('event','checkout');expect(window.clarity.q).toEqual([['event','checkout']]);});
|
||||
it('falls back after 3500ms and reuses existing GA script',()=>{const s=document.createElement('script');s.src='https://www.googletagmanager.com/gtag/js?id=G-test';document.head.append(s);render(<AnalyticsDeferred gaId="G-test"/>);act(()=>vi.advanceTimersByTime(3499));expect(window.dataLayer).toBeUndefined();act(()=>vi.advanceTimersByTime(1));expect(document.scripts).toHaveLength(1);});
|
||||
it('cancels idle work on unmount',()=>{let cb:()=>void=()=>{};vi.stubGlobal('requestIdleCallback',vi.fn(fn=>{cb=fn;return 9;}));vi.stubGlobal('cancelIdleCallback',vi.fn());const v=render(<AnalyticsDeferred gtmId="GTM-test"/>);act(()=>vi.advanceTimersByTime(3500));v.unmount();act(()=>cb());expect(document.scripts).toHaveLength(0);expect(cancelIdleCallback).toHaveBeenCalledWith(9);});
|
||||
it('unmount removes event and timeout callbacks',()=>{const v=render(<AnalyticsDeferred gtmId="GTM-test"/>);v.unmount();fireEvent.scroll(window);act(()=>vi.advanceTimersByTime(4000));expect(document.scripts).toHaveLength(0);});
|
||||
Reference in new issue
Block a user