Skip to content

Commit

Permalink
CATTY-377 Add new object choose image before title
Browse files Browse the repository at this point in the history
  • Loading branch information
amelak9 authored and lucatp committed Aug 17, 2023
1 parent e488257 commit 44dc158
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 46 deletions.
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]) {
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
14 changes: 9 additions & 5 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()
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]))
}

Expand Down
16 changes: 13 additions & 3 deletions src/CattyUITests/ProjectTVCTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 44dc158

Please sign in to comment.