-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a29763
commit 437eb66
Showing
1 changed file
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,46 @@ | ||
it.todo('write a test'); | ||
import ComponentCache from '../cache/componentCache'; | ||
import { getTTLFromResponseHeaders } from '../utils/utils'; | ||
import * as React from 'react'; | ||
|
||
// Test TTL value parsing from response headers | ||
describe('getTTLFromResponseHeaders', () => { | ||
test('should return ttl value in milliseconds from response headers', () => { | ||
expect(getTTLFromResponseHeaders({ 'Cache-Control': 'max-age=3000' })).toBe( | ||
3000 | ||
); | ||
}); | ||
|
||
test('should return -1 if cache control header not found in response headers', () => { | ||
expect(getTTLFromResponseHeaders({})).toBe(-1); | ||
}); | ||
|
||
test('should return -1 if non standard cache control header value is used', () => { | ||
expect(getTTLFromResponseHeaders({ 'Cache-Control': '3000' })).toBe(-1); | ||
}); | ||
}); | ||
|
||
// Test component caching | ||
describe('Component Cache', () => { | ||
const cache = ComponentCache.getInstance<React.Component>(); | ||
const uri = 'https://my-component.com/mock-component'; | ||
const timestamp = Date.now(); | ||
const component = new React.Component({}); | ||
const cacheItem = { | ||
value: component, | ||
ttl: 3000, | ||
timestamp: timestamp, | ||
}; | ||
cache.set(uri, cacheItem); | ||
|
||
test('should return ttl value stored against URI', () => { | ||
expect(cache.getTTL(uri)).toBe(3000); | ||
}); | ||
|
||
test('should return timestamp value stored against URI', () => { | ||
expect(cache.getTimeStamp(uri)).toBe(timestamp); | ||
}); | ||
|
||
test('should return component value stored against URI', () => { | ||
expect(cache.get(uri)).toBe(component); | ||
}); | ||
}); |