Skip to content

Commit 702b67d

Browse files
authored
Merge pull request #3630 from arovit/add_find_replace_test
[WIP: 838] Add find replace test
2 parents 2c061a4 + b22994e commit 702b67d

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

notebook/static/notebook/js/searchandreplace.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ define([
163163

164164
var allCellsButton = $('<button/>')
165165
.append($('<i/>').addClass('fa fa-arrows-v'))
166+
.attr('id', 'findreplace_allcells_btn')
166167
.attr('type', 'button')
167168
.addClass("btn btn-default btn-sm")
168169
.attr('data-toggle','button')
@@ -179,6 +180,7 @@ define([
179180

180181
var search = $("<input/>")
181182
.addClass('form-control input-sm')
183+
.attr('id', 'findreplace_find_inp')
182184
.attr('placeholder',i18n.msg._('Find'));
183185

184186
var findFormGroup = $('<div/>').addClass('form-group');
@@ -194,6 +196,7 @@ define([
194196
)
195197

196198
var replace = $("<input/>")
199+
.attr('id', 'findreplace_replace_inp')
197200
.addClass('form-control input-sm')
198201
.attr('placeholder',i18n.msg._('Replace'));
199202
var replaceFormGroup = $('<div/>').addClass('form-group');
@@ -354,7 +357,8 @@ define([
354357
keyboard_manager: env.notebook.keyboard_manager,
355358
buttons:{
356359
'Replace All':{ class: "btn-primary",
357-
click: function(event){onsubmit(event); return true;}
360+
click: function(event){onsubmit(event); return true;},
361+
id: "findreplace_replaceall_btn",
358362
}
359363
},
360364
open: function(){
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import pytest
2+
3+
4+
def test_find_and_replace(notebook):
5+
""" test find and replace on all the cells """
6+
cell_0, cell_1, cell_2, cell_3 = "hello", "hellohello", "abc", "ello"
7+
8+
find_str = "ello" # string to replace
9+
replace_str = "foo" # string to replace to
10+
11+
# set the contents of the cells
12+
notebook.add_cell(index=0, content=cell_0);
13+
notebook.add_cell(index=1, content=cell_1);
14+
notebook.add_cell(index=2, content=cell_2);
15+
notebook.add_cell(index=3, content=cell_3);
16+
17+
# replace the strings
18+
notebook.find_and_replace(index=0, find_txt=find_str, replace_txt=replace_str)
19+
20+
# check content of the cells
21+
assert notebook.get_cell_contents(0) == cell_0.replace(find_str, replace_str)
22+
assert notebook.get_cell_contents(1) == cell_1.replace(find_str, replace_str)
23+
assert notebook.get_cell_contents(2) == cell_2.replace(find_str, replace_str)
24+
assert notebook.get_cell_contents(3) == cell_3.replace(find_str, replace_str)

notebook/tests/selenium/utils.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
2+
import time
33
from selenium.webdriver import ActionChains
44
from selenium.webdriver.common.by import By
55
from selenium.webdriver.common.keys import Keys
@@ -100,6 +100,16 @@ def focus_cell(self, index=0):
100100
self.to_command_mode()
101101
self.current_cell = cell
102102

103+
def find_and_replace(self, index=0, find_txt='', replace_txt=''):
104+
self.focus_cell(index)
105+
self.to_command_mode()
106+
self.body.send_keys('f')
107+
wait_for_selector(self.browser, "#find-and-replace", single=True)
108+
self.browser.find_element_by_id("findreplace_allcells_btn").click()
109+
self.browser.find_element_by_id("findreplace_find_inp").send_keys(find_txt)
110+
self.browser.find_element_by_id("findreplace_replace_inp").send_keys(replace_txt)
111+
self.browser.find_element_by_id("findreplace_replaceall_btn").click()
112+
103113
def convert_cell_type(self, index=0, cell_type="code"):
104114
# TODO add check to see if it is already present
105115
self.focus_cell(index)
@@ -258,3 +268,4 @@ def ctrl(browser, k):
258268
"""Send key combination Ctrl+(k)"""
259269
ActionChains(browser)\
260270
.key_down(Keys.CONTROL).send_keys(k).key_up(Keys.CONTROL).perform()
271+

0 commit comments

Comments
 (0)