<commit_before>// load type definitions that come with Cypress module
/// <reference types="cypress" />
describe('Mobile Connectors', function () {
  let API_HOST = Cypress.env('API_HOST')
  let apiUrl = `https://${API_HOST}`
  let selectors = {
    fitbit: {
      username: '.pa0 > #loginForm > .row > #email-input > #ember644',
      password: <PASSWORD> > #loginForm > .row > #password-input > #<PASSWORD>',
      submitButton: '.pa0 > #loginForm > .row > .column > #ember685',
    },
    rescuetime: {
      username: '#email',
      password: <PASSWORD>',
      submitButton: 'button[name="button"]',
    },
    facebook: {
      username: '#email',
      password: <PASSWORD>',
      submitButton: '#u_0_2',
    },
    github: {
      username: '#login_field',
      password: <PASSWORD>',
      submitButton: ['input[name="commit"]', 'button[name="authorize"]'],
    },
    runkeeper: {
      username: '#lightBoxLogInForm > input[id="emailInput"][name="email"]',
      password: <PASSWORD> > input[id="passwordInput"][name="password"]',
      submitButton: '#lightBoxLogInForm > button[id="loginSubmit"][type="submit"].component.ctaButton.primary.medium.signup_email_button.success.small.expand > .buttonText',
    },
  }
  function goToMobileConnectPage () {
    cy.log(`Using apiUrl: ${apiUrl}`)
    cy.visitApi(`/api/v1/connect/mobile?log=testuser&pwd=<PASSWORD>`)
    //cy.checkForBrokenImages()  // Keeps falsely failing
  }
    /**
     * @param {string} connectorName
     */
    function clickConnect (connectorName) {
        cy.log(`Connecting ${connectorName}`)
        cy.get(`#${connectorName}-connect-button`).click()
        cy.wait(5000)
    }
    /**
     * @param {string} connectorName
     */
    function clickDisconnect (connectorName) {
        cy.log(`Disconnecting ${connectorName}`)
        cy.get(`#${connectorName}-disconnect-button`).click()
    }
    /**
     * @param {string} connectorName
     */
    function disconnectAndClickConnect (connectorName) {
        goToMobileConnectPage()
        // this only works if there's 100% guarantee body has fully rendered without any pending changes to its state
        cy.get(`#${connectorName} > div.qm-account-block-right > div.qm-button-container`,
            { timeout: 20000 }).then(($connectorBlock) => {
            debugger
            // synchronously ask for the body's text and do something based on whether it includes another string
            if ($connectorBlock.text().includes('Disconnect')) {
                clickDisconnect(connectorName)
                clickConnect(connectorName)
            } else {
                cy.log(`${connectorName} already disconnected`)
                clickConnect(connectorName)
            }
        })
    }
    /**
     * @param {string} connectorName
     */
    function enterCredentials (connectorName) {
        let user = Cypress.env(connectorName.toUpperCase() + '_TEST_USER')
        if(!user){
            throw "Please set env " + connectorName.toUpperCase() + '_TEST_USER'
        }
        cy.enterCredentials(selectors[connectorName].username,
            Cypress.env(connectorName.toUpperCase() + '_TEST_USER'),
            selectors[connectorName].password,
            Cypress.env(connectorName.toUpperCase() + '_TEST_PASSWORD'),
            selectors[connectorName].submitButton)
    }
    /**
     * @param {string} connectorName
     */
    function verifyConnection (connectorName) {
        cy.get(`#${connectorName}-scheduled-button`, { timeout: 60000 })
            .should('contain', 'Update Scheduled')
        cy.get(`#${connectorName}-disconnect-button`)
            .should('exist')
        cy.get(`#${connectorName}-connect-button`)
            .should('not.exist')
    }
    /**
     * @param {string} connectorName
     */
    function checkOAuthConnector (connectorName) {
        cy.log(`Cookies:${JSON.stringify(cy.getCookies())}`)
        disconnectAndClickConnect(connectorName)
        enterCredentials(connectorName)
        verifyConnection(connectorName)
        clickDisconnect(connectorName)
    }
  it.skip('Connects and disconnects Fitbit', function () {
    checkOAuthConnector('fitbit')
  })
  it('Connects and disconnects WhatPulse', function () {
      Cypress.currentTest.retries(2)
    disconnectAndClickConnect('whatpulse')
    cy.get('input[name="username"]').type('mikepsinn', { force: true })
    cy.get('.qm-account-block[data-name=whatpulse3] .qm-account-connect-button-with-params')
            .click({ force: true })
    verifyConnection('whatpulse')<commit_msg>skip 'Connects and disconnects WhatPulse'<commit_after>// load type definitions that come with Cypress module
/// <reference types="cypress" />
describe('Mobile Connectors', function () {
  let API_HOST = Cypress.env('API_HOST')
  let apiUrl = `https://${API_HOST}`
  let selectors = {
    fitbit: {
      username: '.pa0 > #loginForm > .row > #email-input > #ember644',
      password: '.<PASSWORD> > #loginForm > .row > #password-input > #ember<PASSWORD>',
      submitButton: '.pa0 > #loginForm > .row > .column > #ember685',
    },
    rescuetime: {
      username: '#email',
      password: <PASSWORD>',
      submitButton: 'button[name="button"]',
    },
    facebook: {
      username: '#email',
      password: <PASSWORD>',
      submitButton: '#u_0_2',
    },
    github: {
      username: '#login_field',
      password: <PASSWORD>',
      submitButton: ['input[name="commit"]', 'button[name="authorize"]'],
    },
    runkeeper: {
      username: '#lightBoxLogInForm > input[id="emailInput"][name="email"]',
      password: '#<PASSWORD> > input[id="passwordInput"][name="password"]',
      submitButton: '#lightBoxLogInForm > button[id="loginSubmit"][type="submit"].component.ctaButton.primary.medium.signup_email_button.success.small.expand > .buttonText',
    },
  }
  function goToMobileConnectPage () {
    cy.log(`Using apiUrl: ${apiUrl}`)
    cy.visitApi(`/api/v1/connect/mobile?log=testuser&pwd=<PASSWORD>23`)
    //cy.checkForBrokenImages()  // Keeps falsely failing
  }
    /**
     * @param {string} connectorName
     */
    function clickConnect (connectorName) {
        cy.log(`Connecting ${connectorName}`)
        cy.get(`#${connectorName}-connect-button`).click()
        cy.wait(5000)
    }
    /**
     * @param {string} connectorName
     */
    function clickDisconnect (connectorName) {
        cy.log(`Disconnecting ${connectorName}`)
        cy.get(`#${connectorName}-disconnect-button`).click()
    }
    /**
     * @param {string} connectorName
     */
    function disconnectAndClickConnect (connectorName) {
        goToMobileConnectPage()
        // this only works if there's 100% guarantee body has fully rendered without any pending changes to its state
        cy.get(`#${connectorName} > div.qm-account-block-right > div.qm-button-container`,
            { timeout: 20000 }).then(($connectorBlock) => {
            debugger
            // synchronously ask for the body's text and do something based on whether it includes another string
            if ($connectorBlock.text().includes('Disconnect')) {
                clickDisconnect(connectorName)
                clickConnect(connectorName)
            } else {
                cy.log(`${connectorName} already disconnected`)
                clickConnect(connectorName)
            }
        })
    }
    /**
     * @param {string} connectorName
     */
    function enterCredentials (connectorName) {
        let user = Cypress.env(connectorName.toUpperCase() + '_TEST_USER')
        if(!user){
            throw "Please set env " + connectorName.toUpperCase() + '_TEST_USER'
        }
        cy.enterCredentials(selectors[connectorName].username,
            Cypress.env(connectorName.toUpperCase() + '_TEST_USER'),
            selectors[connectorName].password,
            Cypress.env(connectorName.toUpperCase() + '_TEST_PASSWORD'),
            selectors[connectorName].submitButton)
    }
    /**
     * @param {string} connectorName
     */
    function verifyConnection (connectorName) {
        cy.get(`#${connectorName}-scheduled-button`, { timeout: 60000 })
            .should('contain', 'Update Scheduled')
        cy.get(`#${connectorName}-disconnect-button`)
            .should('exist')
        cy.get(`#${connectorName}-connect-button`)
            .should('not.exist')
    }
    /**
     * @param {string} connectorName
     */
    function checkOAuthConnector (connectorName) {
        cy.log(`Cookies:${JSON.stringify(cy.getCookies())}`)
        disconnectAndClickConnect(connectorName)
        enterCredentials(connectorName)
        verifyConnection(connectorName)
        clickDisconnect(connectorName)
    }
  it.skip('Connects and disconnects Fitbit', function () {
    checkOAuthConnector('fitbit')
  })
    // TODO: Re-enable when Whatpulse is fixed
  it.skip('Connects and disconnects WhatPulse', function () {
      Cypress.currentTest.retries(2)
    disconnectAndClickConnect('whatpulse')
    cy.get('input[name="username"]').type('mikepsinn', { force: true })
    cy.get('.qm-account-block[data-name=whatpulse3] .qm-account-connect-button-with-params')
            .click({ force: true })
    verifyConnection('whatpulse')
{'fraction_non_alphanumeric': 0.14577227830239878, 'fraction_numerical': 0.006729621187452513, 'mean_word_length': 2.863312368972746, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 57, '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': '3858495', 'n_tokens_mistral': 2717, 'n_tokens_neox': 2651, 'n_words': 475}