-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using Proxy to prevent against modification the original view model.
- Loading branch information
Showing
3 changed files
with
50 additions
and
10 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
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,22 @@ | ||
export type ViewModel = any; | ||
|
||
export const createVmProxyHandler = ()=> { | ||
const data: Record<string | number, unknown> = {}; | ||
|
||
return { | ||
get(target: any, p: PropertyKey): any { | ||
if (typeof p !== 'string' && typeof p !== 'number') { | ||
return; | ||
} | ||
return p in data ? data[p] : target[p] | ||
}, | ||
set(target: unknown, p: PropertyKey, value: unknown): boolean { | ||
if (typeof p !== 'string' && typeof p !== 'number') { | ||
return false; | ||
} | ||
data[p] = value | ||
|
||
return true | ||
}, | ||
} | ||
} |
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,25 @@ | ||
import * as chai from 'chai'; | ||
import { CellValue, Workbook } from 'exceljs'; | ||
import { ValueType } from 'exceljs'; | ||
import { Renderer } from '../../src/Renderer'; | ||
|
||
const WS_NAME = 'test ws'; | ||
|
||
describe('BaseCell unit tests', () => { | ||
const factory = async ():Promise<Workbook> =>{ | ||
const template = new Workbook(); | ||
template.addWorksheet(WS_NAME).addRow(['## testVar', "#! FINISH"]); | ||
|
||
return template; | ||
} | ||
|
||
it('DateTime', async () => { | ||
const viewModel = { | ||
testVar: new Date(2023, 11, 17, 21, 37) | ||
} | ||
const renderer = new Renderer(); | ||
const output = await renderer.render(factory, viewModel) | ||
|
||
chai.expect(output.getWorksheet(WS_NAME)?.getCell('A1').type).equals(ValueType.Date); | ||
}); | ||
}); |