Skip to content
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

CATTY-377 Add new object choose image before title #1682

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
81 changes: 43 additions & 38 deletions src/Catty/ViewController/Continue&New/SceneTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,41 +101,8 @@ - (void)addObjectAction:(id)sender
{
[self.tableView setEditing:false animated:YES];

[[[[[[[AlertControllerBuilder textFieldAlertWithTitle:kLocalizedAddObject message:[NSString stringWithFormat:@"%@:", kLocalizedObjectName]]
placeholder:kLocalizedEnterYourObjectNameHere]
addCancelActionWithTitle:kLocalizedCancel handler:^{
[self cancelAddingObjectFromScriptEditor];
}]
addDefaultActionWithTitle:kLocalizedOK handler:^(NSString *name) {
[self addObjectActionWithName:name];
}]
valueValidator:^InputValidationResult *(NSString *name) {
InputValidationResult *result = [Util validationResultWithName:name
minLength:kMinNumOfObjectNameCharacters
maxlength:kMaxNumOfObjectNameCharacters];
if (!result.valid) {
return result;
}
// Alert for Objects with same name
if ([[self.scene allObjectNames] containsObject:name]) {
return [InputValidationResult invalidInputWithLocalizedMessage:kLocalizedObjectNameAlreadyExistsDescription];
}
return [InputValidationResult validInput];
}] build]
showWithController:self];
}

-(void)cancelAddingObjectFromScriptEditor
{
if (self.afterSafeBlock) {
self.afterSafeBlock(nil);
}
}

- (void)addObjectActionWithName:(NSString*)objectName
{
[self showLoadingView];
[self.scene addObjectWithName:[Util uniqueName:objectName existingNames:[self.scene allObjectNames]]];
[self.scene addObjectWithName:[Util uniqueName:kLocalizedLook existingNames:[self.scene allObjectNames]]];
NSInteger numberOfRowsInLastSection = [self tableView:self.tableView numberOfRowsInSection:kObjectSectionIndex];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:(numberOfRowsInLastSection - 1) inSection:kObjectSectionIndex];
[self.tableView insertRowsAtIndexPaths:@[indexPath]
Expand All @@ -147,12 +114,44 @@ - (void)addObjectActionWithName:(NSString*)objectName
ltvc.showAddLookActionSheetAtStartForScriptEditor = NO;
ltvc.afterSafeBlock = ^(Look* look) {
[self.navigationController popViewControllerAnimated:YES];
if (look) {
NSString *initialText = look.name;
[[[[[[[[AlertControllerBuilder textFieldAlertWithTitle:kLocalizedAddObject message:[NSString stringWithFormat:@"%@:", kLocalizedObjectName]]
placeholder:kLocalizedEnterYourObjectNameHere]
initialText:initialText]
addCancelActionWithTitle:kLocalizedCancel handler:^{
NSUInteger index = kBackgroundObjectIndex + indexPath.section + indexPath.row;
SpriteObject *object = (SpriteObject*)[self.scene.objects objectAtIndex:index];
[self.scene removeObject:object];
[self.scene.project saveToDiskWithNotification:NO];
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:((indexPath.row != 0) ? UITableViewRowAnimationTop : UITableViewRowAnimationFade)];
[self cancelAddingObjectFromScriptEditor];
}]
addDefaultActionWithTitle:kLocalizedOK handler:^(NSString *name) {
[self renameObjectActionToName:name spriteObject:(SpriteObject*)[self.scene.objects objectAtIndex:(kBackgroundObjectIndex + indexPath.section + indexPath.row)]];
}]
valueValidator:^InputValidationResult *(NSString *name) {
InputValidationResult *result = [Util validationResultWithName:name
minLength:kMinNumOfObjectNameCharacters
maxlength:kMaxNumOfObjectNameCharacters];
if (!result.valid) {
return result;
}
// Alert for Objects with same name
if ([[self.scene allObjectNames] containsObject:name]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to work, when trying to save an image with the same name, it just gets assigned a unique name (e.g. "Look (1)")

return [InputValidationResult invalidInputWithLocalizedMessage:kLocalizedObjectNameAlreadyExistsDescription];
}
return [InputValidationResult validInput];
}] build]
showWithController:self];
}
if (!look) {
NSUInteger index = (kBackgroundObjects + indexPath.row);
NSUInteger index = kBackgroundObjectIndex + indexPath.row + 1;
SpriteObject *object = (SpriteObject*)[self.scene.objects objectAtIndex:index];
[self.scene removeObject:object];
[self.scene.project saveToDiskWithNotification:NO];
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:((indexPath.row != 0) ? UITableViewRowAnimationTop : UITableViewRowAnimationFade)];
[self cancelAddingObjectFromScriptEditor];
}
if (self.afterSafeBlock && look ) {
NSInteger numberOfRowsInLastSection = [self tableView:self.tableView numberOfRowsInSection:kObjectSectionIndex];
Expand All @@ -162,10 +161,16 @@ - (void)addObjectActionWithName:(NSString*)objectName
self.afterSafeBlock(nil);
}
[self showPlaceHolder:!(BOOL)[self.scene numberOfNormalObjects]];
[self hideLoadingView];
[self showPlaceHolder:!(BOOL)[self.scene numberOfNormalObjects]];
};
[self.navigationController pushViewController:ltvc animated:NO];
[self showPlaceHolder:!(BOOL)[self.scene numberOfNormalObjects]];
[self hideLoadingView];
[self.navigationController pushViewController:ltvc animated:NO];}

-(void)cancelAddingObjectFromScriptEditor
{
if (self.afterSafeBlock) {
self.afterSafeBlock(nil);
}
}

- (void)renameProjectActionForProjectWithName:(NSString*)newProjectName
Expand Down
12 changes: 8 additions & 4 deletions src/CattyUITests/Extensions/XCTestCaseExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,21 @@ extension XCTestCase {
func addObjectAndDrawNewImage(name: String, in app: XCUIApplication) {
app.toolbars.buttons[kLocalizedUserListAdd].tap()

let alert = waitForElementToAppear(app.alerts[kLocalizedAddObject])
alert.textFields[kLocalizedEnterYourObjectNameHere].typeText(name)
alert.buttons[kLocalizedOK].tap()

waitForElementToAppear(app.buttons[kLocalizedDrawNewImage]).tap()
XCTAssertNotNil(waitForElementToAppear(app.navigationBars[kLocalizedPaintPocketPaint]))

app.tap()
app.navigationBars.buttons[kLocalizedBack].tap()

waitForElementToAppear(app.buttons[kLocalizedSaveChanges]).tap()
let alert = waitForElementToAppear(app.alerts[kLocalizedAddObject])
alert.textFields[kLocalizedEnterYourObjectNameHere].tap()

let stringValue = alert.textFields[kLocalizedEnterYourObjectNameHere].value as? String
let deleteString = String(repeating: XCUIKeyboardKey.delete.rawValue, count: stringValue!.count)
alert.textFields[kLocalizedEnterYourObjectNameHere].typeText(deleteString)
alert.textFields[kLocalizedEnterYourObjectNameHere].typeText(name)
alert.buttons[kLocalizedOK].tap()
XCTAssertNotNil(waitForElementToAppear(app.navigationBars.buttons[kLocalizedPocketCode]))
}

Expand Down
17 changes: 13 additions & 4 deletions src/CattyUITests/ProjectTVCTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class ProjectTVCTests: XCTestCase {
createProject(name: projectName, in: app)
XCTAssertNotNil(waitForElementToAppear(app.navigationBars[projectName]))
XCTAssertEqual(1, app.tables.cells.count)

addObjectAndDrawNewImage(name: objectName, in: app)
XCTAssertEqual(2, app.tables.cells.count)
}
Expand All @@ -54,10 +53,20 @@ class ProjectTVCTests: XCTestCase {
app.alerts[kLocalizedNewProject].buttons[kLocalizedOK].tap()
XCTAssertNotNil(waitForElementToAppear(app.navigationBars[projectName]))

//Add new Object
//Add new Object
app.toolbars.buttons[kLocalizedUserListAdd].tap()
app.alerts[kLocalizedAddObject].textFields[kLocalizedEnterYourObjectNameHere].typeText(objectName)
app.alerts[kLocalizedAddObject].buttons[kLocalizedOK].tap()

waitForElementToAppear(app.buttons[kLocalizedDrawNewImage]).tap()
XCTAssertNotNil(waitForElementToAppear(app.navigationBars[kLocalizedPaintPocketPaint]))

app.tap()
app.navigationBars.buttons[kLocalizedBack].tap()

waitForElementToAppear(app.buttons[kLocalizedSaveChanges]).tap()
let alert = waitForElementToAppear(app.alerts[kLocalizedAddObject])
alert.textFields[kLocalizedEnterYourObjectNameHere].tap()
alert.textFields[kLocalizedEnterYourObjectNameHere].typeText(objectName)
alert.buttons[kLocalizedOK].tap()

XCTAssert(waitForElementToAppear(app.alerts[kLocalizedPocketCode]).exists)
}
Expand Down