Repository: plotly/dash
File: components/dash-table/tests/selenium/test_basic_copy_paste.py (Python)

Code before:
    #     ActionChains(test.driver).send_keys("v").perform()

    for row in range(2):
        for col in range(1):
            assert (
                target.cell(row, col).get_text() == source.cell(row + 9, col).get_text()
            )

    assert test.get_log_errors() == []


def test_tbcp010_copy_from_unselectable_cells_table(test):
    test.start_server(get_app())

    source = test.table("table3")  # this table has cell_selectable=False
    target = test.table("table2")

    # double click cell to (natively) mark the contained text
    source.cell(2, 2).double_click()
    assert source.cell(2, 2).get_text() == test.get_selected_text()

    # copy the source text to clipboard using CTRL+C or COMMAND+C
    test.copy()
    # Uncomment the following two lines if using a Mac computer
    # with test.hold(Keys.COMMAND):
    #     ActionChains(test.driver).send_keys("c").perform()

    # assert the target cell value is different before paste
    target.cell(1, 1).click()
    assert target.cell(1, 1).get_text() != source.cell(2, 2).get_text()

    # assert the target cell value has changed to the pasted value
    test.paste()
    # Uncomment the following two lines if using a Mac computer
    # with test.hold(Keys.COMMAND):
    #     ActionChains(test.driver).send_keys("v").perform()
    assert target.cell(1, 1).get_text() == source.cell(2, 2).get_text()

    assert test.get_log_errors() == []


def test_tbcp011_copy_double_quotes(test):
    test.start_server(get_app())

    source = test.table("table4")
    target = test.table("table2")

    source.cell(0, 0).click()
    with test.hold(Keys.SHIFT):
        source.cell(0, 1).click()


Review comment (bug):
Oh interesting, I thought I had run these tests before on my Mac but I guess not because you're right, they fail. The better way to do this would be to modify `test.paste` etc so they use `Keys.COMMAND` on Mac and `Keys.CONTROL` on others.

In fact we do exactly that in one place (which has an older pattern in other ways):

https://github.com/plotly/dash/blob/29a389245c8c44802d55ba847b6c2e54a28fe2eb/components/dash-table/tests/selenium/conftest.py#L271

We just need to do the same in copy and paste:

https://github.com/plotly/dash/blob/29a389245c8c44802d55ba847b6c2e54a28fe2eb/components/dash-table/tests/selenium/conftest.py#L520-L526

The cleanest way to do this would be to pull the `CMD =` line up to the top of the module and then use `CMD` in copy & paste.

Code after:
    test.start_server(get_app())

    source = test.table("table3")  # this table has cell_selectable=False
    target = test.table("table2")

    # double click cell to (natively) mark the contained text
    source.cell(2, 2).double_click()
    assert source.cell(2, 2).get_text() == test.get_selected_text()

    # copy the source text to clipboard using CTRL+C or COMMAND+C
    test.copy()

    # assert the target cell value is different before paste
    target.cell(1, 1).click()
    assert target.cell(1, 1).get_text() != source.cell(2, 2).get_text()

    # assert the target cell value has changed to the pasted value
    test.paste()
    assert target.cell(1, 1).get_text() == source.cell(2, 2).get_text()

    assert test.get_log_errors() == []


def test_tbcp011_copy_double_quotes(test):
    test.start_server(get_app())

    source = test.table("table4")
    target = test.table("table2")

    source.cell(0, 0).click()
    with test.hold(Keys.SHIFT):
        source.cell(0, 1).click()

    test.copy()
    target.cell(0, 0).click()
    test.paste()

    for row in range(1):
        for col in range(2):
            assert target.cell(row, col).get_text() == source.cell(row, col).get_text()

    assert test.get_log_errors() == []


def test_tbcp011_copy_multiline(test):
    test.start_server(get_app())

    source = test.table("table4")
    target = test.table("table2")

    source.cell(1, 0).click()