<commit_before>//
//  TaskCellTests.swift
//  MovingHelper
//
//  Created by <NAME> on 7/12/15.
//  Copyright (c) 2015 Razeware. All rights reserved.
//

import UIKit
import XCTest
import MovingHelper

class TaskCellTests: XCTestCase {
  func testCheckingCheckboxMarksTaskDone() {
    let cell = TaskTableViewCell()
    
    //1
    let expectation = expectationWithDescription("Task updated")
    
    //2
    struct TestDelegate: TaskUpdatedDelegate {
      let testExpectation: XCTestExpectation
      let expectedDone: Bool
      
      init(updatedExpectation: XCTestExpectation,
        expectedDoneStateAfterToggle: Bool) {
          testExpectation = updatedExpectation
          expectedDone = expectedDoneStateAfterToggle
      }
      
      func taskUpdated(task: Task) {
        XCTAssertEqual(expectedDone, task.done, "Task done state did not match expected!")
        testExpectation.fulfill()
      }
    }
    
    //3
    let testTask = Task(aTitle: "TestTask", aDueDate: .OneMonthAfter)
    XCTAssertFalse(testTask.done, "Newly created task is already done!")
    cell.delegate = TestDelegate(updatedExpectation: expectation,
      expectedDoneStateAfterToggle: true)
    cell.configureForTask(testTask)
    
    //4
    XCTAssertFalse(cell.checkbox.isChecked, "Checkbox checked for not-done task!")
    
    //5
    cell.checkbox.sendActionsForControlEvents(.TouchUpInside)
    
    //6
    XCTAssertTrue(cell.checkbox.isChecked, "Checkbox not checked after tap!")
    waitForExpectationsWithTimeout(1, handler: nil)
  }
}<commit_msg>Update grabbing cell for test<commit_after>//
//  TaskCellTests.swift
//  MovingHelper
//
//  Created by <NAME> on 7/12/15.
//  Copyright (c) 2015 Razeware. All rights reserved.
//

import UIKit
import XCTest
import MovingHelper

class TaskCellTests: XCTestCase {
  func testCheckingCheckboxMarksTaskDone() {
    var testCell: TaskTableViewCell?
    let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
    if let navVC = mainStoryboard.instantiateInitialViewController() as? UINavigationController,
      listVC = navVC.topViewController as? MasterViewController {
        let tasks = TaskLoader.loadStockTasks()
        listVC.createdMovingTasks(tasks)
        testCell = listVC.tableView(listVC.tableView, cellForRowAtIndexPath: NSIndexPath(forRow: 0, inSection: 0)) as? TaskTableViewCell

        if let cell = testCell {
          //1
          let expectation = expectationWithDescription("Task updated")
          
          //2
          struct TestDelegate: TaskUpdatedDelegate {
            let testExpectation: XCTestExpectation
            let expectedDone: Bool
            
            init(updatedExpectation: XCTestExpectation,
              expectedDoneStateAfterToggle: Bool) {
                testExpectation = updatedExpectation
                expectedDone = expectedDoneStateAfterToggle
            }
            
            func taskUpdated(task: Task) {
              XCTAssertEqual(expectedDone, task.done, "Task done state did not match expected!")
              testExpectation.fulfill()
            }
          }
          
          //3
          let testTask = Task(aTitle: "TestTask", aDueDate: .OneMonthAfter)
          XCTAssertFalse(testTask.done, "Newly created task is already done!")
          cell.delegate = TestDelegate(updatedExpectation: expectation,
            expectedDoneStateAfterToggle: true)
          cell.configureForTask(testTask)
          
          //4
          XCTAssertFalse(cell.checkbox.isChecked, "Checkbox checked for not-done task!")
          
          //5
          cell.checkbox.sendActionsForControlEvents(.TouchUpInside)
          
          //6
          XCTAssertTrue(cell.checkbox.isChecked, "Checkbox not checked after tap!")
          waitForExpectationsWithTimeout(1, handler: nil)
        } else {
          XCTFail("Test cell was nil!")
        }
    } else {
      XCTFail("Could not get reference to list VC!")
    }
  }
}
{'fraction_non_alphanumeric': 0.08249243188698284, 'fraction_numerical': 0.008577194752774974, 'mean_word_length': 2.49647266313933, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5984872', 'n_tokens_mistral': 1132, 'n_tokens_neox': 1081, 'n_words': 258}