mvysny / karibu-testing

Vaadin Server-Side Browserless Containerless Unit Testing
Apache License 2.0
111 stars 14 forks source link

How to check that a column is not present in a grid #150

Closed satorstefan closed 1 year ago

satorstefan commented 1 year ago

I want to check that a user will not see some columns of a grid.

The columns have keys.

Maybe a methode like: assertColumnNotVisible(String key) would be helpful?

mvysny commented 1 year ago

Hi, thank you for letting me know!

Perhaps something like assertFalse(GridKt._getColumnByKey(key).isVisible()) would work equally well - it would provide a proper error message if the column with such a key doesn't exist.

Basically, I'm trying to avoid the API duplication. For example, if we would to have assertColumnNotVisible(String key), then we should also have assertColumnSortable(), assertColumnIsFrozen(), assertColumnIsNotFrozen(String key) and a function for every Grid.Column property, which looks like a lot of existing API duplication.

I propose to instead document the assertColumnNotVisible() solution in the README. Would that work for you?

mvysny commented 1 year ago

Documentation added: https://github.com/mvysny/karibu-testing/tree/master/karibu-testing-v10#grid-columns - please let me know whether this works for you.

satorstefan commented 1 year ago

Hello Martin,

assertFalse(GridKt._getColumnByKey(getGrid(), "delete").isVisible());

but this results in an AssertionError: java.lang.AssertionError: Grid[dataprovider='CallbackDataProvider', @multi-sort-priority='prepend', @theme='no-row-borders compact no-border column-dividers second-grid-theme']: No such column with key 'delete'; available columns: [name, typ, factor, changedAt]

satorstefan commented 1 year ago

Also I think there is a typo in the documentation now. This is not the right code snippet: assertFalse(GridKt._getColumnByKey(grid, "delete"));

satorstefan commented 1 year ago

This seems to work:

 assertThrows(AssertionError.class, () -> {
        GridKt._getColumnByKey(getGrid(), "delete");
    });
mvysny commented 1 year ago

You need to replace "delete" with the appropriate key of your Grid's Column.

satorstefan commented 1 year ago

GridKt._getColumnByKey(getGrid(), SafeguardTable.COLUMN_ACTION);

also leads to:

java.lang.AssertionError: Grid[dataprovider='CallbackDataProvider', @multi-sort-priority='prepend', @theme='no-row-borders compact no-border column-dividers second-grid-theme']: No such column with key 'action'; available columns: [name, typ, factor, changedAt]

This works. So maybe you should update the documentation again?

    assertThrows(AssertionError.class, () -> {
        GridKt._getColumnByKey(getGrid(), SafeguardTable.COLUMN_ACTION);
    });
mvysny commented 1 year ago

Please try GridKt._getColumnByKey(getGrid(), "changedAt"); or some other column that exists on the grid.

satorstefan commented 1 year ago

That works, but I want to check that a column is NOT visible/available.

mvysny commented 1 year ago

If you wish to assert that a column with given key doesn't exist, please use assertNull(grid.getColumnByKey(key)).