Skip to content

Frontend js unit tests #676 #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
dc9c4d6
Frontend js unit tests #676
penelopez Jun 22, 2016
8ab2bad
Fix any issues
penelopez Jun 27, 2016
a9fdec2
Updated script-Added new steps
penelopez Jun 28, 2016
8e68b45
Added new script for editor test cases
penelopez Jun 30, 2016
e9560a4
Added new steps
penelopez Jun 30, 2016
c36d6bf
Added news steps
penelopez Jul 1, 2016
a331a1f
Adding the correct file
penelopez Jul 4, 2016
b04cdd2
Removed folder sketches_counters which contained tests that didn't w…
Jul 29, 2016
ca761f9
Corrected typo in utils.py file.
Jul 29, 2016
5d85a87
Added test for filters and counters in user's homepage.
Jul 29, 2016
f40629d
Merge branch 'master' into frontend_js_unit_tests
Jul 29, 2016
fdd54d9
Check that sketch name is auto-generated as: Untitled Sketch CURRENT_…
Jul 29, 2016
04644d4
Check that when user creates a sketch he is redirected into the editor.
Jul 29, 2016
458eb85
Added missing import.
Jul 29, 2016
1a058b5
Check that Create btn is disabled when you create a sketch without a …
Jul 29, 2016
2cca710
Check that when user creates sketch with invalid name, error message …
Aug 2, 2016
d84b4da
Added short description tests inside Create Sketch modal.
Aug 9, 2016
b3d143c
Added test for "Cloned from" info that appear in homepage.
Aug 9, 2016
5f3db1d
Test that Create button works.
Aug 11, 2016
e2491ec
Test that when sketch short description is modified, modified msg app…
Aug 11, 2016
8740785
Test Share modal.
Aug 11, 2016
0586f9d
Tests clone button.
Aug 11, 2016
0fa143b
Updated utils functions change_name and change_name_editor.
Aug 11, 2016
b881a82
Added test for sketch rename inside editor.
Aug 11, 2016
211cb29
Added test that short_description is updated inside editor.
Aug 11, 2016
9fec384
Added test for file rename in editor.
Aug 11, 2016
b5c8aaa
Updated delete file function inside editor.
Aug 11, 2016
3f32f26
Reformatted code of test_sketch.py
Aug 11, 2016
45e3c43
Added function to change project privacy in editor.
Aug 11, 2016
97eb8e0
Added test that changes privacy in editor.
Aug 11, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions codebender_testing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from codebender_testing.config import get_path
from codebender_testing.config import jsondump
from codebender_testing.disqus import DisqusWrapper

from selenium.webdriver.common.action_chains import ActionChains

# Time to wait until we give up on a DOM property becoming available.
DOM_PROPERTY_DEFINED_TIMEOUT = 30
Expand Down Expand Up @@ -916,11 +916,25 @@ def change_privacy(self, privacy):
privateRadioButton = self.get_element(By.CSS_SELECTOR,'#create-sketch-modal-type-controls [value="private"]')
privateRadioButton.click()

def change_privacy_editor(self, privacy):
driver=self.driver
if privacy == 'private':
privacy = self.get_element(By.CSS_SELECTOR,'#editor_heading_privacy_icon .cb-icon-globe-inv')
actions = ActionChains(driver)
actions.move_to_element(privacy)
actions.double_click(privacy)
actions.perform()
else:
privacy = self.get_element(By.CSS_SELECTOR,'#editor_heading_privacy_icon .icon-lock')
actions = ActionChains(driver)
actions.move_to_element(privacy)
actions.double_click(privacy)
actions.perform()

def change_name(self, name):
nameField = self.get_element(By.CSS_SELECTOR,'#create-sketch-modal .modal-body [id="create-sketch-name"')
nameField.clear()
nameField.send_keys(name)
nameField.send_keys(Keys.ENTER)

def change_name_editor(self, name):
sketchHeading = self.get_element(By.ID, 'editor_heading_project_name')
Expand All @@ -942,10 +956,9 @@ def change_name_editor(self, name):
)

def change_short_description(self, description):
nameField = self.get_element(By.CSS_SELECTOR,'#create-sketch-modal-sort-description')
nameField = self.get_element(By.CSS_SELECTOR,'#create-sketch-modal-short-description')
nameField.clear()
nameField.send_keys(description)
nameField.send_keys(Keys.ENTER)

def change_short_description_editor(self, description):
editDescription = self.get_element(By.CSS_SELECTOR,'.short-description-edit')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
from codebender_testing.utils import SeleniumTestCase
from selenium import webdriver
from selenium.webdriver.common.by import By
from codebender_testing import config
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
import pytest


class TestSketchesCounters(SeleniumTestCase):

@pytest.fixture(scope="class", autouse=True)
def open_user_home(self, tester_login):
"""Makes sure we are logged in and are at the user home page
performing any of these tests."""
pass

def test_sketches_counters(self):
driver = self.driver
# Check that the counters: Public sketches (blue) and Private sketches
# (purple) have the correct value (number of sketches of each category).

assert self.get_element(By.ID, "private-sketches-counter").text=="0"
assert self.get_element(By.ID,"public-sketches-counter").text=="0"

# Check that the counter for private projects also appears at the Badges
# section and has the correct value.
privateProjects = self.get_element(By.ID,
"available-private-sketches-counter").text
assert self.get_element(By.ID,
"privateProjectAvailableNumber").text == \
privateProjects.split('/')[0]

# Check that the counter for available private sketches also appears at
# the upload sketch modal (ino, zip, multiple zip) and at the create and
# edit sketch modal.

# Upload .ino.
self.get_element(By.ID, "sketch-upload-button").click()
self.get_element(By.ID, "upload-sketch-ino").click()
assert self.get_element(By.ID,
"upload-sketch-modal-available-private-sketches").text == \
privateProjects
close_btn = self.get_element(By.CSS_SELECTOR,
"#home-upload-sketch-modal .btn-danger")
close_btn.click()
# Wait for the modal to close.
WebDriverWait(self.driver, 30).until(
expected_conditions.invisibility_of_element_located(
(By.CSS_SELECTOR, ".modal-backdrop fade")
)
)

# Upload .zip.
self.get_element(By.ID, "sketch-upload-button").click()
self.get_element(By.ID, "upload-sketch-zip").click()
assert self.get_element(By.ID,
"upload-sketch-modal-available-private-sketches").text == \
privateProjects
close_btn = self.get_element(By.CSS_SELECTOR,
"#home-upload-sketch-modal .btn-danger")
close_btn.click()
# Wait for the modal to close.
WebDriverWait(self.driver, 30).until(
expected_conditions.invisibility_of_element_located(
(By.CSS_SELECTOR, ".modal-backdrop fade")
)
)

# Upload your sketch folder [.zip].
self.get_element(By.ID, "sketch-upload-button").click()
self.get_element(By.ID, "upload-sketch-folder-zip").click()
assert self.get_element(By.ID,
"upload-sketch-modal-available-private-sketches").text == \
privateProjects
close_btn = self.get_element(By.CSS_SELECTOR,
"#home-upload-sketch-modal .btn-danger")
close_btn.click()
# Wait for the modal to close.
WebDriverWait(self.driver, 30).until(
expected_conditions.invisibility_of_element_located(
(By.CSS_SELECTOR, ".modal-backdrop fade")
)
)

# Create sketch modal.
self.get_element(By.ID, "create_sketch_btn").click()
assert self.get_element(By.ID,
"create-sketch-modal-available-private-sketches").text == \
privateProjects
close_btn = self.get_element(By.CSS_SELECTOR,
"#create-sketch-modal .btn-danger")
close_btn.click()
WebDriverWait(self.driver, 30).until(
expected_conditions.invisibility_of_element_located(
(By.CSS_SELECTOR, ".modal-backdrop fade")
)
)

# Create one public project.
self.create_sketch('public' , 'publicSketch1', 'short description')
self.open("/")

# Check that public sketch number was increased from 0 to 1.
assert self.get_element(By.ID, "public-sketches-counter").text=="1"

# Create one private project.
self.create_sketch('private' , 'privateSketch1', 'short description')
self.open("/")

# Check that private sketch number was increased from 0 to 1.
assert self.get_element(By.ID, "private-sketches-counter").text=="1"

# Check that the counter for available private projects that appears at
# the Badges section has the correct value.

private_sketches = self.get_element(By.ID,
"available-private-sketches-counter").text
assert self.get_element(By.ID,
"privateProjectAvailableNumber").text == \
private_sketches.split('/')[0]

# Check that the number of private and public projects is updated
# each time that you make a change (change a sketch from public
# to private and vice versa).
editInfo = driver.find_element_by_css_selector(
'#project_list li[data-name="publicSketch1"] \
.sketch-block-container .sketch-block-header \
.sketch-block-edit-info')
hoverEditInfo = ActionChains(driver).move_to_element(editInfo).perform()
editInfoClick = driver.find_element_by_css_selector(
'#project_list li[data-name="publicSketch1"] \
.sketch-block-container .sketch-block-header \
.sketch-block-edit-info a')
editInfoClick.click()
# Change project from public to private.
privateRadioButton = self.get_element(By.CSS_SELECTOR,
'#edit-sketch-modal-type-controls [value="private"]')
privateRadioButton.click()
# Click the Save button.
save_btn = self.get_element(By.CSS_SELECTOR,
"#edit-sketch-modal .btn-success")
save_btn.click()
# Wait for the modal to close.
WebDriverWait(self.driver, 30).until(
expected_conditions.invisibility_of_element_located(
(By.CSS_SELECTOR, "#edit-sketch-modal")
)
)
# Check public and private projects counters.
assert self.get_element(By.ID, "private-sketches-counter").text=="2"
assert self.get_element(By.ID, "public-sketches-counter").text=="0"

editInfo = driver.find_element_by_css_selector(
'#project_list li[data-name="publicSketch1"] \
.sketch-block-container .sketch-block-header \
.sketch-block-edit-info')
hoverEditInfo = ActionChains(driver).move_to_element(editInfo).perform()
editInfoClick = driver.find_element_by_css_selector(
'#project_list li[data-name="publicSketch1"] \
.sketch-block-container .sketch-block-header \
.sketch-block-edit-info a')
editInfoClick.click()
# Change project from private to public.
publicRadioButton = self.get_element(By.CSS_SELECTOR,
'#edit-sketch-modal-type-controls [value="public"]')
publicRadioButton.click()
# Click the Save button.
save_btn = self.get_element(By.CSS_SELECTOR,
"#edit-sketch-modal .btn-success")
save_btn.click()
# Wait for the modal to close.
WebDriverWait(self.driver, 30).until(
expected_conditions.invisibility_of_element_located(
(By.CSS_SELECTOR, "#edit-sketch-modal")
)
)
# Check public and private projects counters.
assert self.get_element(By.ID, "private-sketches-counter").text=="1"
assert self.get_element(By.ID, "public-sketches-counter").text=="1"


def test_sketch_filters(self):
# Check that All, Public and Private buttons work, by clicking on each
# of them and verifying hat the correct number of sketches appears.

# Check "All sketches button".
self.get_element(By.CSS_SELECTOR,
'#filter-options label[data-filter="all"]').click()
sketches = self.find_all('#project_list >li')
assert len(sketches) == 2

# Check "Public button".
self.get_element(By.CSS_SELECTOR,
'#filter-options label[data-filter="public"]').click()
sketches = self.find_all('#project_list >li .cb-icon-globe-inv')
assert len(sketches) == 1

# Check "Private button".
self.get_element(By.CSS_SELECTOR,
'#filter-options label[data-filter="private"]').click()
sketches = self.find_all('#project_list >li .fa-lock')
assert len(sketches) == 1

class TestDeleteAllSketches(SeleniumTestCase):

def test_delete(self, tester_login):
try:
sketches = self.find_all('#project_list > li \
.sketch-block-title > a')
projects = []
for sketch in sketches:
projects.append(sketch.text)
for project in projects:
self.delete_project(project)
except:
print 'No sketches found'

self.logout()
Loading