Skip to content

Commit

Permalink
Prevent blank project names
Browse files Browse the repository at this point in the history
Paired with @jonkirkman

Fixes #17
  • Loading branch information
eee-c committed Jul 2, 2013
1 parent 7befa1a commit f0da5a6
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 18 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions lib/full/copy_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
6 changes: 1 addition & 5 deletions lib/full/new_project_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 1 addition & 7 deletions lib/full/rename_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions lib/full/validate.dart
Original file line number Diff line number Diff line change
@@ -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;
}
}
1 change: 1 addition & 0 deletions lib/ice.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: ice_code_editor
version: 0.0.5
version: 0.0.6
description: Code Editor + Preview
authors:
- Chris Strom <[email protected]>
Expand Down
12 changes: 12 additions & 0 deletions test/full/copy_dialog_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
});

});
}
13 changes: 13 additions & 0 deletions test/full/new_project_dialog_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
12 changes: 12 additions & 0 deletions test/full/rename_dialog_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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: '☰');

Expand Down

0 comments on commit f0da5a6

Please sign in to comment.