<commit_before>//
//  ViewAPITests.swift
//  ELHybridWeb
//
//  Created by <NAME> on 8/11/15.
//  Copyright (c) 2015 WalmartLabs. All rights reserved.
//

import UIKit
import XCTest
@testable import ELHybridWeb
import JavaScriptCore

class ViewAPITests: XCTestCase {
    
    func testParentViewControllerChange() {
        let webController = WebViewController()
        let api = HybridAPI(parentViewController: webController)
        let newWebViewController = WebViewController()
        api.parentViewController = newWebViewController
        
        XCTAssertNotNil(api.view.parentViewController)
        XCTAssertEqual(api.view.parentViewController!, newWebViewController)
    }
    
    func testExportName() {
        let api = HybridAPI(parentViewController: WebViewController())
        let context = JSContext(virtualMachine: JSVirtualMachine())!
        context.setObject(api, forKeyedSubscript: HybridAPI.exportName as NSString)
        
        let viewObject: Any = context.evaluateScript("NativeBridge.view").toObject()
        XCTAssert(viewObject is ViewAPI)
    }
    
    func testShow() {
        let webController = WebViewController()
        let api = HybridAPI(parentViewController: webController)
        let context = JSContext(virtualMachine: JSVirtualMachine())!
        context.setObject(api, forKeyedSubscript: HybridAPI.exportName as NSString)
        
        let showCompleteExpectation = expectation(description: "web view show completion callback ran")
        api.view.onShowCallback = {
            showCompleteExpectation.fulfill()
        }
        
        webController.webView.isHidden = true
        api.view.show()
        
        waitForExpectations(timeout: 3.0) { error in
            XCTAssertFalse(webController.webView.isHidden)
        }
        
    }
}<commit_msg>add unit tests to verify view API is exported to JS properly<commit_after>//
//  ViewAPITests.swift
//  ELHybridWeb
//
//  Created by <NAME> on 8/11/15.
//  Copyright (c) 2015 WalmartLabs. All rights reserved.
//

import UIKit
import XCTest
@testable import ELHybridWeb
import JavaScriptCore

class ViewAPITests: XCTestCase {
    func testParentViewControllerChange() {
        let webController = WebViewController()
        let api = HybridAPI(parentViewController: webController)
        let newWebViewController = WebViewController()
        api.parentViewController = newWebViewController
        
        XCTAssertNotNil(api.view.parentViewController)
        XCTAssertEqual(api.view.parentViewController!, newWebViewController)
    }
    
    func testExportName() {
        let api = HybridAPI(parentViewController: WebViewController())
        let context = JSContext(virtualMachine: JSVirtualMachine())!
        context.setObject(api, forKeyedSubscript: HybridAPI.exportName as NSString)
        
        let viewObject: Any = context.evaluateScript("NativeBridge.view").toObject()
        XCTAssert(viewObject is ViewAPI)
    }
    
    func testShow() {
        let webController = WebViewController()
        let api = HybridAPI(parentViewController: webController)
        let context = JSContext(virtualMachine: JSVirtualMachine())!
        context.setObject(api, forKeyedSubscript: HybridAPI.exportName as NSString)
        
        let showCompleteExpectation = expectation(description: "web view show completion callback ran")
        api.view.onShowCallback = {
            showCompleteExpectation.fulfill()
        }
        
        webController.webView.isHidden = true
        api.view.show()
        
        waitForExpectations(timeout: 3.0) { error in
            XCTAssertFalse(webController.webView.isHidden)
        }
    }
    
    func testSetOnAppearExport() {
        let webController = WebViewController()
        webController.addBridgeAPIObject()
        
        let result = webController.bridgeContext.evaluateScript("NativeBridge.view.setOnAppear")!
        XCTAssert(result.isObject)
        XCTAssert(result.toObject() is NSDictionary)
    }
    
    func testSetOnDisappearExport() {
        let webController = WebViewController()
        webController.addBridgeAPIObject()
        
        let result = webController.bridgeContext.evaluateScript("NativeBridge.view.setOnDisappear")!
        XCTAssert(result.isObject)
        XCTAssert(result.toObject() is NSDictionary)
    }
}
{'fraction_non_alphanumeric': 0.0810126582278481, 'fraction_numerical': 0.005063291139240506, 'mean_word_length': 2.887298747763864, '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': '4535253', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1134, 'n_words': 243}