@@ -1268,7 +1268,7 @@ describe("clipboard", () => {
12681268 expect ( getBorder ( model , "C3" ) ) . toEqual ( { bottom : DEFAULT_BORDER_DESC } ) ;
12691269 } ) ;
12701270
1271- test ( "paste as value does not remove number format" , ( ) => {
1271+ test ( "paste as value does remove number format" , ( ) => {
12721272 const model = new Model ( ) ;
12731273 setCellContent ( model , "B2" , "0.451" ) ;
12741274 setFormat ( model , "B2" , "0.00%" ) ;
@@ -1280,7 +1280,7 @@ describe("clipboard", () => {
12801280
12811281 copy ( model , "B2" ) ;
12821282 paste ( model , "C3" , "asValue" ) ;
1283- expect ( getCellContent ( model , "C3" ) ) . toBe ( "45.10% " ) ;
1283+ expect ( getCellContent ( model , "C3" ) ) . toBe ( "0.45 " ) ;
12841284 } ) ;
12851285
12861286 test ( "paste as value works with both no core format and empty string core format" , ( ) => {
@@ -1289,14 +1289,49 @@ describe("clipboard", () => {
12891289
12901290 copy ( model , "D4" ) ;
12911291 paste ( model , "E4" , "asValue" ) ;
1292- expect ( getCell ( model , "E4" ) ) . toMatchObject ( { content : "45448" , format : "m/d/yyyy" } ) ;
1292+ expect ( getCell ( model , "E4" ) ) . toMatchObject ( { content : "45448" , format : undefined } ) ;
12931293
12941294 setFormat ( model , "D4" , "" ) ; // An empty string format is equivalent to no format
12951295 expect ( getCellContent ( model , "D4" ) ) . toBe ( "6/5/2024" ) ;
12961296
12971297 copy ( model , "D4" ) ;
12981298 paste ( model , "E5" , "asValue" ) ;
1299- expect ( getCell ( model , "E5" ) ) . toMatchObject ( { content : "45448" , format : "m/d/yyyy" } ) ;
1299+ expect ( getCell ( model , "E5" ) ) . toMatchObject ( { content : "45448" , format : undefined } ) ;
1300+ } ) ;
1301+
1302+ test . each ( [
1303+ [ "1" , "0.00%" , "100.00%" ] ,
1304+ [ "46023" , "m/d/yyyy" , "1/1/2026" ] ,
1305+ ] ) (
1306+ "can copy a cell with a format and paste as value" ,
1307+ ( originalContent , format , formatedContent ) => {
1308+ const model = new Model ( ) ;
1309+ setCellContent ( model , "B2" , originalContent ) ;
1310+ setFormat ( model , "B2" , format ) ;
1311+ expect ( getCellContent ( model , "B2" ) ) . toBe ( formatedContent ) ;
1312+ expect ( getCell ( model , "B2" ) ! . format ) . toEqual ( format ) ;
1313+
1314+ copy ( model , "B2" ) ;
1315+ paste ( model , "C2" , "asValue" ) ;
1316+
1317+ expect ( getCellContent ( model , "C2" ) ) . toBe ( originalContent ) ;
1318+ expect ( getCell ( model , "C2" ) ! . format ) . not . toBeDefined ( ) ;
1319+ }
1320+ ) ;
1321+
1322+ test ( "copy as value : the cell take the format of the target cell" , ( ) => {
1323+ const model = new Model ( ) ;
1324+ setCellContent ( model , "B2" , "46023" ) ;
1325+ setFormat ( model , "B2" , "0.00%" ) ;
1326+ expect ( getCellContent ( model , "B2" ) ) . toBe ( "4602300.00%" ) ;
1327+ expect ( getCell ( model , "B2" ) ! . format ) . toEqual ( "0.00%" ) ;
1328+
1329+ setFormat ( model , "C2" , "m/d/yyyy" ) ;
1330+ copy ( model , "B2" ) ;
1331+ paste ( model , "C2" , "asValue" ) ;
1332+
1333+ expect ( getCellContent ( model , "C2" ) ) . toBe ( "1/1/2026" ) ;
1334+ expect ( getCell ( model , "C2" ) ! . format ) . toEqual ( "m/d/yyyy" ) ;
13001335 } ) ;
13011336
13021337 test ( "can copy a formula and paste as value" , ( ) => {
0 commit comments