Fix database connection list rendering and backend unit test

This commit is contained in:
Antonin Delpeuch 2019-09-22 18:31:38 +01:00
parent dca496aa3b
commit 71e76524e5
2 changed files with 10 additions and 19 deletions

View File

@ -241,12 +241,15 @@ Refine.DatabaseSourceUI.prototype._editConnection = function(connectionInfo) {
success: function(settings) {
if(settings){
$( "#menuListUl" ).empty();
var menuList = $('#menuListUl');
var items = [];
$.each(settings.savedConnections,function(index,savedConnection){
items.push('<li class="pure-menu-item sc-list"><a href="#" class="pure-menu-link context-menu-one">'
+ '<span class="context-menu-text" >' + savedConnection.connectionName + '</span>'
+ '<span class="sc-context-more-vert pull-right"> </span></a></li>');
var li = $('<li class="pure-menu-item sc-list"></li>').appendTo(menuList);
var a = $('<a href="#" class="pure-menu-link context-menu-one"></a>').appendTo(li);
$('<span class="context-menu-text"></span>').text(savedConnection.connectionName)
.appendTo(a);
$('<span class="sc-context-more-vert pull-right"> </span>').appendTo(a);
})
$( "#menuListUl" ).append(items.join(''));

View File

@ -1,8 +1,9 @@
package com.google.refine.extension.database.cmd;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.times;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertNotNull;
import java.io.File;
@ -14,6 +15,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.http.HttpStatus;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.testng.Assert;
@ -281,8 +283,6 @@ public class SavedConnectionCommandTest extends DBExtensionTests{
SUT.doDelete(request, response);
// String result = sw.getBuffer().toString().trim();
ObjectNode json = ParsingUtilities.mapper.createObjectNode();
Assert.assertNotNull(json);
@ -317,19 +317,7 @@ public class SavedConnectionCommandTest extends DBExtensionTests{
SUT.doPost(request, response);
String result = sw.getBuffer().toString().trim();
assertNotNull(result);
assertFalse(result.isEmpty(), "Valid response Message expected!");
ObjectNode json = ParsingUtilities.mapper.readValue(result, ObjectNode.class);
//System.out.println("json:" + json);
ArrayNode savedConnections = (ArrayNode) json.get("savedConnections");
Assert.assertNotNull(savedConnections);
int len = savedConnections.size();
Assert.assertEquals(len, 1);
verify(response, times(1)).sendError(HttpStatus.SC_BAD_REQUEST, "Connection Name is Invalid. Expecting [a-zA-Z0-9._-]");
}