<commit_before>package geb.de.iteratec.osm.result

import de.iteratec.osm.OsmConfiguration
import de.iteratec.osm.csi.Page
import de.iteratec.osm.measurement.environment.Browser
import de.iteratec.osm.measurement.environment.Location
import de.iteratec.osm.measurement.environment.WebPageTestServer
import de.iteratec.osm.measurement.schedule.ConnectivityProfile
import de.iteratec.osm.measurement.schedule.ConnectivityProfileService
import de.iteratec.osm.measurement.schedule.Job
import de.iteratec.osm.measurement.schedule.JobGroup
import de.iteratec.osm.measurement.script.Script
import de.iteratec.osm.result.*
import de.iteratec.osm.security.Role
import de.iteratec.osm.security.User
import de.iteratec.osm.security.UserRole
import de.iteratec.osm.util.OsmTestLogin
import geb.CustomUrlGebReportingSpec
import geb.pages.de.iteratec.osm.result.EventResultDashboardPage
import grails.testing.mixin.integration.Integration
import grails.gorm.transactions.Rollback
import org.joda.time.DateTime
import org.joda.time.DateTimeZone
import org.openqa.selenium.Keys
import spock.lang.Shared
import spock.lang.Stepwise
/**
 * Created by marko on 22.06.16.
 */
@Integration
@Rollback
@Stepwise
class EventResultDashboardAdjustChartGebSpec extends CustomUrlGebReportingSpec implements OsmTestLogin {

    @Shared
    String script1Name = "TestScript1-564892#Afef1"
    @Shared
    String script2Name = "TestScript2-564892#Afef1"
    @Shared
    String job1Name = "TestJob1-564892#Afef1"
    @Shared
    String job2Name = "TestJob2-564892#Afef1"
    @Shared
    String location1Name = "TestLocation1-564892#Afef1"
    @Shared
    String Location2Name = "TestLocation2-564892#Afef1"
    @Shared
    String jobGroup1Name = "TestJobGroup1-564892#Afef1"
    @Shared
    String page1Name = "TestPage1-564892#Afef1"
    @Shared
    String connectivityProfileName = "ConnectivityProfile-564892#Afef1"
    @Shared
    String measureEvent1Name = "MeasureEvent1-564892#Afef1"

    void cleanupSpec() {
        cleanUpData()
    }

    void "Login makes \"Save as Dashboard\"-Button visible"() {
        when: "User is not logged in"
        createData()
        to EventResultDashboardPage
        then: "The button is invisible"
        !saveAsDashboardButton.present

        when: "User is logged in"
        doLogin()
        to EventResultDashboardPage

        then: "Button is visible"
        saveAsDashboardButton.present

    }

    void "Document Complete graph is shown"() {
        given: "User selects valid timeframe, page and jobgroup"
        timeFrameSelect.click()
        selectDateInDatepicker(fromDatepicker, "21.06.2016 00:00")
        selectDateInDatepicker(toDatepicker, "23.06.2016 23:59")
        sleep(500)
        jobGroupList[0].click()
        pageList[0].click()
        connectivityTab.click()
        waitFor {selectConnectivityProfilesList.displayed}
        selectConnectivityProfilesList[0].click()
        tabVariableSelection.click()

        when: "User wants to see a graph"
        waitFor { showButton.displayed }
        sleep(100)
        waitFor { showButton.click() }

        then: "A graph with a line is shown"
        at EventResultDashboardPage
        waitFor { graphLines.displayed }
        graphLines.size() == 1
        graphName == 'fv Document Complete | TestJobGroup1-564892#Afef1 | MeasureEvent1-564892#Afef1 | TestLocation1-564892#Afef1 | ConnectivityProfile-564892#Afef1'

        def graphSeries = js."window.rickshawGraphBuilder.graph.series"
        graphSeries.size() == 1
        graphSeries[0].data.collect {
            [x: it.x, y: it.y]
        } == [[x: 1466565180, y: 838], [x: 1466565300, y: 238], [x: 1466565480, y: 638]]
    }

    void "Adjust Chart Title"() {
        given: "User opens Adjust Chart"
        clickAdjustChartButton()

        when: "User edits title"
        waitFor { chartTitleInputField.displayed }
        sleep(300)
        chartTitleInputField << "CustomTitle"
        sleep(300)
        adjustChartApply.click()

        then: "Chart title is changed"
        waitFor { chartTitle == "CustomTitle" }
    }

    void "Adjust Chart Size to illegal values"() {
        given: "User edits chart size"
        waitFor { adjustChartButton.click() }
        sleep(200)
        chartWidthInputField.firstElement().clear()
        chartWidthInputField << "0"
        chartheightInputField.firstElement().clear()
        chartheightInputField << "9999999"

        when: "User clicks \"apply\""
        sleep(100)
        def result = withAlert { adjustChartApply.click() }

        then: "Error message is shown"
        result == "Width and height of diagram must be numeric values. Maximum is 5.000 x 3.000 pixels, minimum width is 540 pixels."
    }

    void "Adjust Chart Size"() {
        given: "User edits chart size"
        chartWidthInputField.firstElement().clear()
        chartWidthInputField << "600"
        chartheightInputField.firstElement().clear()
        chartheightInputField << "600"

        when: "User clicks \"apply\""
        waitFor { adjustChartApply.displayed }
        adjustChartApply.click()

        then: "Chart changed"
        waitFor { graphLines.displayed }
        graphLines.size() == 1

        def graphSeries = js."window.rickshawGraphBuilder.graph.series"
        graphSeries.size() == 1
        graphSeries[0].data.collect {
            [x: it.x, y: it.y]
        } == [[x: 1466565180, y: 838], [x: 1466565300, y: 238], [x: 1466565480, y: 638]]

        chartContainer.width == 600
        chartContainer.height == 650
        graphYGridFirstTick == "0"
        graphYGridLastTick == "840"
    }

    void "Add graph alias"() {
        given: "User clicks on the add graph aliases button"
        sleep(200)
        adjustChartButton.click()
        waitFor { addAliasButton.displayed }
        sleep(200)
        addAliasButton.click()

        when: "User provides graph alias"
        waitFor { graphNameSelect.displayed }
        graphNameSelect.click()
        sleep(200)
        graphNameSelectOptions[1].click()
        aliasInputField << "CustomAlias"
        adjustChartApply.click()
        sleep(200)

        then: "Graph is renamed"
        waitFor { graphName == "CustomAlias" }
    }

    void "Change Graph color"() {
        when: "User changes graph color"
        waitFor{ adjustChartButton.click() }
        waitFor { colorPicker.displayed }
        sleep(300)
        setColorPicker("#aaaaaa")
        adjustChartApply.click()

        then: "Graph is recolored"
        true<commit_msg>[IT-1681] Call geb method on single-element navigator<commit_after>package geb.de.iteratec.osm.result

import de.iteratec.osm.OsmConfiguration
import de.iteratec.osm.csi.Page
import de.iteratec.osm.measurement.environment.Browser
import de.iteratec.osm.measurement.environment.Location
import de.iteratec.osm.measurement.environment.WebPageTestServer
import de.iteratec.osm.measurement.schedule.ConnectivityProfile
import de.iteratec.osm.measurement.schedule.ConnectivityProfileService
import de.iteratec.osm.measurement.schedule.Job
import de.iteratec.osm.measurement.schedule.JobGroup
import de.iteratec.osm.measurement.script.Script
import de.iteratec.osm.result.*
import de.iteratec.osm.security.Role
import de.iteratec.osm.security.User
import de.iteratec.osm.security.UserRole
import de.iteratec.osm.util.OsmTestLogin
import geb.CustomUrlGebReportingSpec
import geb.pages.de.iteratec.osm.result.EventResultDashboardPage
import grails.testing.mixin.integration.Integration
import grails.gorm.transactions.Rollback
import org.joda.time.DateTime
import org.joda.time.DateTimeZone
import org.openqa.selenium.Keys
import spock.lang.Shared
import spock.lang.Stepwise
/**
 * Created by marko on 22.06.16.
 */
@Integration
@Rollback
@Stepwise
class EventResultDashboardAdjustChartGebSpec extends CustomUrlGebReportingSpec implements OsmTestLogin {

    @Shared
    String script1Name = "TestScript1-564892#Afef1"
    @Shared
    String script2Name = "TestScript2-564892#Afef1"
    @Shared
    String job1Name = "TestJob1-564892#Afef1"
    @Shared
    String job2Name = "TestJob2-564892#Afef1"
    @Shared
    String location1Name = "TestLocation1-564892#Afef1"
    @Shared
    String Location2Name = "TestLocation2-564892#Afef1"
    @Shared
    String jobGroup1Name = "TestJobGroup1-564892#Afef1"
    @Shared
    String page1Name = "TestPage1-564892#Afef1"
    @Shared
    String connectivityProfileName = "ConnectivityProfile-564892#Afef1"
    @Shared
    String measureEvent1Name = "MeasureEvent1-564892#Afef1"

    void cleanupSpec() {
        cleanUpData()
    }

    void "Login makes \"Save as Dashboard\"-Button visible"() {
        when: "User is not logged in"
        createData()
        to EventResultDashboardPage
        then: "The button is invisible"
        !saveAsDashboardButton.present

        when: "User is logged in"
        doLogin()
        to EventResultDashboardPage

        then: "Button is visible"
        saveAsDashboardButton.present

    }

    void "Document Complete graph is shown"() {
        given: "User selects valid timeframe, page and jobgroup"
        timeFrameSelect.click()
        selectDateInDatepicker(fromDatepicker, "21.06.2016 00:00")
        selectDateInDatepicker(toDatepicker, "23.06.2016 23:59")
        sleep(500)
        jobGroupList[0].click()
        pageList[0].click()
        connectivityTab.click()
        waitFor {selectConnectivityProfilesList.displayed}
        selectConnectivityProfilesList[0].click()
        tabVariableSelection.click()

        when: "User wants to see a graph"
        waitFor { showButton.displayed }
        sleep(100)
        waitFor { showButton.click() }

        then: "A graph with a line is shown"
        at EventResultDashboardPage
        waitFor { graphLines.displayed }
        graphLines.size() == 1
        graphName == 'fv Document Complete | TestJobGroup1-564892#Afef1 | MeasureEvent1-564892#Afef1 | TestLocation1-564892#Afef1 | ConnectivityProfile-564892#Afef1'

        def graphSeries = js."window.rickshawGraphBuilder.graph.series"
        graphSeries.size() == 1
        graphSeries[0].data.collect {
            [x: it.x, y: it.y]
        } == [[x: 1466565180, y: 838], [x: 1466565300, y: 238], [x: 1466565480, y: 638]]
    }

    void "Adjust Chart Title"() {
        given: "User opens Adjust Chart"
        clickAdjustChartButton()

        when: "User edits title"
        waitFor { chartTitleInputField.displayed }
        sleep(300)
        chartTitleInputField << "CustomTitle"
        sleep(300)
        adjustChartApply.click()

        then: "Chart title is changed"
        waitFor { chartTitle == "CustomTitle" }
    }

    void "Adjust Chart Size to illegal values"() {
        given: "User edits chart size"
        waitFor { adjustChartButton.click() }
        sleep(200)
        chartWidthInputField.firstElement().clear()
        chartWidthInputField << "0"
        chartheightInputField.firstElement().clear()
        chartheightInputField << "9999999"

        when: "User clicks \"apply\""
        sleep(100)
        def result = withAlert { adjustChartApply.click() }

        then: "Error message is shown"
        result == "Width and height of diagram must be numeric values. Maximum is 5.000 x 3.000 pixels, minimum width is 540 pixels."
    }

    void "Adjust Chart Size"() {
        given: "User edits chart size"
        chartWidthInputField.firstElement().clear()
        chartWidthInputField << "600"
        chartheightInputField.firstElement().clear()
        chartheightInputField << "600"

        when: "User clicks \"apply\""
        waitFor { adjustChartApply.displayed }
        adjustChartApply.click()

        then: "Chart changed"
        waitFor { graphLines.displayed }
        graphLines.size() == 1

        def graphSeries = js."window.rickshawGraphBuilder.graph.series"
        graphSeries.size() == 1
        graphSeries[0].data.collect {
            [x: it.x, y: it.y]
        } == [[x: 1466565180, y: 838], [x: 1466565300, y: 238], [x: 1466565480, y: 638]]

        chartContainer.width == 600
        chartContainer.height == 650
        graphYGridFirstTick == "0"
        graphYGridLastTick == "840"
    }

    void "Add graph alias"() {
        given: "User clicks on the add graph aliases button"
        sleep(200)
        adjustChartButton.click()
        waitFor { addAliasButton.displayed }
        sleep(200)
        addAliasButton.click()

        when: "User provides graph alias"
        waitFor { graphNameSelect[0].displayed }
        graphNameSelect[0].click()
        sleep(200)
        graphNameSelectOptions[1].click()
        aliasInputField << "CustomAlias"
        adjustChartApply.click()
        sleep(200)

        then: "Graph is renamed"
        waitFor { graphName == "CustomAlias" }
    }

    void "Change Graph color"() {
        when: "User changes graph color"
        waitFor{ adjustChartButton.click() }
        waitFor { colorPicker[0].displayed }
        sleep(300)
        setColorPicker("#aaaaaa")
        adjustChartApply.click()

        then: "Graph is recolored"
        true
{'fraction_non_alphanumeric': 0.09988562714449103, 'fraction_numerical': 0.04704536789935189, 'mean_word_length': 2.8429534134192793, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '5665369', 'n_tokens_mistral': 4359, 'n_tokens_neox': 3913, 'n_words': 869}