from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.keys import Keys from nicegui import ui from .screen import Screen def test_update_table(screen: Screen): grid = ui.aggrid({ 'columnDefs': [{'field': 'name'}, {'field': 'age'}], 'rowData': [{'name': 'Alice', 'age': 18}], }) screen.open('/') screen.should_contain('Name') screen.should_contain('Age') screen.should_contain('Alice') screen.should_contain('18') grid.options['rowData'][0]['age'] = 42 screen.wait(0.5) # HACK: try to fix flaky test grid.update() screen.wait(0.5) # HACK: try to fix flaky test screen.should_contain('42') def test_add_row(screen: Screen): grid = ui.aggrid({ 'columnDefs': [{'field': 'name'}, {'field': 'age'}], 'rowData': [], }) ui.button('Update', on_click=grid.update) screen.open('/') grid.options['rowData'].append({'name': 'Alice', 'age': 18}) screen.click('Update') screen.wait(0.5) screen.should_contain('Alice') screen.should_contain('18') grid.options['rowData'].append({'name': 'Bob', 'age': 21}) screen.click('Update') screen.wait(0.5) screen.should_contain('Alice') screen.should_contain('18') screen.should_contain('Bob') screen.should_contain('21') def test_click_cell(screen: Screen): grid = ui.aggrid({ 'columnDefs': [{'field': 'name'}, {'field': 'age'}], 'rowData': [{'name': 'Alice', 'age': 18}], }) grid.on('cellClicked', lambda msg: ui.label(f'{msg["args"]["data"]["name"]} has been clicked!')) screen.open('/') screen.click('Alice') screen.should_contain('Alice has been clicked!') def test_html_columns(screen: Screen): ui.aggrid({ 'columnDefs': [{'field': 'name'}, {'field': 'age'}], 'rowData': [{'name': 'Alice', 'age': 18}], }, html_columns=[0]) screen.open('/') screen.should_contain('Alice') screen.should_not_contain('