-
Notifications
You must be signed in to change notification settings - Fork 2
/
test-resources.R
462 lines (361 loc) · 17 KB
/
test-resources.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
if (!exists("remDr")) source("initialize.R")
page_url <- paste0(site_url, "/project/Studies/begin.view?pageId=Resources")
context_of("test-resourcesPage.R", "Resources Page", page_url)
test_connection(remDr, page_url, "Resources: /Studies")
sleep_for(2)
test_that("test navigating to link tabs", {
remDr$findElements("id", "headerUserDropdown")[[1]]$clickElement()
remDr$findElements("css", "li#headerUserDropdown ul.dropdown-menu.dropdown-menu-right li")[[9]]$clickElement()
site_title <- remDr$getTitle()[[1]]
expect_equal(site_title, "Welcome to ImmuneSpace")
remDr$navigate(paste0(site_url, "/project/Studies/begin.view?pageId=Resources&tab=Reports"))
site_title <- remDr$getTitle()[[1]]
expect_equal(site_title, "Sign In: /Studies")
remDr$findElements("id", "email")[[1]]$sendKeysToElement(list(ISR_LOGIN))
remDr$findElements("id", "password")[[1]]$sendKeysToElement(list(ISR_PWD))
remDr$findElements("css", "a.labkey-button.primary.signin-btn")[[1]]$clickElement()
sleep_for(5)
site_title <- remDr$getTitle()[[1]]
expect_equal(site_title, "Resources: /Studies")
current_url <- paste0(page_url, "&tab=Reports")
expect_equal(unlist(remDr$getCurrentUrl()), current_url)
expect_equal(unlist(remDr$findElements("css", "div.tab-content div#Reports")[[1]]$getElementAttribute("aria-hidden")), "false")
})
test_that("test clicking linkable tabs", {
navigate_to_link("Reports")
sleep_for(2)
current_url <- paste0(page_url, "&tab=Reports")
expect_equal(unlist(remDr$getCurrentUrl()), current_url)
expect_equal(unlist(remDr$findElements("css", "nav.navbar.navbar-default ul.nav.navbar-nav li")[[1]]$getElementAttribute("class")), "active")
expect_equal(unlist(remDr$findElements("css", "div.tab-content div#Reports")[[1]]$getElementAttribute("aria-hidden")), "false")
navigate_to_link("Tools")
sleep_for(10)
current_url <- paste0(page_url, "&tab=Tools")
expect_equal(unlist(remDr$getCurrentUrl()), current_url)
expect_equal(unlist(remDr$findElements("css", "nav.navbar.navbar-default ul.nav.navbar-nav li a#Tools")[[1]]$getElementAttribute("aria-selected")), "true")
expect_equal(unlist(remDr$findElements("css", "div.tab-content div#Tools")[[1]]$getElementAttribute("aria-hidden")), "false")
navigate_to_link("ImmuneSpaceR")
sleep_for(2)
current_url <- paste0(page_url, "&tab=ImmuneSpaceR")
expect_equal(unlist(remDr$getCurrentUrl()), current_url)
expect_equal(unlist(remDr$findElements("css", "nav.navbar.navbar-default ul.nav.navbar-nav li a#ImmuneSpaceR")[[1]]$getElementAttribute("aria-selected")), "true")
expect_equal(unlist(remDr$findElements("css", "div.tab-content div#ImmuneSpaceR")[[1]]$getElementAttribute("aria-hidden")), "false")
remDr$findElements("css", "div#resources-page ul.nav.navbar-nav li.dropdown")[[1]]$clickElement()
sleep_for(1)
navigate_to_link("MostAccessed")
sleep_for(1)
current_url <- paste0(page_url, "&tab=MostAccessed")
expect_equal(unlist(remDr$getCurrentUrl()), current_url)
expect_equal(unlist(remDr$findElements("css", "nav.navbar.navbar-default ul.nav.navbar-nav li")[[2]]$getElementAttribute("class")), "active dropdown")
expect_equal(unlist(remDr$findElements("css", "div.tab-content div#MostAccessed")[[1]]$getElementAttribute("aria-hidden")), "false")
remDr$findElements("css", "div#resources-page ul.nav.navbar-nav li.dropdown")[[1]]$clickElement()
navigate_to_link("MostCited")
sleep_for(1)
current_url <- paste0(page_url, "&tab=MostCited")
expect_equal(unlist(remDr$getCurrentUrl()), current_url)
expect_equal(unlist(remDr$findElements("css", "div.tab-content div#MostCited")[[1]]$getElementAttribute("aria-hidden")), "false")
remDr$findElements("css", "div#resources-page ul.nav.navbar-nav li.dropdown")[[1]]$clickElement()
navigate_to_link("SimilarStudies")
sleep_for(1)
current_url <- paste0(page_url, "&tab=SimilarStudies")
expect_equal(unlist(remDr$getCurrentUrl()), current_url)
expect_equal(unlist(remDr$findElements("css", "div.tab-content div#SimilarStudies")[[1]]$getElementAttribute("aria-hidden")), "false")
})
test_that("test linking tabs from alternative url", {
remDr$navigate("https://www.google.com/")
expect_equal(unlist(remDr$getCurrentUrl()), "https://www.google.com/")
remDr$navigate(page_url)
sleep_for(5)
current_url <- paste0(page_url, "&tab=Reports")
expect_equal(unlist(remDr$getCurrentUrl()), current_url)
expect_equal(unlist(remDr$findElements("css", "nav.navbar.navbar-default ul.nav.navbar-nav li")[[1]]$getElementAttribute("class")), "active")
expect_equal(unlist(remDr$findElements("css", "div.tab-content div#Reports")[[1]]$getElementAttribute("aria-hidden")), "false")
remDr$goBack()
sleep_for(5)
expect_equal(unlist(remDr$getCurrentUrl()), "https://www.google.com/")
remDr$goForward()
sleep_for(5)
current_url <- paste0(page_url, "&tab=Reports")
expect_equal(unlist(remDr$getCurrentUrl()), current_url)
expect_equal(unlist(remDr$findElements("css", "nav.navbar.navbar-default ul.nav.navbar-nav li")[[1]]$getElementAttribute("class")), "active")
expect_equal(unlist(remDr$findElements("css", "div.tab-content div#Reports")[[1]]$getElementAttribute("aria-hidden")), "false")
remDr$goBack()
sleep_for(5)
expect_equal(unlist(remDr$getCurrentUrl()), "https://www.google.com/")
remDr$navigate(paste0(page_url, "&tab=SimilarStudies"))
sleep_for(1)
current_url <- paste0(page_url, "&tab=SimilarStudies")
expect_equal(unlist(remDr$getCurrentUrl()), current_url)
expect_equal(remDr$findElements("css", "div.tab-content div#SimilarStudies")[[1]]$getElementAttribute("aria-hidden")[[1]], "false")
remDr$goBack()
sleep_for(5)
expect_equal(unlist(remDr$getCurrentUrl()), "https://www.google.com/")
remDr$goForward()
sleep_for(1)
current_url <- paste0(page_url, "&tab=SimilarStudies")
expect_equal(unlist(remDr$getCurrentUrl()), current_url)
expect_equal(remDr$findElements("css", "div.tab-content div#SimilarStudies")[[1]]$getElementAttribute("aria-hidden")[[1]], "false")
})
test_that("forward and back buttons", {
current_url <- paste0(page_url, "&tab=SimilarStudies")
expect_equal(unlist(remDr$getCurrentUrl()), current_url)
navigate_to_link("ImmuneSpaceR")
sleep_for(20)
current_url <- paste0(page_url, "&tab=ImmuneSpaceR")
expect_equal(unlist(remDr$getCurrentUrl()), current_url)
expect_equal(unlist(remDr$findElements("css", "nav.navbar.navbar-default ul.nav.navbar-nav li a#ImmuneSpaceR")[[1]]$getElementAttribute("aria-selected")), "true")
expect_equal(unlist(remDr$findElements("css", "div.tab-content div#ImmuneSpaceR")[[1]]$getElementAttribute("aria-hidden")), "false")
remDr$goBack()
sleep_for(5)
current_url <- paste0(page_url, "&tab=SimilarStudies")
expect_equal(unlist(remDr$getCurrentUrl()), current_url)
expect_equal(remDr$findElements("css", "div.tab-content div#SimilarStudies")[[1]]$getElementAttribute("aria-hidden")[[1]], "false")
remDr$goForward()
sleep_for(20)
current_url <- paste0(page_url, "&tab=ImmuneSpaceR")
expect_equal(unlist(remDr$getCurrentUrl()), current_url)
expect_equal(unlist(remDr$findElements("css", "nav.navbar.navbar-default ul.nav.navbar-nav li a#ImmuneSpaceR")[[1]]$getElementAttribute("aria-selected")), "true")
expect_equal(unlist(remDr$findElements("css", "div.tab-content div#ImmuneSpaceR")[[1]]$getElementAttribute("aria-hidden")), "false")
remDr$goBack()
sleep_for(5)
})
test_that("page refresh", {
current_url <- paste0(page_url, "&tab=SimilarStudies")
expect_equal(unlist(remDr$getCurrentUrl()), current_url)
remDr$refresh()
sleep_for(5)
expect_equal(unlist(remDr$getCurrentUrl()), current_url)
expect_equal(remDr$findElements("css", "div.tab-content div#SimilarStudies")[[1]]$getElementAttribute("aria-hidden")[[1]], "false")
remDr$findElements("id", "ImmuneSpaceR")[[1]]$clickElement()
sleep_for(1)
current_url <- paste0(page_url, "&tab=ImmuneSpaceR")
expect_equal(unlist(remDr$getCurrentUrl()), current_url)
expect_equal(remDr$findElements("css", "div.tab-content div#ImmuneSpaceR")[[1]]$getElementAttribute("aria-hidden")[[1]], "false")
remDr$refresh()
sleep_for(10)
expect_equal(unlist(remDr$getCurrentUrl()), current_url)
expect_equal(remDr$findElements("css", "div.tab-content div#ImmuneSpaceR")[[1]]$getElementAttribute("aria-hidden")[[1]], "false")
})
test_that("all webpart is present", {
test_presence_of_single_item("resources-page")
})
test_that("Highlighted Reports tab has correct elements", {
navigate_to_link("Reports")
div <- remDr$findElement("id", "Reports-content")
expect_length(div, 1)
# number of reports is greater than 0
tableRows <- div$findChildElements("tag name", "tr")
expect_length(tableRows, 6)
# pictures and text are present
actualHeaders <- unlist(sapply(tableRows, function(tr) {
imgTd <- tr$findChildElement("class", "hr-imgCol")
test_presence_of_single_img(imgTd)
infoTd <- tr$findChildElement("class", "hr-infoCol")
ahref <- infoTd$findChildElement("tag name", "a")
expect_length(ahref, 1)
header <- infoTd$findChildElement("tag name", "h2")
headerText <- header$getElementText()
}))
expectedHeaders <- c(
"Correlation of HAI/VN and plasma cell counts",
"Measuring plasmablast abundance by multi-parameter flow cytometry",
"Multiple custom reports related to CyTOF and Flow Cytometry Data",
"Correlating HAI with flow cytometry and ELISPOT results",
"Influenza Vaccine Meta-Analysis to define genetic predictors of vaccine response",
"Standardizing Flow Cytometry Immunophenotyping from Reagents to Analyses: Results of the Human ImmunoPhenotyping Consortium"
)
expect_true(all.equal(actualHeaders, expectedHeaders))
})
test_that("Study Statistics tab has correct elements", {
getBarPlotWidths <- function(rectsContainer) {
widths <- unlist(sapply(rectsContainer, function(rect) {
width <- rect$getElementAttribute("width")
}))
}
# ----
click_target_dropdown("Study Statistics")
reportOptions <- get_dropdown_options()
expect_length(reportOptions, 3)
expectedReportTitles <- c(
"Most Accessed",
"Most Cited",
"Similar Studies"
)
check_dropdown_titles(expectedReportTitles, reportOptions)
###########################
# Most accessed studies #
###########################
reportOptions[[1]]$clickElement()
sleep_for(2)
mostAccessedDiv <- remDr$findElement("id", "most-accessed-content")
h2 <- mostAccessedDiv$findChildElements("tag name", "h2")
expect_length(h2, 1)
# --- check byStudy ---
byStudyDiv <- mostAccessedDiv$findChildElement("id", "byStudy")
plot <- byStudyDiv$findChildElement("id", "ma-barplot-byStudy")
rects <- plot$findChildElements("tag name", "rect")
allUxWidths <- getBarPlotWidths(rects)
expect_true(length(allUxWidths) > 150)
selectOrderBtn <- remDr$findElement("id", "ma-bar-order-select-dropdown")
expect_length(selectOrderBtn, 1)
selectOrderBtn$clickElement()
parentDiv <- remDr$findElement("css", "[class = 'dropdown open btn-group']")
ahrefs <- parentDiv$findChildElements("tag name", "a")
expect_length(ahrefs, 3)
orderOptions <- unlist(sapply(ahrefs, function(a) {
text <- a$getElementText()
}))
expectedOrderOptions <- c(
"UI Pageviews",
"ImmuneSpaceR connections",
"All interactions"
)
expect_true(all.equal(orderOptions, expectedOrderOptions))
ahrefs[[1]]$clickElement()
sleep_for(2)
plot <- remDr$findElement("id", "ma-barplot-byStudy")
rects <- plot$findChildElements("tag name", "rect")
pageViewWidths <- getBarPlotWidths(rects)
expect_true(!isTRUE(all.equal(pageViewWidths, allUxWidths)))
selectOrderBtn <- remDr$findElement("id", "ma-bar-order-select-dropdown")
selectOrderBtn$clickElement()
parentDiv <- remDr$findElement("css", "[class = 'dropdown open btn-group']")
ahrefs <- parentDiv$findChildElements("tag name", "a")
ahrefs[[2]]$clickElement()
sleep_for(2)
plot <- remDr$findElement("id", "ma-barplot-byStudy")
rects <- plot$findChildElements("tag name", "rect")
isrConnectionsWidths <- getBarPlotWidths(rects)
expect_true(!isTRUE(all.equal(isrConnectionsWidths, pageViewWidths)))
selectPlotTypeBtn <- remDr$findElement("id", "ma-type-select-dropdown")
selectPlotTypeBtn$clickElement()
parentDiv <- remDr$findElement("css", "[class = 'dropdown open btn-group']")
ahrefs <- parentDiv$findChildElements("tag name", "a")
expect_length(ahrefs, 2)
plotTypeOptions <- unlist(sapply(ahrefs, function(a) {
text <- a$getElementText()
}))
expectedPlotTypeOptions <- c(
"By Study",
"By Month"
)
expect_true(all.equal(plotTypeOptions, expectedPlotTypeOptions))
ahrefs[[2]]$clickElement()
sleep_for(2)
selectOrderBtn <- remDr$findElements("id", "ma-bar-order-select-dropdown")
expect_length(selectOrderBtn, 0)
plot <- remDr$findElement("id", "ma-lineplot-byMonth")
paths <- plot$findChildElements("tag name", "path")
domains <- sapply(paths, function(x) {
x$getElementAttribute("class")
})
paths <- paths[lengths(domains) == 0] # domain paths are for axis labels
expect_length(paths, 2)
########################
# Most Cited Studies #
########################
click_target_dropdown("Study Statistics")
reportOptions <- get_dropdown_options()
reportOptions[[2]]$clickElement()
sleep_for(2)
mostCitedDiv <- remDr$findElement("id", "#most-cited")
h2 <- mostCitedDiv$findChildElement("tag name", "h2")
expect_length(h2, 1)
ul <- mostCitedDiv$findChildElement("tag name", "ul")
liElements <- ul$findChildElements("tag name", "li")
expect_length(liElements, 3)
plot <- mostCitedDiv$findChildElement("id", "mc-barplot-byPubId")
rects <- plot$findChildElements("tag name", "rect")
byPubIdWidths <- getBarPlotWidths(rects)
expect_true(length(byPubIdWidths) > 65)
selectOrderBtn <- remDr$findElement("id", "order-select-dropdown")
expect_length(selectOrderBtn, 1)
selectOrderBtn$clickElement()
parentDiv <- remDr$findElement("css", "[class = 'dropdown open btn-group']")
ahrefs <- parentDiv$findChildElements("tag name", "a")
expect_length(ahrefs, 3)
orderOptions <- unlist(sapply(ahrefs, function(a) {
text <- a$getElementText()
}))
expectedOrderOptions <- c(
"Most Cited",
"Study ID",
"Most Recent"
)
expect_true(all.equal(orderOptions, expectedOrderOptions))
ahrefs[[2]]$clickElement()
sleep_for(2)
plot <- remDr$findElement("id", "mc-barplot-byPubId")
rects <- plot$findChildElements("tag name", "rect")
byMostCitedWidths <- getBarPlotWidths(rects)
expect_true(!isTRUE(all.equal(byPubIdWidths, byMostCitedWidths)))
#####################
# Similar Studies #
#####################
# -- Assays --
click_target_dropdown("Study Statistics")
reportOptions <- get_dropdown_options()
reportOptions[[3]]$clickElement()
similarStudiesDiv <- remDr$findElement("id", "similar-studies-content")
h2 <- similarStudiesDiv$findChildElement("tag name", "h2")
expect_length(h2, 1)
ul <- similarStudiesDiv$findChildElement("tag name", "ul")
liElements <- ul$findChildElements("tag name", "li")
expect_length(liElements, 2)
assaysDiv <- similarStudiesDiv$findChildElement("id", "assays")
plots <- assaysDiv$findChildElements("tag name", "svg")
expect_length(plots, 8)
circles <- plots[[1]]$findChildElements("tag name", "circle")
expect_true(length(circles) > 95)
byAssayIds <- unlist(sapply(plots, function(plot) {
id <- plot$getElementAttribute("id")
}))
selectOrderBtn <- similarStudiesDiv$findChildElements("id", "order-select-dropdown")
expect_length(selectOrderBtn, 1)
selectOrderBtn[[1]]$clickElement()
parentDiv <- remDr$findElement("css", "[class = 'dropdown open btn-group']")
ahrefs <- parentDiv$findChildElements("tag name", "a")
expect_length(ahrefs, 3)
orderOptions <- unlist(sapply(ahrefs, function(a) {
text <- a$getElementText()
}))
expectedOrderOptions <- c(
"Assay Data Available",
"Study Design",
"Condition Studied"
)
expect_true(all.equal(orderOptions, expectedOrderOptions))
ahrefs[[2]]$clickElement()
sleep_for(2)
# -- similar study design --
similarStudiesDiv <- remDr$findElement("id", "similar-studies-content")
studyDesignDiv <- similarStudiesDiv$findChildElement("id", "studyDesign")
plots <- studyDesignDiv$findChildElements("tag name", "svg")
expect_length(plots, 4)
circles <- plots[[1]]$findChildElements("tag name", "circle")
expect_true(length(circles) > 95)
byStudyDesignIds <- unlist(sapply(plots, function(plot) {
id <- plot$getElementAttribute("id")
}))
expect_true(!isTRUE(all.equal(byAssayIds, byStudyDesignIds)))
# -- condition studied --
selectOrderBtn[[1]]$clickElement()
ahrefs[[3]]$clickElement()
conditionDiv <- similarStudiesDiv$findChildElement("id", "condition")
plots <- conditionDiv$findChildElements("tag name", "svg")
expect_length(plots, 16)
})
test_that("HIPC Tools tab has correct elements", {
navigate_to_link("Tools")
div <- remDr$findElement("id", "tools-content")
expect_length(div, 1)
sections <- div$findChildElements("tag name", "p")
expect_length(sections, 5)
})
test_that("HIPC ImmuneSpaceR tab has correct elements", {
navigate_to_link("ImmuneSpaceR")
sleep_for(3)
iframe <- remDr$findElement("tag", "iframe")
expect_length(iframe, 1)
# TODO: how to inspect iframe contents?
})