def run_panel_line_graph_scenarios(chart_builder_page, driver):
    """
    CHART BUILDER CAN BUILD LINE GRAPHS
    """

    """
    GIVEN some basic data appropriate for building line graphs
    """
    chart_builder_page.refresh()
    inject_data(driver, ethnicity_by_time_data)
    chart_builder_page.click_data_okay()
    """
    WHEN we add panel line chart settings
    """
    chart_builder_page.select_chart_type("Panel line chart")
    chart_builder_page.wait_for_seconds(1)
    chart_builder_page.select_panel_line_x_axis_column("Time")
    chart_builder_page.wait_for_seconds(1)
    chart_builder_page.select_ethnicity_settings("ONS 2011 - 5+1")
    chart_builder_page.wait_for_seconds(2)
    """
    THEN a line graph exists with times on the x-axis and ethnicity names as the series

    note: highcharts optimises x-axes and particularly on panel line charts - we aren't going to check up on these
    """
    ethnicities = chart_builder_page.panel_names()
    assert ethnicities == ["Asian", "Black", "Mixed", "White", "Other"]
def run_complex_table_by_row_scenario(table_builder_page, driver):
    """
    CHART BUILDER CAN BUILD GROUPED BAR TABLES with ethnicity for sub-groups
    """
    """
    GIVEN some basic data appropriate for building grouped bar tables
    """
    table_builder_page.refresh()
    inject_data(driver, ethnicity_by_gender_data)
    table_builder_page.click_data_okay()
    """
    THEN first column names ought to be Ethnicity by default
    """
    assert table_builder_page.input_index_column_name() == "Ethnicity"
    """
    WHEN we set up the complex table options
    """
    table_builder_page.select_data_style("Use ethnicity for rows")
    table_builder_page.wait_for_seconds(1)
    table_builder_page.select_columns_when_ethnicity_is_row("Gender")
    table_builder_page.select_column(1, "Value")
    table_builder_page.select_column(2, "Gender")
    table_builder_page.wait_for_seconds(1)
    """
    THEN a complex table exists with ethnicities on the left, gender along the top, and sub-columns of value and gender.
    """
    assert table_builder_page.table_headers() == ["Ethnicity", "F", "M"]
    assert table_builder_page.table_secondary_headers() == [
        "Value", "Gender", "Value", "Gender"
    ]
    assert table_builder_page.table_column_contents(1) == [
        "Asian", "Black", "Mixed", "White", "Other"
    ]
    assert table_builder_page.table_column_contents(2) == [
        "4", "1", "5", "4", "2"
    ]
    assert table_builder_page.table_column_contents(3) == ["F"] * 5
    assert table_builder_page.table_column_contents(4) == [
        "5", "4", "3", "2", "1"
    ]
    assert table_builder_page.table_column_contents(5) == ["M"] * 5
    """
    AND a first column name set on the table as default
    """
    assert table_builder_page.table_index_column_name() == "Ethnicity"
    """
    WHEN we change the value of the first column in the input box
    """
    table_builder_page.set_input_index_column_name("Custom first column")
    """
    THEN it changes the value of the first column in the table
    """
    assert table_builder_page.table_index_column_name(
    ) == "Custom first column"
def run_panel_bar_charts_scenarios(chart_builder_page, driver):
    """
    CHART BUILDER CAN BUILD GROUPED BAR CHARTS with ethnicity for sub-groups
    """
    """
    GIVEN some basic data appropriate for building panel bar charts
    """
    chart_builder_page.refresh()
    inject_data(driver, ethnicity_by_gender_data)
    chart_builder_page.click_data_okay()
    """
    WHEN we add basic panel bar chart settings
    """
    chart_builder_page.select_chart_type("Panel bar chart")
    chart_builder_page.wait_for_seconds(1)
    chart_builder_page.select_panel_bar_data_style("Use ethnicity for bars")
    chart_builder_page.wait_for_seconds(1)
    chart_builder_page.select_panel_bar_panel_column("Gender")
    chart_builder_page.wait_for_seconds(1)
    chart_builder_page.select_ethnicity_settings("ONS 2011 - 5+1")
    chart_builder_page.wait_for_seconds(1)
    """
    THEN panel bar charts exists ethnicities as bars and with one panel for each gender
    """
    genders = set(chart_builder_page.panel_names())
    assert genders == {"F", "M"}

    ethnicities = chart_builder_page.chart_x_axis()
    assert ethnicities == ["Asian", "Black", "Mixed", "White", "Other"]

    """
    CHART BUILDER CAN BUILD PANEL CHARTS with ethnicity for panels
    """
    """
    WHEN we add basic component chart settings
    """
    chart_builder_page.select_panel_bar_data_style("Use ethnicity for panels")
    chart_builder_page.wait_for_seconds(1)
    chart_builder_page.select_panel_bar_bar_column("Gender")
    chart_builder_page.wait_for_seconds(1)
    chart_builder_page.select_ethnicity_settings("ONS 2011 - 5+1")
    chart_builder_page.wait_for_seconds(1)

    """
    THEN panel bar charts exist with genders as bars and with one panel for each ethnicity
    """
    ethnicities = chart_builder_page.panel_names()
    assert ethnicities == ["Asian", "Black", "Mixed", "White", "Other"]

    genders = set(chart_builder_page.chart_x_axis())
    assert genders == {"M", "F"}
def run_component_charts_scenarios(chart_builder_page, driver):
    """


    CHART BUILDER CAN BUILD COMPONENT CHARTS with ethnicity for bars
    """
    """
    GIVEN some basic data appropriate for building component charts
    """
    chart_builder_page.refresh()
    inject_data(driver, ethnicity_by_gender_data)
    chart_builder_page.click_data_ok()
    """
    WHEN we add basic component chart settings
    """
    chart_builder_page.select_chart_type("Component chart")
    chart_builder_page.wait_for_seconds(1)
    chart_builder_page.select_component_data_style("Use ethnicity for bars")
    chart_builder_page.wait_for_seconds(1)
    chart_builder_page.select_component_section_column("Gender")
    chart_builder_page.wait_for_seconds(1)
    """
    THEN a component graph exists with ethnicities as bars and genders for sections
    """
    ethnicities = chart_builder_page.chart_x_axis()
    assert ethnicities == ["Asian", "Black", "Mixed", "White", "Other"]
    genders = set(chart_builder_page.chart_series())
    assert genders == {"F", "M"}
    """


    CHART BUILDER CAN BUILD COMPONENT CHARTS with ethnicity for sections
    """
    """
    WHEN we add basic component chart settings
    """
    chart_builder_page.select_component_data_style(
        "Use ethnicity for bar sections")
    chart_builder_page.wait_for_seconds(1)
    chart_builder_page.select_component_bar_column("Gender")
    chart_builder_page.wait_for_seconds(1)
    """
    THEN a component graph exists with two gender bars and ethnicity sections
    """
    genders = set(chart_builder_page.chart_x_axis())
    assert genders == {"F", "M"}
    ethnicities = chart_builder_page.chart_series()
    assert ethnicities == ["Asian", "Black", "Mixed", "White", "Other"]
def run_line_graph_scenarios(chart_builder_page, driver):
    """

    CHART BUILDER CAN BUILD LINE GRAPHS
    """
    """
    GIVEN some basic data appropriate for building line graphs
    """
    chart_builder_page.refresh()
    inject_data(driver, ethnicity_by_time_data)
    chart_builder_page.click_data_okay()
    """
    WHEN we add basic line chart settings
    """
    chart_builder_page.select_chart_type("Line graph")
    chart_builder_page.wait_for_seconds(1)
    chart_builder_page.select_line_x_axis_column("Time")
    chart_builder_page.wait_for_seconds(1)
    """
    THEN a line graph exists with times on the x-axis and ethnicity names as the series
    """
    times = chart_builder_page.chart_x_axis()
    assert times == ["1", "2", "3"]
    ethnicities = chart_builder_page.graph_series()
    assert ethnicities == ["Asian", "Black", "Mixed", "White", "Other"]
    """

    CHART BUILDER ORDERS LINE GRAPH SERIES according to classifications
    """
    """
    GIVEN some shuffled up data appropriate for building line graphs
    """
    chart_builder_page.refresh()
    inject_data(driver, shuffle_table(ethnicity_by_time_data))
    chart_builder_page.click_data_okay()
    """
    WHEN we add basic line chart settings
    """
    chart_builder_page.select_chart_type("Line graph")
    chart_builder_page.wait_for_seconds(1)
    chart_builder_page.select_line_x_axis_column("Time")
    chart_builder_page.wait_for_seconds(1)
    """
    THEN ethnicities are ordered as the series
    """
    ethnicities = chart_builder_page.graph_series()
    assert ethnicities == ["Asian", "Black", "Mixed", "White", "Other"]
def run_save_and_load_scenario(table_builder_page, driver):
    """
    Check that settings are retained on save
    """
    table_builder_page.refresh()

    """
    GIVEN we build a basic table
    """
    inject_data(driver, simple_data)
    table_builder_page.click_data_ok()
    table_builder_page.wait_for_seconds(1)
    table_builder_page.click_data_edit()
    table_builder_page.wait_for_seconds(1)
    table_builder_page.click_data_cancel()
    table_builder_page.wait_for_seconds(1)

    """
    THEN the edit screen should setup with default classification (for simple data)
    """
    assert table_builder_page.get_ethnicity_settings_code() == "5B"
    assert table_builder_page.get_ethnicity_settings_value() == "ONS 2011 - 5+1"
    assert table_builder_page.get_custom_classification_panel().is_displayed() is False

    """
    WHEN we choose a column to display
    """
    table_builder_page.select_column(1, "Value")
    table_builder_page.wait_for_seconds(1)

    """
    AND we select an alternate classification and save
    """
    table_builder_page.select_ethnicity_settings_value("ONS 2001 - 5+1")

    assert table_builder_page.get_ethnicity_settings_code() == "5A"
    assert table_builder_page.get_ethnicity_settings_value() == "ONS 2001 - 5+1"

    table_builder_page.click_save()
    table_builder_page.wait_for_seconds(1)

    """
    THEN it should reload with the alternate settings
    """
    assert table_builder_page.get_ethnicity_settings_code() == "5A"
    assert table_builder_page.get_ethnicity_settings_value() == "ONS 2001 - 5+1"
def run_save_and_load_scenario(chart_builder_page, driver):
    """
    Check that settings are retained on save
    """
    chart_builder_page.refresh()

    """
    GIVEN we build a basic chart
    """
    inject_data(driver, simple_data)
    chart_builder_page.click_data_okay()
    chart_builder_page.wait_for_seconds(1)
    chart_builder_page.click_edit_data()
    chart_builder_page.wait_for_seconds(1)
    chart_builder_page.click_data_cancel()
    chart_builder_page.select_chart_type("Bar chart")
    chart_builder_page.wait_for_seconds(1)

    """
    THEN the edit screen should setup with default classification (for simple data)
    """
    assert chart_builder_page.get_ethnicity_settings_code() == "5B"
    assert chart_builder_page.get_ethnicity_settings_value() == "ONS 2011 - 5+1"

    """
    WHEN we select an alternate classification and save
    """
    chart_builder_page.select_ethnicity_settings_value("ONS 2001 - 5+1")

    assert chart_builder_page.get_ethnicity_settings_code() == "5A"
    assert chart_builder_page.get_ethnicity_settings_value() == "ONS 2001 - 5+1"

    chart_builder_page.click_save()
    chart_builder_page.wait_for_seconds(1)

    """
    THEN it should reload with the alternate settings
    """
    assert chart_builder_page.get_ethnicity_settings_code() == "5A"
    assert chart_builder_page.get_ethnicity_settings_value() == "ONS 2001 - 5+1"
def run_parent_child_bar_chart_scenarios(chart_builder_page, driver):
    """
    SCENARIO 1. USING DATA THAT DOESN'T HAVE PARENT CATEGORIES
    """

    """
    GIVEN a version of data that has low granularity but doesn't include
    """
    chart_builder_page.refresh()
    inject_data(driver, granular_data)
    chart_builder_page.click_data_okay()

    """
    WHEN we select bar chart
    """
    chart_builder_page.select_chart_type("Bar chart")
    chart_builder_page.wait_for_seconds(1)

    """
    THEN the ethnicities are correctly sorted automatically and include parents
    """
    ethnicities = chart_builder_page.chart_x_axis()
    actual = spaceless(ethnicities)
    expected = spaceless(
        [
            "Asian",
            "Bangladeshi",
            "Indian",
            "Pakistani",
            "Asian other",
            "Black",
            "Black African",
            "Black Caribbean",
            "Black other",
            "Mixed",
            "Mixed White/Asian",
            "Mixed White/Black African",
            "Mixed White/Black Caribbean",
            "Mixed other",
            "White",
            "White British",
            "White Irish",
            "White other",
            "Other inc Chinese",
            "Chinese",
            "Any other",
        ]
    )

    assert actual == expected

    """
    SCENARIO 2. USING DATA THAT DOES HAVE PARENT CATEGORIES
    """

    """
    GIVEN a version of data that has low granularity but doesn't include parents
    """
    chart_builder_page.refresh()
    inject_data(driver, granular_with_parent_data)
    chart_builder_page.click_data_okay()

    """
    WHEN we select bar chart
    """
    chart_builder_page.select_chart_type("Bar chart")
    chart_builder_page.wait_for_seconds(1)

    """
    THEN the ethnicities are correctly sorted automatically and include parents
    """
    ethnicities = chart_builder_page.chart_x_axis()
    actual = spaceless(ethnicities)
    expected = spaceless(
        [
            "Asian",
            "Bangladeshi",
            "Indian",
            "Pakistani",
            "Asian other",
            "Black",
            "Black African",
            "Black Caribbean",
            "Black other",
            "Mixed",
            "Mixed White/Asian",
            "Mixed White/Black African",
            "Mixed White/Black Caribbean",
            "Mixed other",
            "White",
            "White British",
            "White Irish",
            "White other",
            "Other inc Chinese",
            "Chinese",
            "Any other",
        ]
    )
    assert actual == expected

    """
    AND the parent bars are a different colour to child bars
    note: Asian (parent) = 0, Bangladeshi (child) = 1, Indian (child) = 2
    """
    bar_colours = chart_builder_page.chart_bar_colours()
    assert bar_colours[0] != bar_colours[1]
    assert bar_colours[1] == bar_colours[2]
def run_bar_chart_scenarios(chart_builder_page, driver):
    """
    SCENARIO 1. CREATE A SIMPLE CHART
    """

    """
    GIVEN some basic data appropriate for building bar charts
    """
    inject_data(driver, simple_data)
    chart_builder_page.click_data_okay()
    chart_builder_page.wait_for_seconds(1)

    """
    THEN the edit screen should get set up
    """
    assert chart_builder_page.source_contains("5 rows by 2 columns")
    assert len(chart_builder_page.get_ethnicity_settings_list()) == 3
    assert chart_builder_page.get_ethnicity_settings_value() == "ONS 2011 - 5+1"

    """
    WHEN we select bar chart
    """
    chart_builder_page.select_chart_type("Bar chart")
    chart_builder_page.wait_for_seconds(1)

    """
    THEN we should have a chart with ethnicities as the bars
    """
    ethnicities = chart_builder_page.chart_x_axis()
    assert ethnicities == ["Asian", "Black", "Mixed", "White", "Other"]

    values = chart_builder_page.chart_labels()
    assert values == ["5", "4", "3", "2", "1"]

    """
    WHEN we select an alternative ethnicity set up
    """
    chart_builder_page.select_ethnicity_settings("ONS 2001 - 5+1")
    chart_builder_page.wait_for_seconds(1)

    """
    THEN the ethnicities that appear in the charts get changed
    """
    ethnicities = chart_builder_page.chart_x_axis()
    assert ethnicities == ["Asian", "Black", "Mixed", "White", "Other inc Chinese"]

    """
    SCENARIO 2. CREATE A CHART WITH DISORDERLY DATA
    """

    """
    GIVEN a shuffled version of our simple data
    """
    chart_builder_page.refresh()
    inject_data(driver, shuffle_table(simple_data))
    chart_builder_page.click_data_okay()

    """
    WHEN we select bar chart
    """
    chart_builder_page.select_chart_type("Bar chart")
    chart_builder_page.wait_for_seconds(1)

    """
    THEN the ethnicities are correctly sorted automatically
    """
    ethnicities = chart_builder_page.chart_x_axis()
    assert ethnicities == ["Asian", "Black", "Mixed", "White", "Other"]
    return chart_builder_page
def test_can_create_a_measure_page(driver, app, test_app_editor, live_server,
                                   stub_topic_page, stub_subtopic_page,
                                   stub_published_measure_page):
    page = RandomMeasure()

    login(driver, live_server, test_app_editor)
    """
    BROWSE TO POINT WHERE WE CAN ADD A MEASURE
    """
    home_page = HomePage(driver, live_server)
    home_page.click_topic_link(stub_topic_page)

    topic_page = TopicPage(driver, live_server, stub_topic_page)
    topic_page.expand_accordion_for_subtopic(stub_subtopic_page)
    """
    CREATE A NEW MEASURE
    """
    topic_page.click_add_measure(stub_subtopic_page)
    topic_page.wait_until_url_contains("/measure/new")
    create_measure(driver, live_server, page, stub_topic_page,
                   stub_subtopic_page)
    """
    EDIT THE MEASURE
    """
    topic_page.wait_until_url_contains("/edit")
    edit_measure_page = MeasureEditPage(driver)

    edit_measure_page.set_measure_summary(page.measure_summary)
    edit_measure_page.set_summary(page.summary)
    edit_measure_page.click_save()
    assert edit_measure_page.is_current()
    """
    PREVIEW CURRENT PROGRESS
    """
    edit_measure_page.click_preview()
    edit_measure_page.wait_until_url_does_not_contain("/cms/")

    preview_measure_page = MeasurePreviewPage(driver)
    assert preview_measure_page.is_current()

    assert_page_contains(preview_measure_page, page.title)
    assert_page_contains(preview_measure_page, page.measure_summary)
    assert_page_contains(preview_measure_page, page.summary)
    """
    ADD A DIMENSION
    Save some dimension data
    """
    edit_measure_page.get()
    assert edit_measure_page.is_current()

    dimension = RandomDimension()

    edit_measure_page.click_add_dimension()
    edit_measure_page.wait_until_url_contains("/dimension/new")

    create_dimension_page = DimensionAddPage(driver)

    create_dimension_page.set_title(dimension.title)
    create_dimension_page.set_time_period(dimension.time_period)
    create_dimension_page.set_summary(dimension.summary)
    create_dimension_page.click_save()

    create_dimension_page.wait_for_seconds(1)
    edit_dimension_page = DimensionEditPage(driver)
    assert edit_dimension_page.is_current()

    preview_measure_page.get()
    edit_dimension_page.wait_until_url_does_not_contain("/cms/")
    assert_page_contains(preview_measure_page, dimension.title)
    assert_page_contains(preview_measure_page, dimension.time_period)
    assert_page_contains(preview_measure_page, dimension.summary)
    """
    EDIT A DIMENSION
    """
    edit_dimension_page.get()
    edit_dimension_page.wait_for_seconds(1)
    assert edit_dimension_page.is_current()

    edit_dimension_page.set_summary("some updated text")
    edit_dimension_page.click_update()

    assert edit_dimension_page.is_current()

    preview_measure_page.get()
    edit_dimension_page.wait_until_url_does_not_contain("/cms/")
    assert_page_contains(preview_measure_page, "some updated text")
    """
    CHART BUILDER
    test content has been moved to a separate set of functional tests
    """
    """
    CREATE A SIMPLE TABLE
    """
    edit_dimension_page.get()
    edit_dimension_page.wait_for_seconds(1)
    assert edit_dimension_page.is_current()
    edit_dimension_page.click_create_table()
    edit_dimension_page.wait_until_url_contains("create-table")

    table_builder_page = TableBuilderPage(driver)
    assert table_builder_page.is_current()

    inject_data(driver, simple_data)
    table_builder_page.click_data_okay()
    table_builder_page.wait_for_seconds(1)
    table_builder_page.select_column(1, "Value")
    table_builder_page.wait_for_seconds(1)
    table_builder_page.click_save()
    table_builder_page.wait_for_seconds(1)
    """
    CREATE A TABLE WITH TWO COLUMNS
    """
    table_builder_page.get()
    table_builder_page.click_data_edit()
    table_builder_page.wait_for_seconds(1)
    inject_data(driver, ethnicity_by_gender_data)
    table_builder_page.click_data_okay()
    table_builder_page.wait_for_seconds(1)

    table_builder_page.select_data_style("Use ethnicity for rows")
    table_builder_page.wait_for_seconds(1)
    table_builder_page.select_columns_when_ethnicity_is_row("Gender")
    table_builder_page.select_column(1, "Value")
    table_builder_page.select_column(2, "Gender")
    table_builder_page.wait_for_seconds(1)

    table_builder_page.click_save()
    table_builder_page.wait_for_seconds(1)
def run_complex_table_by_column_scenario(table_builder_page, driver):
    """
    CHART BUILDER CAN BUILD GROUPED BAR TABLES with ethnicity for sub-groups using ethnicity for column groups
    """
    """
    GIVEN some basic data appropriate for building grouped bar tables
    """
    table_builder_page.refresh()
    inject_data(driver, ethnicity_by_gender_data)
    table_builder_page.click_data_okay()
    """
    WHEN we set up the complex table options for a use ethnicity by column setup
    """
    table_builder_page.select_data_style("Use ethnicity for columns")
    table_builder_page.wait_for_seconds(1)
    table_builder_page.select_rows_when_ethnicity_is_columns("Gender")
    table_builder_page.select_column(1, "Value")
    table_builder_page.select_column(2, "Gender")
    table_builder_page.wait_for_seconds(1)
    """
    AND a complex table exists with ethnicities across the columns, gender on the left, and sub-columns of value and gender.
    """
    assert table_builder_page.table_headers() == [
        "Gender", "Asian", "Black", "Mixed", "White", "Other"
    ]
    assert table_builder_page.table_secondary_headers() == [
        "Value",
        "Gender",
        "Value",
        "Gender",
        "Value",
        "Gender",
        "Value",
        "Gender",
        "Value",
        "Gender",
    ]
    assert table_builder_page.table_column_contents(1) == ["F", "M"]
    assert table_builder_page.table_column_contents(2) == ["4", "5"]
    assert table_builder_page.table_column_contents(3) == ["F", "M"]
    assert table_builder_page.table_column_contents(4) == ["1", "4"]
    assert table_builder_page.table_column_contents(5) == ["F", "M"]
    """
    AND the first column setting has changed to the name of the selected row column
    """
    assert table_builder_page.table_index_column_name() == "Gender"
    assert table_builder_page.input_index_column_name() == "Gender"
    """
    WHEN we change to an ethnicity is rows setup
    """
    table_builder_page.select_data_style("Use ethnicity for rows")
    # table_builder_page.wait_for_seconds(1)
    table_builder_page.select_columns_when_ethnicity_is_row("Gender")
    # table_builder_page.wait_for_seconds(1)
    """
    THEN the first column reverts to ethnicity
    """
    assert table_builder_page.table_index_column_name() == "Ethnicity"
    assert table_builder_page.input_index_column_name() == "Ethnicity"
    """
    WHEN we change back to the ethnicity is columns setup
    """
    table_builder_page.select_data_style("Use ethnicity for columns")
    """
    THEN the first column reverts to gender
    """
    assert table_builder_page.table_index_column_name() == "Gender"
    assert table_builder_page.input_index_column_name() == "Gender"
    """
    WHEN we change the value of the first column in the input box
    """
    table_builder_page.set_input_index_column_name("Custom first column")
    """
    THEN it changes the value of the first column in the table
    """
    assert table_builder_page.table_index_column_name(
    ) == "Custom first column"
    """
    WHEN we change back to the ethnicity is rows setup
    """
    table_builder_page.select_data_style("Use ethnicity for rows")
    """
    THEN the first column name does not change
    """
    assert table_builder_page.table_index_column_name(
    ) == "Custom first column"
    assert table_builder_page.input_index_column_name(
    ) == "Custom first column"
    """
    WHEN we change back to the ethnicity is columns setup
    """
    table_builder_page.select_data_style("Use ethnicity for columns")
    """
    THEN the first column name does not change
    """
    assert table_builder_page.table_index_column_name(
    ) == "Custom first column"
    assert table_builder_page.input_index_column_name(
    ) == "Custom first column"
def run_simple_table_scenarios(table_builder_page, driver):
    """
    SCENARIO 1. CREATE A SIMPLE TABLE
    """
    """
    GIVEN some basic data appropriate for building simple tables
    """
    inject_data(driver, simple_data)
    table_builder_page.click_data_okay()
    table_builder_page.wait_for_seconds(1)
    """
    THEN the edit screen should get set up
    """
    assert table_builder_page.source_contains("5 rows by 2 columns")
    assert len(table_builder_page.get_ethnicity_settings_list()) == 3
    assert table_builder_page.get_ethnicity_settings_value(
    ) == "ONS 2011 - 5+1"
    assert table_builder_page.input_index_column_name() == "Ethnicity"
    """
    THEN we select the column to display
    """
    table_builder_page.select_column(1, "Value")
    table_builder_page.wait_for_seconds(1)
    """
    THEN we should have a table with appropriate headers
    """
    assert table_builder_page.table_headers() == ["Ethnicity", "Value"]
    assert table_builder_page.table_index_column_name() == "Ethnicity"
    """
    AND we should have a table with appropriate column values
    """
    assert table_builder_page.table_column_contents(1) == [
        "Asian", "Black", "Mixed", "White", "Other"
    ]
    assert table_builder_page.table_column_contents(2) == [
        "5", "4", "3", "2", "1"
    ]
    """
    WHEN we select an alternative ethnicity set up
    """
    table_builder_page.select_ethnicity_settings_value("ONS 2001 - 5+1")
    table_builder_page.wait_for_seconds(1)
    """
    THEN the ethnicities that appear in the tables get changed
    """
    assert table_builder_page.table_column_contents(1) == [
        "Asian", "Black", "Mixed", "White", "Other inc Chinese"
    ]
    """
    WHEN we select an alternative first column name
    """
    table_builder_page.set_input_index_column_name("Custom first column")
    table_builder_page.wait_for_seconds(1)
    """
    THEN the first column name in the table is changed
    """
    assert table_builder_page.table_index_column_name(
    ) == "Custom first column"
    """
    SCENARIO 2. CREATE A CHART WITH DISORDERLY DATA
    """
    """
    GIVEN a shuffled version of our simple data
    """
    table_builder_page.refresh()
    inject_data(driver, shuffle_table(simple_data))
    table_builder_page.click_data_okay()
    """
    THEN we select the column to display
    """
    table_builder_page.select_column(1, "Value")
    table_builder_page.wait_for_seconds(1)
    """
    THEN the ethnicities are correctly sorted automatically
    """
    assert table_builder_page.table_column_contents(1) == [
        "Asian", "Black", "Mixed", "White", "Other"
    ]
    return table_builder_page