aboutsummaryrefslogtreecommitdiff
path: root/webAO/__tests__/isLowMemory.test.ts
diff options
context:
space:
mode:
authorstonedDiscord <Tukz@gmx.de>2025-06-26 19:03:47 +0200
committerstonedDiscord <Tukz@gmx.de>2025-06-26 19:03:47 +0200
commitceff9e184102cf72d04521332e8832f3475255f1 (patch)
tree2b281d8cf6b4d5f55d935fa55cacfcc45fb25a60 /webAO/__tests__/isLowMemory.test.ts
parentf3e80b1575442044adb3f835539e33701e1ef149 (diff)
dumbass smart tv
Diffstat (limited to 'webAO/__tests__/isLowMemory.test.ts')
-rw-r--r--webAO/__tests__/isLowMemory.test.ts44
1 files changed, 44 insertions, 0 deletions
diff --git a/webAO/__tests__/isLowMemory.test.ts b/webAO/__tests__/isLowMemory.test.ts
new file mode 100644
index 0000000..6428e17
--- /dev/null
+++ b/webAO/__tests__/isLowMemory.test.ts
@@ -0,0 +1,44 @@
+import { isLowMemory } from '../client/isLowMemory';
+import { setOldLoading } from '../client';
+
+// Mock the setOldLoading function
+jest.mock('../client', () => ({
+ setOldLoading: jest.fn(),
+}));
+
+describe('isLowMemory', () => {
+ beforeEach(() => {
+ // Reset mock before each test to ensure isolation
+ (setOldLoading as jest.Mock).mockReset();
+ });
+
+ it('should call setOldLoading with true when user agent is low memory device', () => {
+ Object.defineProperty(window, 'navigator', { value: { userAgent: 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.6099.270 Safari/537.36 WebAppManager' }, writable: true });
+ isLowMemory();
+
+ expect(setOldLoading).toHaveBeenCalled();
+ });
+
+ it('should not call setOldLoading when user agent is not a low memory device', () => {
+ Object.defineProperty(window, 'navigator', { value: { userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36' }, writable: true });
+ isLowMemory();
+
+ expect(setOldLoading).not.toHaveBeenCalled();
+ });
+
+ it('should call setOldLoading with true for different low memory devices', () => {
+ const testCases = [
+ 'Mozilla/5.0 (iPod touch; CPU iPhone OS 10_3_2 like Mac OS X) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.0 Mobile/14F89 Safari/602.1',
+ 'Mozilla/5.0 (Linux U; en-US) AppleWebKit/528.5 (KHTML, like Gecko, Safari/528.5 ) Version/4.0 Kindle/3.0 (screen 600x800; rotate) [ip:134.209.137.157]',
+ 'Mozilla/5.0 (New Nintendo 3DS like iPhone) AppleWebKit/536.30 (KHTML, like Gecko) NX/3.0.0.5.24 Mobile NintendoBrowser/1.12.10178.EU'
+ ];
+
+ for (const device of testCases) {
+ Object.defineProperty(window, 'navigator', { value: { userAgent: device }, writable: true });
+ isLowMemory();
+
+ expect(setOldLoading).toHaveBeenCalledWith(true);
+ }
+ });
+
+}); \ No newline at end of file