Skip to content

Commit 98a04cd

Browse files
author
Anders Breid
authored
Add clone and download buttons (#233)
- New Clone button to clone the subscription and open a new modal to edit the cloned subscription in. - Download Subscription, downloads the subscription as a .json file. - Removed text for buttons and replaced with mouse over text. - Update to documentation - Add tests
1 parent 1d4e7b6 commit 98a04cd

File tree

14 files changed

+320
-160
lines changed

14 files changed

+320
-160
lines changed

src/functionaltest/java/com/ericsson/ei/frontend/TestSubscriptionHandling.java

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@ public class TestSubscriptionHandling extends SeleniumBaseClass {
2727

2828
private static final String DOWNLOADED_TEMPLATE_FILE_PATH = String.join(File.separator, SeleniumConfig.getTempDownloadDirectory().getPath(),
2929
"subscriptionsTemplate.json");
30+
private static final String DOWNLOADED_BULK_SUBSCRIPTIONS_FILE_PATH = String.join(File.separator, SeleniumConfig.getTempDownloadDirectory().getPath(),
31+
"subscriptionsData.json");
3032
private static final String SUBSCRIPTION_TEMPLATE_FILE_PATH = String.join(File.separator, "src", "functionaltest", "resources", "responses",
3133
"SubscriptionTemplate.json");
3234
private static final String SUBSCRIPTION_FOR_RELOAD_TEST_FILE_PATH_LDAP = String.join(File.separator, "src", "functionaltest", "resources",
3335
"responses", "SubscriptionForUploadLDAP.json");
3436

3537
private static final String EXPAND_BUTTON_XPATH = "//tr[contains(.,'Subscription1')]/td[1]";
3638
private static final String VIEW_BUTTON_XPATH = "(//button[@id='view-Subscription1'])";
39+
private static final String CLONE_BUTTON_XPATH = "(//button[@id='clone-Subscription1'])";
3740
private static final String EDIT_BUTTON_XPATH = "(//button[@id='edit-Subscription1'])";
3841
private static final String DELETE_BUTTON_XPATH = "(//button[@id='delete-Subscription1'])";
3942

@@ -65,6 +68,12 @@ public class TestSubscriptionHandling extends SeleniumBaseClass {
6568

6669
private SubscriptionPage subscriptionPage;
6770

71+
@BeforeClass
72+
public static void setUpMocks() throws IOException {
73+
mockServer = startClientAndServer();
74+
mockClient = new MockServerClient(BASE_URL, mockServer.getLocalPort());
75+
}
76+
6877
@Before
6978
public void before() throws IOException {
7079
int portServer = mockServer.getLocalPort();
@@ -80,6 +89,7 @@ public void testSubscriptionButtons() throws Exception {
8089
setupMockEndpoints(security, username);
8190
removeAllSubscriptions();
8291
clickAndVerifyGetTemplateButton();
92+
clickAndVerifyBulkDownloadButton();
8393
uploadSubscriptions();
8494
verifySubscriptionsRequestDeleteAndPost();
8595
}
@@ -92,6 +102,8 @@ public void testAddSubscriptionAndVerifyForm() throws Exception {
92102
loadAndRefreshSubscriptionPage();
93103
clickAddSubscriptionAndVerifyFormOpen();
94104
clickFormCancelAndVerifyFormClosed();
105+
clickCloneSubscriptionAndVerifyFormOpen();
106+
clickFormCancelAndVerifyFormClosed();
95107
clickAddSubscriptionAndVerifyFormOpen();
96108
verifySelectTemplateMail();
97109
verifySelectTemplateREST();
@@ -133,12 +145,6 @@ public void testSubscriptionHandlingWithLDAPEnabled() throws Exception {
133145
verifyUnauthorizedSubscriptionCRUD();
134146
}
135147

136-
@BeforeClass
137-
public static void setUpMocks() throws IOException {
138-
mockServer = startClientAndServer();
139-
mockClient = new MockServerClient(BASE_URL, mockServer.getLocalPort());
140-
}
141-
142148
@AfterClass
143149
public static void tearDownMocks() throws IOException {
144150
mockClient.stop();
@@ -155,6 +161,7 @@ private void uploadSubscriptions() throws IOException {
155161

156162
private void removeAllSubscriptions() throws IOException {
157163
subscriptionPage.loadPage();
164+
subscriptionPage.clickCheckAll();
158165
subscriptionPage.clickBulkDelete();
159166
subscriptionPage.refreshPage();
160167
}
@@ -166,6 +173,16 @@ private void verifySubscriptionsRequestDeleteAndPost() throws InterruptedExcepti
166173
mockClient.verify(request().withMethod("POST").withPath("/subscriptions").withBody(downloadedSubscriptionsTemplate));
167174
}
168175

176+
private void clickAndVerifyBulkDownloadButton() throws IOException {
177+
subscriptionPage.loadPage();
178+
subscriptionPage.clickCheckAll();
179+
subscriptionPage.clickBulkDownload();
180+
new WebDriverWait(driver, 10).until((webdriver) -> Files.exists(Paths.get(DOWNLOADED_BULK_SUBSCRIPTIONS_FILE_PATH)));
181+
String downloadedSubscriptionsTemplate = getJSONStringFromFile(DOWNLOADED_BULK_SUBSCRIPTIONS_FILE_PATH);
182+
String subscriptions = getJSONStringFromFile(SUBSCRIPTION_FOR_RELOAD_TEST_FILE_PATH_LDAP);
183+
assertEquals(subscriptions, downloadedSubscriptionsTemplate);
184+
}
185+
169186
private void clickAndVerifyGetTemplateButton() throws IOException {
170187
new WebDriverWait(driver, 10).until((webdriver) -> subscriptionPage.presenceOfClickGetTemplateButton());
171188
subscriptionPage.clickGetTemplate();
@@ -249,9 +266,15 @@ private void clickAddSubscriptionAndVerifyFormOpen() {
249266
assert (subscriptionPage.presenceOfHeader(FORM_HEADER));
250267
}
251268

269+
private void clickCloneSubscriptionAndVerifyFormOpen() {
270+
subscriptionPage.clickExpandButtonByXPath(EXPAND_BUTTON_XPATH);
271+
subscriptionPage.clickButtonByXPath(CLONE_BUTTON_XPATH);
272+
assert (subscriptionPage.presenceOfHeader(FORM_HEADER));
273+
}
274+
252275
private void verifyViewButtonOnSubscription() {
253276
subscriptionPage.clickExpandButtonByXPath(EXPAND_BUTTON_XPATH2);
254-
subscriptionPage.clickViewButtonByXPath(VIEW_BUTTON_XPATH2);
277+
subscriptionPage.clickButtonByXPath(VIEW_BUTTON_XPATH2);
255278
assert (new WebDriverWait(driver, 10).until((webdriver) -> driver.getPageSource().contains("View Subscription")));
256279
subscriptionPage.clickFormCloseBtn();
257280
}
@@ -273,14 +296,20 @@ private void verifyUnauthorizedSubscriptionCRUD() {
273296
private void setupMockEndpoints(boolean security, String user) throws IOException {
274297
mockClient.clear(request());
275298
String subscriptionResponse = getJSONStringFromFile(SUBSCRIPTION_FOR_RELOAD_TEST_FILE_PATH_LDAP);
299+
String downloadBulkSubscriptionResponse = "{\"foundSubscriptions\": " + subscriptionResponse + "}";
276300
mockClient.when(request().withMethod("GET").withPath("/subscriptions"))
277301
.respond(response().withStatusCode(200).withBody(subscriptionResponse));
302+
mockClient.when(request().withMethod("GET").withPath("/subscriptions/Subscription1,Subscription2,Subscription3"))
303+
.respond(response().withStatusCode(200).withBody(downloadBulkSubscriptionResponse));
278304
mockClient.when(request().withMethod("DELETE").withPath("/subscriptions")).respond(response().withStatusCode(200).withBody(""));
279305
mockClient.when(request().withMethod("POST").withPath("/subscriptions")).respond(response().withStatusCode(200).withBody(""));
280306

281307
String subscriptionResponse2 = getJSONStringFromFile(SUBSCRIPTION_TEMPLATE_FILE_PATH);
308+
String downloadSubscriptionResponse = "{\"foundSubscriptions\": " + subscriptionResponse2 + "}";
282309
mockClient.when(request().withMethod("GET").withPath("/subscriptions/Subscription2"))
283310
.respond(response().withStatusCode(200).withBody(subscriptionResponse2));
311+
mockClient.when(request().withMethod("GET").withPath("/subscriptions/Subscription1"))
312+
.respond(response().withStatusCode(200).withBody(downloadSubscriptionResponse));
284313

285314
String responseStatus = "{\"status\":\"OK\"}";
286315
mockClient.when(request().withMethod("GET").withPath("/auth/checkStatus")).respond(response().withStatusCode(200).withBody(responseStatus));

src/functionaltest/java/com/ericsson/ei/frontend/pageobjects/SubscriptionPage.java

Lines changed: 64 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@
1414

1515
public class SubscriptionPage extends PageBaseClass {
1616
private static final String ROUTE = "/#subscriptions";
17+
private static final String ADD_SUBSCRIPTION_BUTTON_ID = "addSubscription";
18+
private static final String FORM_CANCEL_BUTTON_ID = "btnFormCancel";
19+
private static final String CHECK_ALL_BUTTON_ID = "check-all";
20+
private static final String RELOAD_BUTTON_ID = "reloadButton";
21+
private static final String SAVE_BUTTON_ID = "btnSave";
22+
private static final String GET_TEMPLATE_BUTTON_ID = "getTemplateButton";
23+
private static final String BULK_DOWNLOAD_BUTTON_ID = "bulkDownload";
24+
private static final String ADD_CONDITION_BUTTON_ID = "addCondition";
25+
private static final String ADD_REQUIREMENT_BUTTON_ID = "addRequirement";
26+
private static final String BULK_DELETE_BUTTON_ID = "bulkDelete";
27+
private static final String CLOSE_BUTTON_CLASS_NAME = "close";
1728

1829
public SubscriptionPage(CloseableHttpClient mockedHttpClient, FirefoxDriver driver, String baseUrl)
1930
throws IOException {
@@ -35,50 +46,75 @@ public boolean presenceOfHeader(String loc) {
3546
}
3647
}
3748

49+
/*
50+
* Button clicking start.
51+
*/
52+
3853
public void clickAddSubscription() {
39-
WebElement addSubscriptionBtn = new WebDriverWait(driver, TIMEOUT_TIMER).until(
40-
ExpectedConditions.elementToBeClickable(By.id("addSubscription")));
41-
addSubscriptionBtn.click();
54+
clickButtonById(ADD_SUBSCRIPTION_BUTTON_ID);
4255
}
4356

4457
public void clickFormsCancelBtn() {
45-
new WebDriverWait(driver, TIMEOUT_TIMER).until(ExpectedConditions.elementToBeClickable(By.id("btnFormCancel")));
46-
WebElement cancelBtn = driver.findElement(By.id("btnFormCancel"));
47-
cancelBtn.click();
58+
clickButtonById(FORM_CANCEL_BUTTON_ID);
4859
}
4960

50-
public void clickBulkDelete() throws IOException {
51-
new WebDriverWait(driver, TIMEOUT_TIMER).until(ExpectedConditions.elementToBeClickable(By.id("check-all")));
52-
WebElement checkbox = driver.findElement(By.id("check-all"));
53-
checkbox.click();
61+
public void clickCheckAll() {
62+
clickButtonById(CHECK_ALL_BUTTON_ID);
63+
}
64+
65+
public void clickReload() {
66+
clickButtonById(RELOAD_BUTTON_ID);
67+
}
5468

55-
new WebDriverWait(driver, TIMEOUT_TIMER).until(ExpectedConditions.elementToBeClickable(By.id("bulkDelete")));
56-
WebElement bulkDeleteBtn = driver.findElement(By.id("bulkDelete"));
57-
bulkDeleteBtn.click();
69+
public void clickFormsSaveBtn() {
70+
clickButtonById(SAVE_BUTTON_ID);
71+
}
72+
73+
public void clickGetTemplate() {
74+
clickButtonById(GET_TEMPLATE_BUTTON_ID);
75+
}
76+
77+
public void clickBulkDownload() {
78+
clickButtonById(BULK_DOWNLOAD_BUTTON_ID);
79+
}
80+
81+
public void clickAddConditionBtn() {
82+
clickButtonById(ADD_CONDITION_BUTTON_ID);
83+
}
84+
85+
public void clickAddRequirementBtn() {
86+
clickButtonById(ADD_REQUIREMENT_BUTTON_ID);
87+
}
88+
89+
public void clickReloadLDAP() {
90+
clickButtonById(RELOAD_BUTTON_ID);
91+
}
92+
93+
public void clickBulkDelete() throws IOException {
94+
clickButtonById(BULK_DELETE_BUTTON_ID);
5895
// Click confirm button to confirm delete
5996
new WebDriverWait(driver, TIMEOUT_TIMER).until(
6097
ExpectedConditions.elementToBeClickable(By.cssSelector(".confirm-delete .modal-footer .btn-danger")));
6198
WebElement confirmBtn = driver.findElement(By.cssSelector(".confirm-delete .modal-footer .btn-danger"));
6299
confirmBtn.click();
63100
}
64101

65-
public void clickReload() {
66-
new WebDriverWait(driver, TIMEOUT_TIMER).until(ExpectedConditions.elementToBeClickable(By.id("reloadButton")));
67-
WebElement reloadBtn = driver.findElement(By.id("reloadButton"));
68-
reloadBtn.click();
102+
public void clickButtonById(String id) {
103+
new WebDriverWait(driver, TIMEOUT_TIMER).until(
104+
ExpectedConditions.elementToBeClickable(By.id(id)));
105+
WebElement button = driver.findElement(By.id(id));
106+
button.click();
69107
}
70108

71-
public void clickFormsSaveBtn() throws IOException {
72-
new WebDriverWait(driver, TIMEOUT_TIMER).until(ExpectedConditions.elementToBeClickable(By.id("btnSave")));
73-
WebElement saveBtn = driver.findElement(By.id("btnSave"));
74-
saveBtn.click();
109+
public void clickFormCloseBtn() {
110+
new WebDriverWait(driver, TIMEOUT_TIMER).until(ExpectedConditions.elementToBeClickable(By.className(CLOSE_BUTTON_CLASS_NAME)));
111+
WebElement formCloseButton = driver.findElement(By.className(CLOSE_BUTTON_CLASS_NAME));
112+
formCloseButton.click();
75113
}
76114

77-
public void clickKVbtn(String loc) {
78-
new WebDriverWait(driver, TIMEOUT_TIMER).until(ExpectedConditions.elementToBeClickable(By.id(loc)));
79-
WebElement kvBtn = driver.findElement(By.id(loc));
80-
kvBtn.click();
81-
}
115+
/*
116+
* Button clicking stop.
117+
*/
82118

83119
public void selectDropdown(String loc, String value) {
84120
new WebDriverWait(driver, TIMEOUT_TIMER).until(ExpectedConditions.elementToBeClickable(By.id(loc)));
@@ -142,32 +178,6 @@ public boolean presenceOfClickGetTemplateButton() {
142178
}
143179
}
144180

145-
public void clickGetTemplate() {
146-
new WebDriverWait(driver, TIMEOUT_TIMER).until(
147-
ExpectedConditions.elementToBeClickable(By.id("getTemplateButton")));
148-
WebElement getTemplateButton = driver.findElement(By.id("getTemplateButton"));
149-
getTemplateButton.click();
150-
}
151-
152-
public void clickFormCloseBtn() {
153-
new WebDriverWait(driver, TIMEOUT_TIMER).until(ExpectedConditions.elementToBeClickable(By.className("close")));
154-
WebElement viewBtn = driver.findElement(By.className("close"));
155-
viewBtn.click();
156-
}
157-
158-
public void clickAddConditionBtn() {
159-
new WebDriverWait(driver, TIMEOUT_TIMER).until(ExpectedConditions.elementToBeClickable(By.id("addCondition")));
160-
WebElement viewBtn = driver.findElement(By.id("addCondition"));
161-
viewBtn.click();
162-
}
163-
164-
public void clickAddRequirementBtn() {
165-
new WebDriverWait(driver, TIMEOUT_TIMER).until(
166-
ExpectedConditions.elementToBeClickable(By.id("addRequirement")));
167-
WebElement viewBtn = driver.findElement(By.id("addRequirement"));
168-
viewBtn.click();
169-
}
170-
171181
public String getSubscriptionNameFromSubscription() {
172182
new WebDriverWait(driver, TIMEOUT_TIMER).until(
173183
ExpectedConditions.elementToBeClickable(By.xpath("//tr[@class='odd']/td[3]")));
@@ -186,8 +196,7 @@ public boolean expandButtonExist(String XPath) {
186196

187197
public boolean buttonExistByXPath(String XPath) {
188198
// The row indicates weather or not the del / view and edit buttons has moved
189-
// down to
190-
// next row.
199+
// down to next row.
191200
String findInRow;
192201
try {
193202
findInRow = "[2]";
@@ -217,12 +226,6 @@ public boolean buttonDisabledByXPath(String XPath) {
217226
}
218227
}
219228

220-
public void clickReloadLDAP() throws IOException {
221-
WebElement reloadBtn = new WebDriverWait(driver, TIMEOUT_TIMER).until(
222-
ExpectedConditions.elementToBeClickable(By.id("reloadButton")));
223-
reloadBtn.click();
224-
}
225-
226229
public boolean textExistsInTable(String txt) {
227230
try {
228231
new WebDriverWait(driver, TIMEOUT_TIMER).until(
@@ -263,7 +266,7 @@ public int countElements(String id) {
263266
.size();
264267
}
265268

266-
public void clickViewButtonByXPath(String XPath) {
269+
public void clickButtonByXPath(String XPath) {
267270
// The row indicates weather or not the del / view and edit buttons has moved
268271
// down to
269272
// next row.
@@ -293,5 +296,4 @@ public boolean noPresenceOfHeader(String loc) {
293296
return false;
294297
}
295298
}
296-
297299
}

src/main/resources/static/css/style.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,24 @@ table.dataTable.dtr-inline.collapsed > tbody > tr[role="row"] > td:first-child:b
249249
table.dataTable.dtr-inline.collapsed > tbody > tr > td > .dtr-details > li {
250250
word-break: break-word;
251251
}
252+
.table-btn .tooltiptext {
253+
visibility: hidden;
254+
width: 74px;
255+
background-color: #555555;
256+
color: #fff;
257+
text-align: center;
258+
border-radius: 6px;
259+
padding: 5px 0;
260+
261+
/* Position the tooltip */
262+
position: absolute;
263+
z-index: 1;
264+
margin-left: -46px;
265+
margin-top: -38px;
266+
}
267+
.table-btn:hover .tooltiptext {
268+
visibility: visible;
269+
}
252270
.modal-subscription {
253271
height: 100%;
254272
padding-left: 0 !important;

src/main/resources/static/js/common.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,22 @@ function executeIfLdapIsDeactivated() {
308308
$("#ldapUserName").text("");
309309
}
310310

311+
function downloadSubscriptions(subscriptionData, subscriptionNames) {
312+
var foundSubscriptions = subscriptionData.foundSubscriptions;
313+
var jsonData = JSON.stringify(foundSubscriptions, null, 2);
314+
if (jsonData == undefined || subscriptionNames == undefined) {
315+
logMessage("Subscription data to download was not found");
316+
return;
317+
}
318+
var fileName = "";
319+
if (stringContainsSubstring(subscriptionNames, ",")) {
320+
fileName = "subscriptionsData.json";
321+
} else {
322+
fileName = subscriptionNames + ".json";
323+
}
324+
downloadFile(jsonData, "application/json;charset=utf-8", fileName);
325+
}
326+
311327
function checkBackendSecured() {
312328
var callback = {
313329
success: function (responseData, textStatus) {
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
function downloadFile(data, type, title) {
1+
function downloadFile(data, type, fileName) {
22
if (window.navigator.msSaveOrOpenBlob) {
3-
downloadFileMSExplorer(data, type, title);
3+
downloadFileMSExplorer(data, type, fileName);
44
} else {
5-
downloadFileChromeFirefox(data, type, title);
5+
downloadFileChromeFirefox(data, type, fileName);
66
}
77
}
88

9-
function downloadFileChromeFirefox(data, type, title) {
9+
function downloadFileChromeFirefox(data, type, fileName) {
1010
var link = document.createElement('a');
1111
document.body.appendChild(link);
1212
link.setAttribute("href", "data:" + type + "," + encodeURIComponent(data));
13-
link.setAttribute("download", title);
13+
link.setAttribute("download", fileName);
1414
link.setAttribute("class", "hidden");
1515
link.setAttribute("target", "_self");
1616
link.click();
1717
}
1818

19-
function downloadFileMSExplorer(data, type, title) {
19+
function downloadFileMSExplorer(data, type, fileName) {
2020
var blob = new Blob([data], { type: type });
21-
window.navigator.msSaveOrOpenBlob(blob, title);
21+
window.navigator.msSaveOrOpenBlob(blob, fileName);
2222
}

0 commit comments

Comments
 (0)