@@ -1405,7 +1405,7 @@ describe("draggable.vue when initialized with a transition group", () => {
1405
1405
} ) ;
1406
1406
} ) ;
1407
1407
1408
- describe ( "when using only footer slot" , ( ) => {
1408
+ describe ( "when using only footer slot with an empty list " , ( ) => {
1409
1409
beforeEach ( async ( ) => {
1410
1410
resetMocks ( ) ;
1411
1411
@@ -1429,7 +1429,7 @@ describe("when using only footer slot", () => {
1429
1429
expectHTML ( wrapper , expectedDOM ) ;
1430
1430
} ) ;
1431
1431
1432
- describe ( "when add is called on an empty list with " , ( ) => {
1432
+ describe ( "when add is called" , ( ) => {
1433
1433
let newItem ;
1434
1434
const expectedDOMAfterUpdate = `<ul><li data-draggable="true">1</li><footer>I am the footer</footer></ul>` ;
1435
1435
beforeEach ( async ( ) => {
@@ -1475,3 +1475,74 @@ describe("when using only footer slot", () => {
1475
1475
} ) ;
1476
1476
} ) ;
1477
1477
} ) ;
1478
+
1479
+ describe ( "when using only footer slot with an none-empty list" , ( ) => {
1480
+ beforeEach ( async ( ) => {
1481
+ resetMocks ( ) ;
1482
+
1483
+ wrapper = mount ( draggable , {
1484
+ props : {
1485
+ tag : "ul" ,
1486
+ list : [ "first" ] ,
1487
+ itemKey : k => k
1488
+ } ,
1489
+ slots : {
1490
+ item : ( { element } ) => h ( "li" , null , element ) ,
1491
+ footer : ( ) => h ( "footer" , null , "I am the footer" )
1492
+ }
1493
+ } ) ;
1494
+ vm = wrapper . vm ;
1495
+ element = wrapper . element ;
1496
+ } ) ;
1497
+
1498
+ it ( "renders correctly" , ( ) => {
1499
+ const expectedDOM = `<ul><li data-draggable="true">first</li><footer>I am the footer</footer></ul>` ;
1500
+ expectHTML ( wrapper , expectedDOM ) ;
1501
+ } ) ;
1502
+
1503
+ describe ( "when add is called" , ( ) => {
1504
+ let newItem ;
1505
+ const expectedDOMAfterUpdate = `<ul><li data-draggable="true">first</li><li data-draggable="true">last</li><footer>I am the footer</footer></ul>` ;
1506
+ beforeEach ( async ( ) => {
1507
+ await nextTick ( ) ;
1508
+
1509
+ newItem = document . createElement ( "li" ) ;
1510
+ const newContent = document . createTextNode ( "1" ) ;
1511
+ newItem . appendChild ( newContent ) ;
1512
+ newItem . _underlying_vm_ = "last" ;
1513
+ const last = element . children [ 1 ] ;
1514
+ element . insertBefore ( newItem , last ) ;
1515
+
1516
+ const add = getEvent ( "onAdd" ) ;
1517
+ add ( {
1518
+ item : newItem ,
1519
+ newIndex : 1
1520
+ } ) ;
1521
+ } ) ;
1522
+
1523
+ it ( "DOM changes should be performed" , async ( ) => {
1524
+ await nextTick ( ) ;
1525
+ expectHTML ( wrapper , expectedDOMAfterUpdate ) ;
1526
+ } ) ;
1527
+
1528
+ it ( "list should be updated" , async ( ) => {
1529
+ await nextTick ( ) ;
1530
+ expect ( vm . list ) . toEqual ( [ "first" , "last" ] ) ;
1531
+ } ) ;
1532
+
1533
+ it ( "sends a update event" , async ( ) => {
1534
+ await nextTick ( ) ;
1535
+ const expectedEvt = {
1536
+ item : newItem ,
1537
+ newIndex : 1
1538
+ } ;
1539
+ expect ( wrapper . emitted ( ) . add ) . toEqual ( [ [ expectedEvt ] ] ) ;
1540
+ } ) ;
1541
+
1542
+ it ( "sends a change event" , async ( ) => {
1543
+ await nextTick ( ) ;
1544
+ const expectedEvt = { added : { element : "last" , newIndex : 1 } } ;
1545
+ expect ( wrapper . emitted ( ) . change ) . toEqual ( [ [ expectedEvt ] ] ) ;
1546
+ } ) ;
1547
+ } ) ;
1548
+ } ) ;
0 commit comments