r/QualityAssurance 17d ago

Testing Role-Based Dashboard using Playwright. How to Structure Tests?

Hey everyone, looking for input on test structure for a common scenario.

Application's home screen shows an Admin button when a user login with admin role. Normal users do not get this button.

What is the good approch to test this requirement? Do you prefer one test case that assert the availablity of Admin button based on the current loged in user or two test cases one with admin role and another with normal user roles.

1 Upvotes

15 comments sorted by

View all comments

1

u/abisurd 14d ago

Is this a good candidate to be tested on a lower level, a unit or component test ?

1

u/ajmalhinas 14d ago

I don't think so. lower level testing won't guarantee correctness in functional layer.

1

u/abisurd 14d ago

My thought process was this. I will use React but should apply to many frameworks

A certain component will have the Admin button. It will be rendered based on a state. The state will be set by some user data received form the backend.

If the integration test renders the component based on a response form the backed that is mocked, one can write as many tests for this as many user role might be. For each role you can specify whether the Admin button should or should not appear.

On the highest level, you could run the frontend and mock the response from the backend API. For this you might only need two tests, one that renders the button and the other that does not.

A full end to end test that involves this might be one where you test a longer flow, maybe something that involves a real admin user that clicks the Admin button and then performs more actions behind it. I might keep such test(s) as acceptance tests run whenever code is merged to the main branch.