diff --git a/CHANGELOG.md b/CHANGELOG.md index 78f6e54f..69379866 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -168,6 +168,8 @@ check vscode pylance, mypy, jetbrains qodana... ### DOING: draft Element descriptors POC? +#### TODO: decide on lru_cache vs set attr on instance... + ### Deprecated conditions - `be.present` in favor of `be.present_in_dom` diff --git a/tests/examples/pom/test_material_ui__react_x_data_grid__mit.py b/tests/examples/pom/test_material_ui__react_x_data_grid__mit.py index 594de3d1..559e338f 100644 --- a/tests/examples/pom/test_material_ui__react_x_data_grid__mit.py +++ b/tests/examples/pom/test_material_ui__react_x_data_grid__mit.py @@ -6,7 +6,7 @@ class DataGridMIT: grid = Element('[role=grid]') - headers = grid.all('[role=columnheader]') + header = grid.element('.MuiDataGrid-columnHeaders') toggle_all_checkbox = header.element('.PrivateSwitchBase-input') ''' @@ -14,24 +14,23 @@ class DataGridMIT: toggle_all = headers.ElementBy(have.attribute('data-field').value('__check__')) toggle_all_checkbox = toggle_all.Element('[type=checkbox]') ''' + column_headers = grid.all('[role=columnheader]') + + footer = Element('.MuiDataGrid-footerContainer') + selected_rows_count = footer.element('.MuiDataGrid-selectedRowCount') + pagination = footer.element('.MuiTablePagination-root') + pagination_rows_displayed = pagination.element('.MuiTablePagination-displayedRows') + page_to_right = pagination.element('[data-testid=KeyboardArrowRightIcon]') + page_to_left = pagination.element('[data-testid=KeyboardArrowLeftIcon]') + content = grid.element('[role=rowgroup]') rows = content.all('[role=row]') _cells_selector = '[role=gridcell]' cells = content.all(_cells_selector) editing_cell_input = content.element('.MuiDataGrid-cell--editing').element('input') - ''' - # DONE: now the following works... - # it failed previously because content.element('.MuiDataGrid-cell--editing') - # couldn't be "resolved", because has no name, was not actually used - # as a descriptor - editing_cell_input = content.element('.MuiDataGrid-cell--editing').element('input') - # this will work, by the way: - editing_cell = content.element('.MuiDataGrid-cell--editing') - editing_cell_input = editing_cell.element('input') - # the following worked - editing_cell_input = Element('input').within(lambda self: self.content.element('.MuiDataGrid-cell--editing')) - # so we fixed it incorporating this idea into the code of descriptor.element - ''' + + def __init__(self, context): + self.context = context def cells_of_row(self, number, /): return self.rows[number - 1].all(self._cells_selector) @@ -39,9 +38,9 @@ def cells_of_row(self, number, /): # todo: support int for column def cell(self, *, row, column_data_field=None, column=None): if column: - column_data_field = self.headers.element_by(have.exact_text(column)).get( - query.attribute('data-field') - ) + column_data_field = self.column_headers.element_by( + have.exact_text(column) + ).get(query.attribute('data-field')) return self.cells_of_row(row).element_by( have.attribute('data-field').value(column_data_field) @@ -53,16 +52,6 @@ def set_cell(self, *, row, column_data_field=None, column=None, to_text): ).double_click() self.editing_cell_input.perform(command.select_all).type(to_text).press_enter() - footer = Element('.MuiDataGrid-footerContainer') - selected_rows_count = footer.element('.MuiDataGrid-selectedRowCount') - pagination = footer.element('.MuiTablePagination-root') - pagination_rows_displayed = pagination.element('.MuiTablePagination-displayedRows') - page_to_right = pagination.element('[data-testid=KeyboardArrowRightIcon]') - page_to_left = pagination.element('[data-testid=KeyboardArrowLeftIcon]') - - def __init__(self, context): - self.context = context - @pytest.mark.parametrize( 'characters', @@ -70,7 +59,6 @@ def __init__(self, context): DataGridMIT( browser.with_(timeout=2.0).element('#DataGridDemo+* .MuiDataGrid-root') ), - # DataGridMIT.by_id('demo-simple-select'), ], ) def test_material_ui__react_x_data_grid_mit(characters): @@ -80,18 +68,22 @@ def test_material_ui__react_x_data_grid_mit(characters): browser.open('https://mui.com/x/react-data-grid/#DataGridDemo') # THEN - characters.headers.should(have.size(6)) - characters.headers.should( + # - check headers + characters.column_headers.should(have.size(6)) + characters.column_headers.should( have._exact_texts_like( {...}, 'ID', 'First name', 'Last name', 'Age', 'Full name' ) ) + + # - pagination works characters.pagination_rows_displayed.should(have.exact_text('1–5 of 9')) characters.page_to_right.click() characters.pagination_rows_displayed.should(have.exact_text('6–9 of 9')) characters.page_to_left.click() characters.pagination_rows_displayed.should(have.exact_text('1–5 of 9')) + # - toggle all works to select all rows characters.selected_rows_count.should(be.not_.visible) characters.toggle_all_checkbox.should(be.not_.checked) characters.toggle_all_checkbox.click() @@ -101,16 +93,27 @@ def test_material_ui__react_x_data_grid_mit(characters): characters.toggle_all_checkbox.should(be.not_.checked) characters.selected_rows_count.should(be.not_.visible) + # - check rows characters.rows.should(have.size(5)) characters.cells_of_row(1).should( - have._exact_texts_like(..., 'Jon', 'Snow', '14', 'Jon Snow') + have._exact_texts_like({...}, {...}, 'Jon', 'Snow', '14', 'Jon Snow') ) + + # - sorting works + # TODO: implement + + # - filtering works + # TODO: implement + + # - hiding works + # TODO: implement + + # - a cell can be edited characters.set_cell(row=1, column_data_field='firstName', to_text='John') characters.cells_of_row(1).should( - have._exact_texts_like(..., 'John', 'Snow', '14', 'John Snow') + have._exact_texts_like({...}, {...}, 'John', 'Snow', '14', 'John Snow') ) - characters.set_cell(row=1, column='First name', to_text='Jon') characters.cells_of_row(1).should( - have._exact_texts_like(..., 'Jon', 'Snow', '14', 'Jon Snow') + have._exact_texts_like({...}, {...}, 'Jon', 'Snow', '14', 'Jon Snow') )