Skip to content

Commit

Permalink
fix: added input control for special characters + test (#970)
Browse files Browse the repository at this point in the history
* added input control for special characters + test

* refactored test

* syntax fix
  • Loading branch information
MMFernando authored Jun 20, 2019
1 parent 877d715 commit d756e1f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
17 changes: 11 additions & 6 deletions portal/static/portal/js/join_create_game_toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ program; modified versions of the program must be marked as such and not
identified as the original program.
*/

$(document).ready(function() {
$(document).ready(function () {
var game_name_input = $('#id_name');
var create_game_form = $('#create-game-form');
var join_game_section = $('#join_game');
Expand All @@ -45,24 +45,28 @@ $(document).ready(function() {
var create_new_game_button = $('#create_new_game_button');
var back_button = $('#back_button');

if(game_name_input.val()) {
if (game_name_input.val()) {
showCreateGameForm();
game_name_input.val("");
showInputError("Sorry, a game with this name already exists...");
}

create_new_game_button.click(function() {
create_new_game_button.click(function () {
showCreateGameForm();
});

back_button.click(function() {
back_button.click(function () {
showJoinGameForm();
});

create_game_button.click(function() {
if(!game_name_input.val() || game_name_input.val() === "") {
create_game_button.click(function () {
if (!game_name_input.val() || game_name_input.val() === "") {
showInputError("Give your new game a name...");
}
var exp = /^[\w-]+$/;
if (!exp.test(game_name_input.val())) {
showInputError("Name cannot contain special characters.");
}
else {
create_game_form.submit();
}
Expand All @@ -84,6 +88,7 @@ $(document).ready(function() {
}

function showInputError(error_message) {
game_name_input.val("");
game_name_input.attr("placeholder", error_message);
game_name_input.addClass('input-invalid');
}
Expand Down
10 changes: 9 additions & 1 deletion portal/tests/test_preview_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def test_preview_user_can_create_game(self):

self.assertIn("/aimmo/play/1/", self.selenium.driver.current_url)

def test_preview_user_cannot_create_empty_game(self):
def test_preview_user_cannot_create_invalid_game_name(self):
email, password = signup_teacher_directly_as_preview_user()
create_organisation_directly(email, True)
_, _, access_code = create_class_directly(email)
Expand All @@ -170,6 +170,14 @@ def test_preview_user_cannot_create_empty_game(self):
page.get_input_game_name_placeholder(), "Give your new game a name..."
)

page.input_new_game_name("it's an invalid name")
page.click_create_game_button()

self.assertEqual(
page.get_input_game_name_placeholder(),
"Name cannot contain special characters.",
)

def test_preview_user_cannot_create_duplicate_game(self):
email, password = signup_teacher_directly_as_preview_user()
create_organisation_directly(email, True)
Expand Down

0 comments on commit d756e1f

Please sign in to comment.