|
| 1 | +import { describe, test, expect, beforeEach } from 'react-native-harness'; |
| 2 | +import { NativeCookie } from 'mendix-native'; |
| 3 | + |
| 4 | +describe('NativeCookie', () => { |
| 5 | + describe('API surface', () => { |
| 6 | + test('should expose clearAll method', () => { |
| 7 | + expect(typeof NativeCookie.clearAll).toBe('function'); |
| 8 | + }); |
| 9 | + }); |
| 10 | + |
| 11 | + describe('clearAll', () => { |
| 12 | + test('should call clearAll without throwing', async () => { |
| 13 | + await expect(NativeCookie.clearAll()).resolves.not.toThrow(); |
| 14 | + }); |
| 15 | + |
| 16 | + test('should return a Promise', () => { |
| 17 | + const result = NativeCookie.clearAll(); |
| 18 | + expect(result).toBeInstanceOf(Promise); |
| 19 | + }); |
| 20 | + |
| 21 | + test('should resolve to undefined', async () => { |
| 22 | + const result = await NativeCookie.clearAll(); |
| 23 | + expect(result).toBeOneOf([undefined, null]); |
| 24 | + }); |
| 25 | + |
| 26 | + test('should be callable multiple times', async () => { |
| 27 | + await NativeCookie.clearAll(); |
| 28 | + await NativeCookie.clearAll(); |
| 29 | + await NativeCookie.clearAll(); |
| 30 | + |
| 31 | + // Should not throw |
| 32 | + expect(true).toBe(true); |
| 33 | + }); |
| 34 | + |
| 35 | + test('should handle concurrent clearAll calls', async () => { |
| 36 | + const promises = [ |
| 37 | + NativeCookie.clearAll(), |
| 38 | + NativeCookie.clearAll(), |
| 39 | + NativeCookie.clearAll(), |
| 40 | + ]; |
| 41 | + |
| 42 | + await expect(Promise.all(promises)).resolves.not.toThrow(); |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + describe('integration scenarios', () => { |
| 47 | + beforeEach(async () => { |
| 48 | + // Clear cookies before each test |
| 49 | + await NativeCookie.clearAll(); |
| 50 | + }); |
| 51 | + |
| 52 | + test('should clear all cookies when called', async () => { |
| 53 | + // This test verifies that clearAll can be called successfully |
| 54 | + // The actual cookie clearing behavior would need to be tested |
| 55 | + // in an integration test with a real web view |
| 56 | + await expect(NativeCookie.clearAll()).resolves.not.toThrow(); |
| 57 | + }); |
| 58 | + |
| 59 | + test('should work when no cookies exist', async () => { |
| 60 | + // Calling clearAll when there are no cookies should succeed |
| 61 | + await NativeCookie.clearAll(); |
| 62 | + await expect(NativeCookie.clearAll()).resolves.not.toThrow(); |
| 63 | + }); |
| 64 | + }); |
| 65 | +}); |
0 commit comments