1- import Big from "big.js" ;
2- import { listAttribute , listExpression , dynamic , obj } from "@mendix/widget-plugin-test-utils" ;
1+ jest . mock ( "mendix" , ( ) => ( { } ) , { virtual : true } ) ;
2+
3+ import { Big } from "big.js" ;
34import { ObjectItem } from "mendix" ;
5+ import { listAttribute , listExpression , dynamic , obj } from "@mendix/widget-plugin-test-utils" ;
46import { column } from "../../../utils/test-utils" ;
57import { readChunk , ExcelCell } from "../cell-readers" ;
68
@@ -46,24 +48,24 @@ describe("cell-readers", () => {
4648 expect ( cell . z ) . toBe ( "#,##0.00" ) ;
4749 } ) ;
4850
49- it ( "exports boolean attribute as Yes/No string cell" , ( ) => {
51+ it ( "exports boolean attribute as boolean cell" , ( ) => {
5052 const col = column ( "Active" , c => {
5153 c . showContentAs = "attribute" ;
5254 c . attribute = listAttribute ( ( ) => true ) ;
5355 } ) ;
5456 const cell = readSingleCell ( col ) ;
55- expect ( cell . t ) . toBe ( "s " ) ;
56- expect ( cell . v ) . toBe ( "Yes" ) ;
57+ expect ( cell . t ) . toBe ( "b " ) ;
58+ expect ( cell . v ) . toBe ( true ) ;
5759 } ) ;
5860
59- it ( "exports false boolean attribute as No " , ( ) => {
61+ it ( "exports false boolean attribute as boolean cell " , ( ) => {
6062 const col = column ( "Active" , c => {
6163 c . showContentAs = "attribute" ;
6264 c . attribute = listAttribute ( ( ) => false ) ;
6365 } ) ;
6466 const cell = readSingleCell ( col ) ;
65- expect ( cell . t ) . toBe ( "s " ) ;
66- expect ( cell . v ) . toBe ( "No" ) ;
67+ expect ( cell . t ) . toBe ( "b " ) ;
68+ expect ( cell . v ) . toBe ( false ) ;
6769 } ) ;
6870
6971 it ( "exports date attribute with format as date cell" , ( ) => {
@@ -80,16 +82,17 @@ describe("cell-readers", () => {
8082 expect ( cell . z ) . toBe ( "yyyy-mm-dd" ) ;
8183 } ) ;
8284
83- it ( "exports date attribute without format as string cell (displayValue) " , ( ) => {
85+ it ( "exports date attribute without format using default date format " , ( ) => {
8486 const testDate = new Date ( "2024-06-15T10:30:00Z" ) ;
8587 const col = column ( "Created" , c => {
8688 c . showContentAs = "attribute" ;
8789 c . attribute = listAttribute ( ( ) => testDate ) ;
8890 c . exportType = "default" ;
8991 } ) ;
9092 const cell = readSingleCell ( col ) ;
91- expect ( cell . t ) . toBe ( "s" ) ;
92- expect ( cell . v ) . toBe ( `Formatted ${ testDate } ` ) ;
93+ expect ( cell . t ) . toBe ( "d" ) ;
94+ expect ( cell . v ) . toEqual ( new Date ( Date . UTC ( 2024 , 5 , 15 ) ) ) ;
95+ expect ( cell . z ) . toBe ( "dd-mm-yyyy" ) ;
9396 } ) ;
9497
9598 it ( "returns empty cell when attribute is not available" , ( ) => {
@@ -125,7 +128,7 @@ describe("cell-readers", () => {
125128 it ( "returns n/a cell when dynamicText is unavailable" , ( ) => {
126129 const col = column ( "Label" , c => {
127130 c . showContentAs = "dynamicText" ;
128- c . dynamicText = listExpression ( ( ) => "text" , "unavailable" ) ;
131+ c . dynamicText = { get : ( ) => ( { status : "unavailable" , value : undefined } ) } as any ;
129132 } ) ;
130133 const cell = readSingleCell ( col ) ;
131134 expect ( cell . t ) . toBe ( "s" ) ;
@@ -226,15 +229,16 @@ describe("cell-readers", () => {
226229 expect ( cell . z ) . toBe ( "yyyy-mm-dd" ) ;
227230 } ) ;
228231
229- it ( "exports date as string when no format provided" , ( ) => {
232+ it ( "exports date with default format when no format provided" , ( ) => {
230233 const col = column ( "Created" , c => {
231234 c . showContentAs = "customContent" ;
232235 c . exportValue = listExpression ( ( ) => "2024-06-15T10:30:00Z" ) ;
233236 c . exportType = "date" ;
234237 } ) ;
235238 const cell = readSingleCell ( col ) ;
236- expect ( cell . t ) . toBe ( "s" ) ;
237- expect ( cell . v ) . toBe ( "2024-06-15T10:30:00Z" ) ;
239+ expect ( cell . t ) . toBe ( "d" ) ;
240+ expect ( cell . v ) . toEqual ( new Date ( Date . UTC ( 2024 , 5 , 15 ) ) ) ;
241+ expect ( cell . z ) . toBe ( "dd-mm-yyyy" ) ;
238242 } ) ;
239243
240244 it ( "falls back to string when date parse fails" , ( ) => {
@@ -260,6 +264,65 @@ describe("cell-readers", () => {
260264 expect ( cell . t ) . toBe ( "s" ) ;
261265 expect ( cell . v ) . toBe ( "" ) ;
262266 } ) ;
267+
268+ it ( "exports as boolean true when exportType is boolean and value is 'true'" , ( ) => {
269+ const col = column ( "Active" , c => {
270+ c . showContentAs = "customContent" ;
271+ c . exportValue = listExpression ( ( ) => "true" ) ;
272+ c . exportType = "boolean" ;
273+ } ) ;
274+ const cell = readSingleCell ( col ) ;
275+ expect ( cell . t ) . toBe ( "b" ) ;
276+ expect ( cell . v ) . toBe ( true ) ;
277+ } ) ;
278+
279+ it ( "exports as boolean false when exportType is boolean and value is 'false'" , ( ) => {
280+ const col = column ( "Active" , c => {
281+ c . showContentAs = "customContent" ;
282+ c . exportValue = listExpression ( ( ) => "false" ) ;
283+ c . exportType = "boolean" ;
284+ } ) ;
285+ const cell = readSingleCell ( col ) ;
286+ expect ( cell . t ) . toBe ( "b" ) ;
287+ expect ( cell . v ) . toBe ( false ) ;
288+ } ) ;
289+
290+ it ( "exports boolean true for case-insensitive values" , ( ) => {
291+ for ( const val of [ "True" , "YES" , "1" ] ) {
292+ const col = column ( "Active" , c => {
293+ c . showContentAs = "customContent" ;
294+ c . exportValue = listExpression ( ( ) => val ) ;
295+ c . exportType = "boolean" ;
296+ } ) ;
297+ const cell = readSingleCell ( col ) ;
298+ expect ( cell . t ) . toBe ( "b" ) ;
299+ expect ( cell . v ) . toBe ( true ) ;
300+ }
301+ } ) ;
302+
303+ it ( "exports boolean false for case-insensitive values" , ( ) => {
304+ for ( const val of [ "False" , "NO" , "0" ] ) {
305+ const col = column ( "Active" , c => {
306+ c . showContentAs = "customContent" ;
307+ c . exportValue = listExpression ( ( ) => val ) ;
308+ c . exportType = "boolean" ;
309+ } ) ;
310+ const cell = readSingleCell ( col ) ;
311+ expect ( cell . t ) . toBe ( "b" ) ;
312+ expect ( cell . v ) . toBe ( false ) ;
313+ }
314+ } ) ;
315+
316+ it ( "falls back to string for unrecognized boolean value" , ( ) => {
317+ const col = column ( "Active" , c => {
318+ c . showContentAs = "customContent" ;
319+ c . exportValue = listExpression ( ( ) => "maybe" ) ;
320+ c . exportType = "boolean" ;
321+ } ) ;
322+ const cell = readSingleCell ( col ) ;
323+ expect ( cell . t ) . toBe ( "s" ) ;
324+ expect ( cell . v ) . toBe ( "maybe" ) ;
325+ } ) ;
263326 } ) ;
264327
265328 describe ( "long number precision" , ( ) => {
0 commit comments