<commit_before>//
//  StandardIntegrationUITests.swift
//  StandardIntegrationUITests
//
//  Created by <NAME> on 8/21/19.
//  Copyright © 2019 Stripe. All rights reserved.
//

import XCTest

class StandardIntegrationUITests: XCTestCase {

    override func setUp() {
        // In UI tests it is usually best to stop immediately when a failure occurs.
        continueAfterFailure = false

        // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
        let app = XCUIApplication()
        let stripePublishableKey = "<KEY>"
        let backendBaseURL = "https://stripe-mobile-test-backend.herokuapp.com/"
        app.launchArguments.append(contentsOf: ["-StripePublishableKey", stripePublishableKey, "-StripeBackendBaseURL", backendBaseURL])
        app.launch()
    }

    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
    }
    
    func disableAddressEntry(_ app: XCUIApplication) {
        app.navigationBars["Emoji Apparel"].buttons["Settings"].tap()
        app.tables.children(matching: .cell).element(boundBy: 8).staticTexts["None"].tap()
        app.navigationBars["Settings"].buttons["Done"].tap()
    }
    
    func selectItems(_ app: XCUIApplication) {
        let cellsQuery = app.collectionViews.cells
        cellsQuery.otherElements.containing(.staticText, identifier:"👠").element.tap()
        app.collectionViews.staticTexts["👞"].tap()
        cellsQuery.otherElements.containing(.staticText, identifier:"👗").children(matching: .other).element(boundBy: 0).tap()
    }
    
    func waitToAppear(_ target: Any?) {
        let exists = NSPredicate(format: "exists == 1")
        expectation(for: exists, evaluatedWith: target, handler: nil)
        waitForExpectations(timeout: 60.0, handler: nil)
    }
    
    func testSimpleTransaction() {
        let app = XCUIApplication()
        disableAddressEntry(app)
        selectItems(app)
        
        app.buttons["Buy Now"].tap()
        app.tables.otherElements.containing(.staticText, identifier:"Pay from").children(matching: .button).element.tap()
        let visa = app.tables.staticTexts["Visa Ending In 4242"]
        waitToAppear(visa)
        visa.tap()
        app.buttons["Buy"].tap()
        let success = app.alerts["Success"].buttons["OK"]
        waitToAppear(success)
        success.tap()
    }
    
    func test3DS1() {
        let app = XCUIApplication()
        disableAddressEntry(app)
        selectItems(app)

        let buyNowButton = app.buttons["Buy Now"]
        buyNowButton.tap()

        app.tables.otherElements.containing(.staticText, identifier:"Pay from").children(matching: .button).element.tap()
        let visa3063 = app.tables.staticTexts["Visa Ending In 3063"]
        waitToAppear(visa3063)
        visa3063.tap()

        let buyButton = app.buttons["Buy"]
        buyButton.tap()
        
        let webViewsQuery = app.webViews
        let completeAuth = webViewsQuery.buttons["COMPLETE AUTHENTICATION"]
        waitToAppear(completeAuth)
        completeAuth.tap()
        var returnToMerchant = webViewsQuery.staticTexts["Return to Merchant"]
        waitToAppear(returnToMerchant)
        returnToMerchant.tap()
        let successButton = app.alerts["Success"].buttons["OK"]
        waitToAppear(successButton)
        successButton.tap()
        buyButton.tap()

        let failAuth = webViewsQuery.buttons["FAIL AUTHENTICATION"]
        waitToAppear(failAuth)
        failAuth.tap()
        returnToMerchant = webViewsQuery.staticTexts["Return to Merchant"]
        waitToAppear(returnToMerchant)
        app.buttons["Close"].tap()
        let errorButton = app.alerts["Error"].buttons["OK"]
        waitToAppear(errorButton)
        errorButton.tap()
    }
    
    func test3DS2() {
        let app = XCUIApplication()<commit_msg>Update tests for new redirect<commit_after>//
//  StandardIntegrationUITests.swift
//  StandardIntegrationUITests
//
//  Created by <NAME> on 8/21/19.
//  Copyright © 2019 Stripe. All rights reserved.
//

import XCTest

class StandardIntegrationUITests: XCTestCase {

    override func setUp() {
        // In UI tests it is usually best to stop immediately when a failure occurs.
        continueAfterFailure = false

        // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
        let app = XCUIApplication()
        let stripePublishableKey = "<KEY>"
        let backendBaseURL = "https://stripe-mobile-test-backend.herokuapp.com/"
        app.launchArguments.append(contentsOf: ["-StripePublishableKey", stripePublishableKey, "-StripeBackendBaseURL", backendBaseURL])
        app.launch()
    }

    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
    }
    
    func disableAddressEntry(_ app: XCUIApplication) {
        app.navigationBars["Emoji Apparel"].buttons["Settings"].tap()
        app.tables.children(matching: .cell).element(boundBy: 8).staticTexts["None"].tap()
        app.navigationBars["Settings"].buttons["Done"].tap()
    }
    
    func selectItems(_ app: XCUIApplication) {
        let cellsQuery = app.collectionViews.cells
        cellsQuery.otherElements.containing(.staticText, identifier:"👠").element.tap()
        app.collectionViews.staticTexts["👞"].tap()
        cellsQuery.otherElements.containing(.staticText, identifier:"👗").children(matching: .other).element(boundBy: 0).tap()
    }
    
    func waitToAppear(_ target: Any?) {
        let exists = NSPredicate(format: "exists == 1")
        expectation(for: exists, evaluatedWith: target, handler: nil)
        waitForExpectations(timeout: 60.0, handler: nil)
    }
    
    func testSimpleTransaction() {
        let app = XCUIApplication()
        disableAddressEntry(app)
        selectItems(app)
        
        app.buttons["Buy Now"].tap()
        app.tables.otherElements.containing(.staticText, identifier:"Pay from").children(matching: .button).element.tap()
        let visa = app.tables.staticTexts["Visa Ending In 4242"]
        waitToAppear(visa)
        visa.tap()
        app.buttons["Buy"].tap()
        let success = app.alerts["Success"].buttons["OK"]
        waitToAppear(success)
        success.tap()
    }
    
    func test3DS1() {
        let app = XCUIApplication()
        disableAddressEntry(app)
        selectItems(app)

        let buyNowButton = app.buttons["Buy Now"]
        buyNowButton.tap()

        app.tables.otherElements.containing(.staticText, identifier:"Pay from").children(matching: .button).element.tap()
        let visa3063 = app.tables.staticTexts["Visa Ending In 3063"]
        waitToAppear(visa3063)
        visa3063.tap()

        let buyButton = app.buttons["Buy"]
        buyButton.tap()
        
        let webViewsQuery = app.webViews
        let completeAuth = webViewsQuery.buttons["COMPLETE AUTHENTICATION"]
        waitToAppear(completeAuth)
        completeAuth.tap()
        let successButton = app.alerts["Success"].buttons["OK"]
        waitToAppear(successButton)
        successButton.tap()
        buyButton.tap()

        let failAuth = webViewsQuery.buttons["FAIL AUTHENTICATION"]
        waitToAppear(failAuth)
        failAuth.tap()
        let errorButton = app.alerts["Error"].buttons["OK"]
        waitToAppear(errorButton)
        errorButton.tap()
    }
    
    func test3DS2() {
        let app = XCUIApplication()
{'fraction_non_alphanumeric': 0.11341431212041193, 'fraction_numerical': 0.010298389226300502, 'mean_word_length': 2.7780548628428927, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '3436407', 'n_tokens_mistral': 2293, 'n_tokens_neox': 2138, 'n_words': 468}