Skip to content

Commit

Permalink
Recipe testing
Browse files Browse the repository at this point in the history
  • Loading branch information
cabmatthew committed Dec 12, 2024
1 parent 7a751db commit 670fa89
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 40 deletions.
Binary file not shown.
2 changes: 1 addition & 1 deletion SwiftFood/Views/RecipeCreate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct RecipeCreate: View {
ScrollView {
TextEditor(text: $instructions)
.accessibilityIdentifier("CreateRecipeInstructions")
.frame(height: 150) // Fixed height
.frame(height: 150)
.cornerRadius(8)
.overlay(RoundedRectangle(cornerRadius: 8).stroke(Color.gray))
}
Expand Down
4 changes: 4 additions & 0 deletions SwiftFood/Views/RecipeDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ struct RecipeDetail: View {
Text("Time required: \(String(format: "%.1f", recipe.time_required)) hours")
Text("Serving count: \(recipe.servings_amount) servings")

Text("Ingredients:")
.font(.title)
.padding()

Text("Instructions:")
.font(.title)
.padding()
Expand Down
2 changes: 1 addition & 1 deletion SwiftFood/Views/RecipeList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct RecipeList: View {

}
.cornerRadius(20)
NavigationLink("Create new recipe") {
NavigationLink("Create New Recipe") {
RecipeCreate()
}
.accessibilityIdentifier("ToRecipeCreate")
Expand Down
108 changes: 70 additions & 38 deletions SwiftFoodUITests/SwiftFoodUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@
import XCTest

final class SwiftFoodUITests: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.

// In UI tests it is usually best to stop immediately when a failure occurs.
continueAfterFailure = false

// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

@MainActor
func testExample() throws {
// UI tests must launch the application that they test.
let app = XCUIApplication()
app.launch()

// Use XCTAssert and related functions to verify your tests produce the correct results.
}

@MainActor
func testLaunchPerformance() throws {
if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) {
Expand All @@ -43,35 +43,67 @@ final class SwiftFoodUITests: XCTestCase {

// My tests
@MainActor
func testAddItem() throws {
let app = XCUIApplication()
app.launch()

// For now, launch goes straight to my ingredient list.
// Might have to navigate to this screen using button presses in future.
let toIngredientsButton = app.buttons["ToIngredients"]
toIngredientsButton.tap()

// Access fields using accessibility identifiers, tap -> type
let ingredientTitleField = app.textFields["Title"]
ingredientTitleField.tap()
ingredientTitleField.typeText("Flour")

let amountField = app.textFields["Amount"]
amountField.tap()
amountField.typeText("2")

let unitField = app.textFields["Unit"]
unitField.tap()
unitField.typeText("Cups")

// Access button w/ accessibility identifier
// Assert the button exists
let addButton = app.buttons["AddButton"]
XCTAssertTrue(addButton.exists, "The 'Add Ingredient' button should exist.")
addButton.tap()

// Verify the new item is displayed
XCTAssertTrue(app.staticTexts["Flour"].exists, "The new item should be displayed in the list.")
}
func testAddItem() throws {
let app = XCUIApplication()
app.launch()

// For now, launch goes straight to my ingredient list.
// Might have to navigate to this screen using button presses in future.
// update: navigation
let toIngredientsButton = app.buttons["ToIngredients"]
toIngredientsButton.tap()

// Access fields using accessibility identifiers, tap -> type
let ingredientTitleField = app.textFields["Title"]
ingredientTitleField.tap()
ingredientTitleField.typeText("Flour")

let amountField = app.textFields["Amount"]
amountField.tap()
amountField.typeText("2")

let unitField = app.textFields["Unit"]
unitField.tap()
unitField.typeText("Cups")

// Access button w/ accessibility identifier
let addButton = app.buttons["AddButton"]
addButton.tap()

// Verify the new item is displayed
XCTAssertTrue(app.staticTexts["Flour"].exists, "Ingredient not added.")
}

@MainActor
func testAddRecipe() throws {
let app = XCUIApplication()
app.launch()

// Navigate to create new recipes
app.buttons["ToRecipes"].tap()
app.buttons["ToRecipeCreate"].tap()

// Fill in fields
let recipeTitleField = app.textFields["CreateRecipeTitle"]
recipeTitleField.tap()
recipeTitleField.typeText("Test Recipe")

let recipeTimeRequiredField = app.textFields["CreateRecipeTimeRequired"]
recipeTimeRequiredField.tap()
recipeTimeRequiredField.typeText(".7")

let recipeServingsField = app.textFields["CreateRecipeServingsAmount"]
recipeServingsField.tap()
recipeServingsField.typeText("4")

let recipeInstructions = app.textViews["CreateRecipeInstructions"]
recipeInstructions.tap()
recipeInstructions.typeText("These are test instructions.")

let recipeAddButton = app.buttons["AddRecipeButton"]
recipeAddButton.tap()

// Verify recipe was added
XCTAssertTrue(app.staticTexts["Test Recipe"].exists, "Recipe not added")
}
}

0 comments on commit 670fa89

Please sign in to comment.