<commit_before>
import WebKit
import XCTest

class WMFArticleJSTests: XCTestCase, WKScriptMessageHandler {
    
    var session: SessionSingleton?
    var webVC: WebViewController?
    var obamaURL: URL?
    var obamaArticle: MWKArticle?

    var firstSectionAppearedMessageReceivedExpectation: XCTestExpectation?
    var startTimeMessageReceivedExpectation: XCTestExpectation?

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

        session = SessionSingleton.init(dataStore: MWKDataStore.temporary())
        webVC = WebViewController.wmf_initialViewControllerFromClassStoryboard()
        
        guard
            let newObamaURL = NSURL.wmf_URL(withDomain: "wikipedia.org", language: "en", title: "Barack Obama", fragment: nil),
            let dataStore = session?.dataStore
        else {
            assertionFailure("Expected Obama article and data store")
            return
        }
        obamaURL = newObamaURL
        obamaArticle = article(withMobileViewJSONFixture: "Obama", with: newObamaURL, dataStore: dataStore)
        obamaArticle?.save()
        
        startTimeMessageReceivedExpectation = nil
        firstSectionAppearedMessageReceivedExpectation = nil
    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }

    let jsTestingMessageHandlerString = "jsTesting"
    let startTimeMessageString = "startTime"
    let firstSectionAppearedMessageString = "firstSectionAppeared"
    
    func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
        // print("\n \n \n message body : \(message.body) \n \n \n ")
        guard
            let messageString = message.body as? String
        else {
            assertionFailure("Unhandled message type")
            return
        }
        switch messageString {
        case startTimeMessageString:
            startTimeMessageReceivedExpectation?.fulfill()
        case firstSectionAppearedMessageString:
            firstSectionAppearedMessageReceivedExpectation?.fulfill()<commit_msg>Check message.name in 'didReceiveMessage' delegate callback.<commit_after>
import WebKit
import XCTest

class WMFArticleJSTests: XCTestCase, WKScriptMessageHandler {
    
    var session: SessionSingleton?
    var webVC: WebViewController?
    var obamaURL: URL?
    var obamaArticle: MWKArticle?

    var firstSectionAppearedMessageReceivedExpectation: XCTestExpectation?
    var startTimeMessageReceivedExpectation: XCTestExpectation?

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

        session = SessionSingleton.init(dataStore: MWKDataStore.temporary())
        webVC = WebViewController.wmf_initialViewControllerFromClassStoryboard()
        
        guard
            let newObamaURL = NSURL.wmf_URL(withDomain: "wikipedia.org", language: "en", title: "Barack Obama", fragment: nil),
            let dataStore = session?.dataStore
        else {
            assertionFailure("Expected Obama article and data store")
            return
        }
        obamaURL = newObamaURL
        obamaArticle = article(withMobileViewJSONFixture: "Obama", with: newObamaURL, dataStore: dataStore)
        obamaArticle?.save()
        
        startTimeMessageReceivedExpectation = nil
        firstSectionAppearedMessageReceivedExpectation = nil
    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }

    let jsTestingMessageHandlerString = "jsTesting"
    let startTimeMessageString = "startTime"
    let firstSectionAppearedMessageString = "firstSectionAppeared"
    
    func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
        // print("\n \n \n message body : \(message.body) \n \n \n ")
        guard
            let messageString = message.body as? String
        else {
            assertionFailure("Unhandled message type")
            return
        }
        
        switch message.name {
        case jsTestingMessageHandlerString:
            switch messageString {
            case startTimeMessageString:
                startTimeMessageReceivedExpectation?.fulfill()
            case firstSectionAppearedMessageString:
                firstSectionAppearedMessageReceivedExpectation?.fulfill()
            default:
                return
            }
{'fraction_non_alphanumeric': 0.0647133220910624, 'fraction_numerical': 0.0, 'mean_word_length': 2.736220472440945, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6638778', 'n_tokens_mistral': 1224, 'n_tokens_neox': 1177, 'n_words': 324}