diff --git a/README.md b/README.md index b4b4ebf..9592278 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ The example app contained in `example` is a simple Dart web server. From the `ex * [William Estoque](https://github.com/westoque) * [Daniel Gempesaw](https://github.com/gempesaw) * [Nik Graf](https://github.com/nikgraf) + * [Jon Kirkman](https://github.com/jonkirkman) * [Anita Kuno](https://github.com/anteaya) * [Morgan Nelson](https://github.com/korishev) * [Michael Risse](https://github.com/rissem) diff --git a/lib/full/copy_dialog.dart b/lib/full/copy_dialog.dart index e349c1a..16ed18c 100644 --- a/lib/full/copy_dialog.dart +++ b/lib/full/copy_dialog.dart @@ -31,11 +31,7 @@ class CopyDialog extends Dialog implements MenuAction { _copyProject() { var title = _field.value; - if (store.containsKey(title)) { - var message = "There is already a project with that name"; - Notify.alert(message, parent: parent); - return; - } + if (!new Validate(title, store, parent).isValid) return; store[title] = {'code': ice.content}; diff --git a/lib/full/new_project_dialog.dart b/lib/full/new_project_dialog.dart index 6378bc3..edcee44 100644 --- a/lib/full/new_project_dialog.dart +++ b/lib/full/new_project_dialog.dart @@ -35,11 +35,7 @@ class NewProjectDialog extends Dialog implements MenuAction { _create() { var title = _field.value; - if (store.containsKey(title)) { - var message = "There is already a project with that name"; - Notify.alert(message, parent: parent); - return; - } + if (!new Validate(title, store, parent).isValid) return; var template = _list.value, code = Templates.byTitle(template); diff --git a/lib/full/rename_dialog.dart b/lib/full/rename_dialog.dart index eb203b3..f626b30 100644 --- a/lib/full/rename_dialog.dart +++ b/lib/full/rename_dialog.dart @@ -28,13 +28,7 @@ class RenameDialog extends Dialog implements MenuAction { _renameProject() { var title = _field.value; - - if(store.containsKey(title)) { - var message = "There is already a project with that name"; - - Notify.alert(message, parent: parent); - return; - } + if (!new Validate(title, store, parent).isValid) return; var project = store.remove(_currentProjectTitle); store[title] = project; diff --git a/lib/full/validate.dart b/lib/full/validate.dart new file mode 100644 index 0000000..63021d7 --- /dev/null +++ b/lib/full/validate.dart @@ -0,0 +1,28 @@ +part of ice; + +class Validate { + String title; + + Element parent; + Editor ice; + Store store; + + // TODO: generalize so that these are not passed directly to Validate + Validate(this.title, this.store, this.parent); + + bool get isValid { + if (store.containsKey(title)) { + var message = "There is already a project with that name"; + Notify.alert(message, parent: parent); + return false; + } + + if (title.trim().isEmpty) { + var message = "The project name cannot be blank"; + Notify.alert(message, parent: parent); + return false; + } + + return true; + } +} diff --git a/lib/ice.dart b/lib/ice.dart index e1d9a07..3061c8d 100644 --- a/lib/ice.dart +++ b/lib/ice.dart @@ -16,6 +16,7 @@ part 'full.dart'; part 'full/default_project.dart'; part 'full/templates.dart'; part 'full/notify.dart'; +part 'full/validate.dart'; part 'full/menu_item.dart'; part 'full/menu_action.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index 958b5ec..f2d7e85 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: ice_code_editor -version: 0.0.5 +version: 0.0.6 description: Code Editor + Preview authors: - Chris Strom diff --git a/test/full/copy_dialog_test.dart b/test/full/copy_dialog_test.dart index 30f2248..d7d9ad3 100644 --- a/test/full/copy_dialog_test.dart +++ b/test/full/copy_dialog_test.dart @@ -197,5 +197,17 @@ copy_dialog_tests() { ); }); + test("cannot have a blank name", () { + helpers.click('button', text: '☰'); + helpers.click('li', text: 'Make a Copy'); + helpers.typeIn(' '); + helpers.click('button', text: 'Save'); + + expect( + query('#alert').text, + 'The project name cannot be blank' + ); + }); + }); } diff --git a/test/full/new_project_dialog_test.dart b/test/full/new_project_dialog_test.dart index 3d5de6c..77cba30 100644 --- a/test/full/new_project_dialog_test.dart +++ b/test/full/new_project_dialog_test.dart @@ -72,6 +72,19 @@ new_project_dialog_tests(){ text, equals("There is already a project with that name")); }); + test("cannot have a blank name", () { + helpers.click('button', text: '☰'); + helpers.click('li', text: 'New'); + helpers.typeIn(' '); + + helpers.click('button', text: 'Save'); + + expect( + query('#alert').text, + 'The project name cannot be blank' + ); + }); + test("can be named", (){ helpers.click('button', text: '☰'); helpers.click('li', text: 'New'); diff --git a/test/full/rename_dialog_test.dart b/test/full/rename_dialog_test.dart index f98d1b9..2c39951 100644 --- a/test/full/rename_dialog_test.dart +++ b/test/full/rename_dialog_test.dart @@ -104,6 +104,18 @@ rename_dialog_tests() { ); }); + test("cannot have a blank name", () { + helpers.click('button', text: '☰'); + helpers.click('li', text: 'Rename'); + helpers.typeIn(' '); + helpers.click('button', text: 'Rename'); + + expect( + query('#alert').text, + equals("The project name cannot be blank") + ); + }); + test("hitting the enter key renames", (){ helpers.click('button', text: '☰');