-
Notifications
You must be signed in to change notification settings - Fork 794
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
only generate TS localtext proxy for objects - dont generate for valu…
…es (#6870) add tests for localtext proxy call localtext when proxy tries to access null keys
- Loading branch information
1 parent
f8f3096
commit c1bc580
Showing
3 changed files
with
77 additions
and
6 deletions.
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
beforeEach(() => { | ||
jest.resetModules(); | ||
jest.unmock('./system'); | ||
}); | ||
|
||
const mockLocalTextStore = (localTexts: Record<string, any>) => { | ||
jest.mock('./system', () => ({ | ||
getStateStore: jest.fn(() => localTexts) | ||
})); | ||
} | ||
|
||
|
||
|
||
describe('proxyTexts', () => { | ||
it('proxies simple object', async () => { | ||
mockLocalTextStore({ | ||
'a.b': 'Abc', | ||
}); | ||
|
||
const proxyTexts = (await import('./localtext')).proxyTexts; | ||
const texts = proxyTexts({}, '', {a: {}}) as any; | ||
|
||
expect(texts.a.b).toEqual('Abc'); | ||
}); | ||
|
||
it('proxies nested object', async () => { | ||
mockLocalTextStore({ | ||
'a.b.c': 'Ab12c', | ||
'a.c': 'A1c', | ||
}); | ||
|
||
const proxyTexts = (await import('./localtext')).proxyTexts; | ||
const texts = proxyTexts({}, '', { | ||
a: { | ||
b: {} | ||
} | ||
}) as any; | ||
|
||
expect(texts.a.b.c).toEqual('Ab12c'); | ||
expect(texts.a.c).toEqual('A1c'); | ||
}); | ||
|
||
it('proxies multiple nested object', async () => { | ||
mockLocalTextStore({ | ||
'a.b.c': 'Ab12c', | ||
'a.c': 'A1c', | ||
'b.c.d': 'B1cd', | ||
}); | ||
|
||
const proxyTexts = (await import('./localtext')).proxyTexts; | ||
const texts = proxyTexts({}, '', { | ||
a: { | ||
b: {} | ||
}, | ||
b: { | ||
c: {} | ||
} | ||
}) as any; | ||
|
||
expect(texts.b.c.d).toEqual('B1cd'); | ||
}); | ||
|
||
it('proxies single level object', async () => { | ||
mockLocalTextStore({ | ||
'a': 'Abc', | ||
}); | ||
|
||
const proxyTexts = (await import('./localtext')).proxyTexts; | ||
const texts = proxyTexts({}, '', {}) as any; | ||
|
||
expect(texts.a).toEqual('Abc'); | ||
}); | ||
}); |
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
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