Skip to content

Commit

Permalink
[#505] TEST: clean pom test
Browse files Browse the repository at this point in the history
  • Loading branch information
yashaka committed Jul 21, 2024
1 parent 41460f6 commit 35e2d1e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 34 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
71 changes: 37 additions & 34 deletions tests/examples/pom/test_material_ui__react_x_data_grid__mit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,41 @@

class DataGridMIT:
grid = Element('[role=grid]')
headers = grid.all('[role=columnheader]')

header = grid.element('.MuiDataGrid-columnHeaders')
toggle_all_checkbox = header.element('.PrivateSwitchBase-input')
'''
# todo: support also the following:
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)

# 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)
Expand All @@ -53,24 +52,13 @@ 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',
[
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):
Expand All @@ -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()
Expand All @@ -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')
)

0 comments on commit 35e2d1e

Please sign in to comment.