From 44dc158cbc82da1a1f6da71e65d76fed0c8a133b Mon Sep 17 00:00:00 2001 From: amelak9 Date: Mon, 26 Jul 2021 15:35:28 +0200 Subject: [PATCH] CATTY-377 Add new object choose image before title --- .../Continue&New/SceneTableViewController.m | 81 ++++++++++--------- .../Extensions/XCTestCaseExtension.swift | 14 ++-- src/CattyUITests/ProjectTVCTests.swift | 16 +++- 3 files changed, 65 insertions(+), 46 deletions(-) diff --git a/src/Catty/ViewController/Continue&New/SceneTableViewController.m b/src/Catty/ViewController/Continue&New/SceneTableViewController.m index 692d20c111..330167ed58 100644 --- a/src/Catty/ViewController/Continue&New/SceneTableViewController.m +++ b/src/Catty/ViewController/Continue&New/SceneTableViewController.m @@ -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] @@ -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]) { + 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]; @@ -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 diff --git a/src/CattyUITests/Extensions/XCTestCaseExtension.swift b/src/CattyUITests/Extensions/XCTestCaseExtension.swift index 7f11d23771..1fc8e66b97 100644 --- a/src/CattyUITests/Extensions/XCTestCaseExtension.swift +++ b/src/CattyUITests/Extensions/XCTestCaseExtension.swift @@ -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() + waitForElementToAppear(app.sheets.firstMatch).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])) } diff --git a/src/CattyUITests/ProjectTVCTests.swift b/src/CattyUITests/ProjectTVCTests.swift index b974ec1db9..ab2e377aad 100644 --- a/src/CattyUITests/ProjectTVCTests.swift +++ b/src/CattyUITests/ProjectTVCTests.swift @@ -54,10 +54,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.sheets.firstMatch).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) }