rave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfrank...@apache.org
Subject svn commit: r1145661 - in /incubator/rave/trunk/rave-portal/src: main/java/org/apache/rave/portal/model/ main/java/org/apache/rave/portal/service/ main/java/org/apache/rave/portal/service/impl/ main/java/org/apache/rave/portal/web/api/rpc/ main/webapp/...
Date Tue, 12 Jul 2011 16:26:26 GMT
Author: mfranklin
Date: Tue Jul 12 16:26:25 2011
New Revision: 1145661

URL: http://svn.apache.org/viewvc?rev=1145661&view=rev
Log:
Updated delete rpc api to take only a regionWidgetId for delete operations (Supports RAVE-58)

Modified:
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/RegionWidget.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/PageService.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java
    incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/PageApi.java
    incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/home.jsp
    incubator/rave/trunk/rave-portal/src/main/webapp/script/rave.js
    incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_api.js
    incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/repository/AbstractJpaRepositoryTest.java
    incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/PageServiceTest.java
    incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/PageApiTest.java
    incubator/rave/trunk/rave-portal/src/test/javascript/raveApiSpec.js

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/RegionWidget.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/RegionWidget.java?rev=1145661&r1=1145660&r2=1145661&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/RegionWidget.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/model/RegionWidget.java
Tue Jul 12 16:26:25 2011
@@ -49,6 +49,10 @@ public class RegionWidget implements Bas
     @Column(name = "collapsed")
     private boolean collapsed;
 
+    @Basic
+    @Column(name="region_id")
+    private long regionId;
+
     @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
     @JoinColumn(name = "region_widget_id", referencedColumnName = "id")
     private List<RegionWidgetPreference> preferences;
@@ -122,6 +126,18 @@ public class RegionWidget implements Bas
     }
 
     /**
+     * Gets the id of the associated region
+     * @return region's id
+     */
+    public long getRegionId() {
+        return regionId;
+    }
+
+    public void setRegionId(long regionId) {
+        this.regionId = regionId;
+    }
+
+    /**
      * Gets whether or not to render the gadget in collapsed mode
      *
      * @return true if render collapsed; false otherwise

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/PageService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/PageService.java?rev=1145661&r1=1145660&r2=1145661&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/PageService.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/PageService.java
Tue Jul 12 16:26:25 2011
@@ -53,14 +53,15 @@ public interface PageService {
     RegionWidget addWidgetToPage(long page_id, long widget_id);
 
 	 /**
-	  * Deletes a specified widget from the specied page.
+	  * Deletes the specified widget from the page.
 	  *
       * @param regionWidgetId the id of the region widget to delete.\
-	  */
-	 void removeWidgetFromPage(long regionWidgetId);
+      * @return the region from which the widget was deleted
+      */
+	 Region removeWidgetFromPage(long regionWidgetId);
 
 	 /**
-	  * Registers a new page. 
+	  * Registers a new page.
 	  * @param page the page object to register with the data management system.
 	  */
 	 void registerNewPage(Page page);

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java?rev=1145661&r1=1145660&r2=1145661&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java
Tue Jul 12 16:26:25 2011
@@ -66,13 +66,10 @@ public class DefaultPageService implemen
 
     @Override
     @Transactional
-    public void removeWidgetFromPage(long regionWidgetId) {
+    public Region removeWidgetFromPage(long regionWidgetId) {
         RegionWidget widget = getFromRepository(regionWidgetId, regionWidgetRepository);
-        if (widget != null) {
-            regionWidgetRepository.delete(widget);
-        } else {
-            throw new IllegalArgumentException("Region widget with id " + regionWidgetId
+ " was not found in the repository");
-        }
+        regionWidgetRepository.delete(widget);
+        return getFromRepository(widget.getRegionId(), regionRepository);
     }
 
     @Override

Modified: incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/PageApi.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/PageApi.java?rev=1145661&r1=1145660&r2=1145661&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/PageApi.java
(original)
+++ incubator/rave/trunk/rave-portal/src/main/java/org/apache/rave/portal/web/api/rpc/PageApi.java
Tue Jul 12 16:26:25 2011
@@ -121,8 +121,7 @@ public class PageApi {
 		return new RpcOperation<Region>() {
 			@Override
 			public Region execute() {
-		        pageService.removeWidgetFromPage(regionWidgetId);
-                return null;
+		        return pageService.removeWidgetFromPage(regionWidgetId);
             }
 		}.getResult();
     }

Modified: incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/home.jsp
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/home.jsp?rev=1145661&r1=1145660&r2=1145661&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/home.jsp (original)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/WEB-INF/views/home.jsp Tue Jul 12 16:26:25
2011
@@ -55,7 +55,7 @@
               </button>
               <button id="widget-${regionWidget.id}-remove"
                       class="widget-toolbar-btn"
-                      onclick="rave.toolbarDelete(this,{myRegionWidgetId:${regionWidget.id},myRegionId:${region.id},myPageId:${defaultPage.id}})">
+                      onclick="rave.toolbarDelete(this,{myRegionWidgetId:${regionWidget.id}})">
               </button>
             </div>
           </div>

Modified: incubator/rave/trunk/rave-portal/src/main/webapp/script/rave.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/webapp/script/rave.js?rev=1145661&r1=1145660&r2=1145661&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/script/rave.js (original)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/script/rave.js Tue Jul 12 16:26:25 2011
@@ -113,20 +113,15 @@ var rave = rave || (function() {
 		  }
 		  function maximizeAction(button,args) {
 				alert("Maximize button not yet implemented");
-		  };
+		  }
 		  function deleteAction(button,args) {
 				rave.api.rpc.removeWidget({
-					 regionWidgetId: args.myRegionWidgetId, 
-					 pageId : args.myPageId,
-					 region: {
-						  id : rave.getGadgetRegion(args.myRegionWidgetId)
-					 },
-					 succCB: function() {
+					 regionWidgetId: args.myRegionWidgetId,
+					 successCallback: function() {
 						  $("#widget-wrapper-"+args.myRegionWidgetId).remove();
 					 }
 				});
-
-		  };
+		  }
 		  return {
 				maximizeAction : maximizeAction,
 				deleteAction : deleteAction

Modified: incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_api.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_api.js?rev=1145661&r1=1145660&r2=1145661&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_api.js (original)
+++ incubator/rave/trunk/rave-portal/src/main/webapp/script/rave_api.js Tue Jul 12 16:26:25
2011
@@ -1,4 +1,4 @@
- /*
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -18,73 +18,69 @@
  */
 var rave = rave || {};
 /**
- * Namespace that provides client access to Rave server APIs. 
+ * Namespace that provides client access to Rave server APIs.
  * Note required jquery libraries must be imported by the containing page.
  */
 rave.api = rave.api || (function() {
     var rpcApi = (function() {
-      //Base path to RPC services
+        //Base path to RPC services
         var path = "api/rpc/";
 
-      //This method is implemented by PageApi.java.  
+        //This method is implemented by PageApi.java.
         function moveWidgetOnPage(args) {
             var widgetObjectId = rave.getObjectIdFromDomId(args.widget.id);
             var toRegionObjectId = rave.getObjectIdFromDomId(args.targetRegion.id);
             var fromRegionObjectId = rave.getObjectIdFromDomId(args.currentRegion.id);
             //Note context must be set outside this library.  See home.jsp for example.
             $.post(rave.getContext() + path + "page/regionWidget/" + widgetObjectId + "/move",
-                    {
-                        newPosition: args.targetIndex,
-                        toRegion: toRegionObjectId,
-                        fromRegion: fromRegionObjectId
-                    },
-                    function(result) {
-                        if (result.error) {
-                            handleRpcError(result);
-                        } else {
-                            rave.mapGadgetToRegion(widgetObjectId, toRegionObjectId);
-                        }
+                {
+                    newPosition: args.targetIndex,
+                    toRegion: toRegionObjectId,
+                    fromRegion: fromRegionObjectId
+                },
+                function(result) {
+                    if (result.error) {
+                        handleRpcError(result);
+                    } else {
+                        rave.mapGadgetToRegion(widgetObjectId, toRegionObjectId);
                     }
+                }
             ).error(handleError);
         }
 
         function addWidgetToPage(args) {
             $.post(rave.getContext() + path + "page/" + args.pageId + "/widget/add",
-                    {
-                        widgetId: args.widgetId
-                    },
-                    function(result) {
-                        if (result.error) {
-                            handleRpcError(result);
-                        } else {
-                            var widgetTitle = "The widget";
-                            var addedWidget = result.result != undefined ? result.result.widget
: undefined;
-                            
-                            if (addedWidget != undefined && addedWidget.title !=
undefined && addedWidget.title.length > 0) {
-                                widgetTitle = addedWidget.title;
-                            }
-                            alert(widgetTitle + " has been added to your page");
+                {
+                    widgetId: args.widgetId
+                },
+                function(result) {
+                    if (result.error) {
+                        handleRpcError(result);
+                    } else {
+                        var widgetTitle = "The widget";
+                        var addedWidget = result.result != undefined ? result.result.widget
: undefined;
+
+                        if (addedWidget != undefined && addedWidget.title != undefined
&& addedWidget.title.length > 0) {
+                            widgetTitle = addedWidget.title;
                         }
-                    }).error(handleError);
+                        alert(widgetTitle + " has been added to your page");
+                    }
+                }).error(handleError);
         }
 
-      function deleteWidgetOnPage(args) {
-        $.post(rave.getContext() + path + "page/" +args.pageId + "/widget/delete",
-             {
-                widgetId: args.regionWidgetId,
-                regionId: args.region.id            
-             },
-             function(result) {
-                if(result.error && result.error == true) {
-                  handleRpcError(result);
-                } else {
-                    rave.mapGadgetToRegion(args.regionWidgetId, null);
-                    if (args.succCB != null && typeof args.succCB == 'function')
{
-                        args.succCB();
+        function deleteWidgetOnPage(args) {
+            $.post(rave.getContext() + path + "page/regionWidget/" + args.regionWidgetId
+ "/delete",
+                null,
+                function(result) {
+                    if (result.error) {
+                        handleRpcError(result);
+                    } else {
+                        if (typeof args.successCallback == 'function') {
+                            args.successCallback();
+                        }
                     }
-                }
-             }).error(handleError);
-      }
+                }).error(handleError);
+        }
 
         function handleError(jqXhr, status, error) {
             alert("Rave encountered an error while trying to contact the server.  Please
reload the page and try again. error: " + error);
@@ -97,11 +93,11 @@ rave.api = rave.api || (function() {
                     break;
                 case "INVALID_PARAMS":
                     alert("Rave attempted to update the server with your recent changes,
" +
-                            " but the changes were rejected by the server as invalid.");
+                        " but the changes were rejected by the server as invalid.");
                     break;
                 case "INTERNAL_ERROR":
                     alert("Rave attempted to update the server with your recent changes,
" +
-                            " but the server encountered an internal error.");
+                        " but the server encountered an internal error.");
                     break;
             }
         }

Modified: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/repository/AbstractJpaRepositoryTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/repository/AbstractJpaRepositoryTest.java?rev=1145661&r1=1145660&r2=1145661&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/repository/AbstractJpaRepositoryTest.java
(original)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/repository/AbstractJpaRepositoryTest.java
Tue Jul 12 16:26:25 2011
@@ -21,6 +21,7 @@ package org.apache.rave.portal.repositor
 
 import org.apache.rave.portal.model.BasicEntity;
 import org.apache.rave.portal.repository.impl.AbstractJpaRepository;
+import org.hamcrest.CoreMatchers;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -98,6 +99,17 @@ public class AbstractJpaRepositoryTest {
 
     }
 
+    @Test
+    @Rollback(true)
+    public void delete() {
+        for(AbstractJpaRepository repository : repositories) {
+            BasicEntity entity = repository.get(VALID_ENTITY_ID);
+            repository.delete(entity);
+            sharedManager.flush();
+            assertThat(repository.get(VALID_ENTITY_ID), is(nullValue()));
+        }
+    }
+
     private BasicEntity constructNewEntityForRepository(AbstractJpaRepository repository)
{
         try {
             Field field = AbstractJpaRepository.class.getDeclaredField("type");

Modified: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/PageServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/PageServiceTest.java?rev=1145661&r1=1145660&r2=1145661&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/PageServiceTest.java
(original)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/service/PageServiceTest.java
Tue Jul 12 16:26:25 2011
@@ -25,6 +25,7 @@ import org.apache.rave.portal.model.Regi
 import org.apache.rave.portal.model.Widget;
 import org.apache.rave.portal.repository.PageRepository;
 import org.apache.rave.portal.repository.RegionRepository;
+import org.apache.rave.portal.repository.RegionWidgetRepository;
 import org.apache.rave.portal.repository.WidgetRepository;
 import org.apache.rave.portal.service.impl.DefaultPageService;
 import org.hamcrest.CoreMatchers;
@@ -44,6 +45,7 @@ public class PageServiceTest {
     private PageRepository pageRepository;
     private RegionRepository regionRepository;
     private WidgetRepository widgetRepository;
+    private RegionWidgetRepository regionWidgetRepository;
 
     private static final long REGION_WIDGET_ID = 5L;
     private static final long TO_REGION_ID = 1L;
@@ -57,7 +59,8 @@ public class PageServiceTest {
         pageRepository = createNiceMock(PageRepository.class);
         regionRepository = createNiceMock(RegionRepository.class);
         widgetRepository = createNiceMock(WidgetRepository.class);
-        pageService = new DefaultPageService(pageRepository, regionRepository, widgetRepository,
null);
+        regionWidgetRepository = createNiceMock(RegionWidgetRepository.class);
+        pageService = new DefaultPageService(pageRepository, regionRepository, widgetRepository,
regionWidgetRepository);
 
         targetRegion = new Region();
         targetRegion.setRegionWidgets(new ArrayList<RegionWidget>());
@@ -229,6 +232,37 @@ public class PageServiceTest {
         pageService.addWidgetToPage(PAGE_ID, WIDGET_ID);
     }
 
+    @Test
+    public void removeWidgetFromPage_validWidget() {
+        long WIDGET_ID = 1L;
+        long REGION_ID = 2L;
+        RegionWidget widget = new RegionWidget(WIDGET_ID);
+        widget.setRegionId(REGION_ID);
+        Region region = new Region();
+
+        expect(regionWidgetRepository.get(WIDGET_ID)).andReturn(widget);
+        regionWidgetRepository.delete(widget);
+        expectLastCall();
+        replay(regionWidgetRepository);
+        expect(regionRepository.get(REGION_ID)).andReturn(region);
+        replay(regionRepository);
+
+        Region result = pageService.removeWidgetFromPage(WIDGET_ID);
+        verify(regionWidgetRepository);
+        verify(regionRepository);
+        assertThat(result, is(sameInstance(region)));
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void removeWidgetFromPage_invalidWidget() {
+        long WIDGET_ID = -1L;
+        expect(regionWidgetRepository.get(WIDGET_ID)).andReturn(null);
+        replay(regionWidgetRepository);
+        replay(regionRepository);
+
+        pageService.removeWidgetFromPage(WIDGET_ID);
+    }
+
     private void verifyPositions(int newPosition, RegionWidget widget, boolean sameRegion)
{
         assertThat(widget.getRenderOrder(), is(equalTo(newPosition)));
         if (!sameRegion) {

Modified: incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/PageApiTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/PageApiTest.java?rev=1145661&r1=1145660&r2=1145661&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/PageApiTest.java
(original)
+++ incubator/rave/trunk/rave-portal/src/test/java/org/apache/rave/portal/web/api/rpc/PageApiTest.java
Tue Jul 12 16:26:25 2011
@@ -19,9 +19,11 @@
 
 package org.apache.rave.portal.web.api.rpc;
 
+import org.apache.rave.portal.model.Region;
 import org.apache.rave.portal.model.RegionWidget;
 import org.apache.rave.portal.service.PageService;
 import org.apache.rave.portal.web.api.rpc.model.RpcResult;
+import org.hamcrest.CoreMatchers;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -147,24 +149,24 @@ public class PageApiTest {
     @Test
     public void deleteWidget_validParams() {
         final long WIDGET_ID = 3;
-        pageService.removeWidgetFromPage(WIDGET_ID);
-        expectLastCall();
-        RpcResult result = pageApi.removeWidgetFromPage(WIDGET_ID);
+        expect(pageService.removeWidgetFromPage(WIDGET_ID)).andReturn(new Region());
+        replay(pageService);
+
+        RpcResult<Region> result = pageApi.removeWidgetFromPage(WIDGET_ID);
         verify(pageService);
         assertThat(result, is(notNullValue()));
-        assertThat(result.getResult(), is(nullValue()));
+        assertThat(result.getResult(), is(notNullValue()));
         assertThat(result.isError(), is(false));
 
     }
 
    @Test
     public void deleteWidget_invalidParams() {
-        final int PAGE_ID = 1;
         final long WIDGET_ID = 2;
 
-        expect(pageService.addWidgetToPage(PAGE_ID, WIDGET_ID)).andThrow(new IllegalArgumentException(PARAM_ERROR_MESSAGE));
+        expect(pageService.removeWidgetFromPage(WIDGET_ID)).andThrow(new IllegalArgumentException(PARAM_ERROR_MESSAGE));
         replay(pageService);
-        RpcResult result = pageApi.addWidgetToPage(PAGE_ID, WIDGET_ID);
+        RpcResult result = pageApi.removeWidgetFromPage(WIDGET_ID);
         verify(pageService);
         assertThat(result, is(notNullValue()));
         assertThat(result.getResult(), is(nullValue()));
@@ -175,12 +177,11 @@ public class PageApiTest {
 
     @Test
     public void deleteWidget_internalError() {
-        final int PAGE_ID = 1;
         final long WIDGET_ID = 2;
 
-        expect(pageService.addWidgetToPage(PAGE_ID, WIDGET_ID)).andThrow(new RuntimeException(INTERNAL_ERROR_MESSAGE));
+        expect(pageService.removeWidgetFromPage(WIDGET_ID)).andThrow(new RuntimeException(INTERNAL_ERROR_MESSAGE));
         replay(pageService);
-        RpcResult result = pageApi.addWidgetToPage(PAGE_ID, WIDGET_ID);
+        RpcResult result = pageApi.removeWidgetFromPage(WIDGET_ID);
         verify(pageService);
         assertThat(result, is(notNullValue()));
         assertThat(result.getResult(), is(nullValue()));

Modified: incubator/rave/trunk/rave-portal/src/test/javascript/raveApiSpec.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal/src/test/javascript/raveApiSpec.js?rev=1145661&r1=1145660&r2=1145661&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal/src/test/javascript/raveApiSpec.js (original)
+++ incubator/rave/trunk/rave-portal/src/test/javascript/raveApiSpec.js Tue Jul 12 16:26:25
2011
@@ -30,7 +30,8 @@ describe("Rave API", function() {
                     expect(data.widgetId).toEqual(2);
                     expect(typeof(callback)).toEqual("function");
                     return {
-                        error: function(a, b, c) {}
+                        error: function(a, b, c) {
+                        }
                     }
                 };
                 rave.api.rpc.addWidgetToPage({pageId: 1, widgetId: 2});
@@ -46,24 +47,46 @@ describe("Rave API", function() {
                     expect(data.newPosition).toEqual(3);
                     expect(typeof(callback)).toEqual("function");
                     return {
-                        error: function(a, b, c) {}
+                        error: function(a, b, c) {
+                        }
                     }
                 };
                 rave.api.rpc.moveWidget({targetRegion: {id:"region-1"}, currentRegion: {id:"region-2"},
targetIndex: 3, widget:{id:"widget-3-body"}});
             });
         });
+        describe("deleteWidget", function() {
+            it("posts correct values to the RPC service for deleting a widget from the page",
function() {
+                var callbackCalled = false;
+                $.post = function(url, data, callback) {
+                    expect(url).toEqual("api/rpc/page/regionWidget/1/delete");
+                    expect(typeof(callback)).toEqual("function");
+                    callback({error:false});
+                    return {
+                        error: function(a, b, c) {
+                        }
+                    }
+                };
+                var callback = function() {
+                    callbackCalled = true
+                };
+                rave.api.rpc.removeWidget({regionWidgetId : 1, successCallback: callback});
+                expect(callbackCalled).toBeTruthy();
+            });
+
+        });
         describe("Error handling", function() {
             it("displays the appropriate alert when invalid parameters are passed", function()
{
 
                 $.post = function(url, data, handler) {
                     handler({error: true, errorCode: "INVALID_PARAMS"});
                     return {
-                        error: function(a, b, c) {}
+                        error: function(a, b, c) {
+                        }
                     }
                 };
                 alert = function(str) {
                     expect(str).toEqual("Rave attempted to update the server with your recent
changes, " +
-                            " but the changes were rejected by the server as invalid.");
+                        " but the changes were rejected by the server as invalid.");
                 };
                 rave.api.rpc.moveWidget({targetRegion: {id:"region-1"}, currentRegion: {id:"region-2"},
targetIndex: 3, widget:{id:"widget-3-body"}});
 
@@ -73,12 +96,13 @@ describe("Rave API", function() {
                 $.post = function(url, data, handler) {
                     handler({error: true, errorCode: "INTERNAL_ERROR"});
                     return {
-                        error: function(a, b, c) {}
+                        error: function(a, b, c) {
+                        }
                     }
                 };
                 alert = function(str) {
                     expect(str).toEqual("Rave attempted to update the server with your recent
changes, " +
-                            " but the server encountered an internal error.");
+                        " but the server encountered an internal error.");
                 };
                 rave.api.rpc.moveWidget({targetRegion: {id:"region-1"}, currentRegion: {id:"region-2"},
targetIndex: 3, widget:{id:"widget-3-body"}});
             });



Mime
View raw message