From d90a4d9ec5aa43b0f509a7673ec4eb71e2ab8cd8 Mon Sep 17 00:00:00 2001 From: ARPANPATRA111 Date: Fri, 12 Jun 2026 11:52:38 +0530 Subject: [PATCH] test(cacheControl-theme-contrast): verify Dark and Light Prefers-Color-Scheme Visual Cohesion (Variation 3) --- utils/cacheControl.theme-contrast.test.ts | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 utils/cacheControl.theme-contrast.test.ts diff --git a/utils/cacheControl.theme-contrast.test.ts b/utils/cacheControl.theme-contrast.test.ts new file mode 100644 index 000000000..5c81c560c --- /dev/null +++ b/utils/cacheControl.theme-contrast.test.ts @@ -0,0 +1,34 @@ +import { describe, it, expect } from 'vitest'; +import { buildCacheControlHeader } from './cacheControl'; + +describe('cacheControl - Dark and Light Prefers-Color-Scheme Visual Cohesion', () => { + it('returns the default s-maxage header when no options are provided', () => { + const header = buildCacheControlHeader({}); + expect(header).toBe('s-maxage=3600, stale-while-revalidate=86400'); + }); + + it('returns a no-store directive when bypass is true, overriding all other options', () => { + const header = buildCacheControlHeader({ + bypass: true, + secondsToMidnight: 5000, + isHistoricalYear: true, + }); + expect(header).toBe('no-cache, no-store, must-revalidate'); + }); + + it('returns an immutable cache header when isHistoricalYear is set', () => { + const header = buildCacheControlHeader({ isHistoricalYear: true }); + expect(header).toBe('public, s-maxage=31536000, immutable'); + }); + + it('includes secondsToMidnight in the s-maxage when provided without bypass or historical', () => { + const header = buildCacheControlHeader({ secondsToMidnight: 7200 }); + expect(header).toMatch(/^public, s-maxage=7200,/); + expect(header).toContain('stale-while-revalidate=86400'); + }); + + it('handles secondsToMidnight of zero correctly, producing s-maxage=0', () => { + const header = buildCacheControlHeader({ secondsToMidnight: 0 }); + expect(header).toBe('public, s-maxage=0, stale-while-revalidate=86400'); + }); +});