-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: happy path playwright query tests #290
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool stuff! Thanks for contributing again! I'll let Kevin take another look in case I'm missing anything. I've shared a few gut reactions on code-style but I'm not that experienced with playwright so I'm not confident they are useful opinions or not. Might be worth sticking with what's here and seeing how it goes? Will defer to @kevinwcyu for a final approval/thoughts.
@@ -102,6 +102,7 @@ export class ListAssetsQueryEditor extends PureComponent<Props, State> { | |||
<div className="gf-form"> | |||
<InlineField label="Model ID" labelWidth={firstLabelWith} grow={true}> | |||
<Select | |||
aria-label="Model ID" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it make sense to use data-testid
instead of an aria label if the sole purpose is for testing? I think we want to only add aria labels it we are trying to fix an accessibility issue.
I also see we have the option to link the inlinefield label: grafana/grafana#31230
Not sure if that works with the new e2e package but might be worth looking into
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These ARIA labels are actually already used with the new style of components, but it seems we forgot to add them to both places in multiple instances. For example, see https://github.com/grafana/iot-sitewise-datasource/blob/main/src/components/query/ListAssetsQueryEditor.tsx#L74 for the model ID label.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @sarahzinger, that's a good call out.
I found some additional docs around testing that suggest using htmlFor
on the label component, <InlineField />
in this case, and using inputId
on the <Select />
component.
I tried it out and the label
does have the correct association to the input
element when using htmlFor
and inputId
. The getByLabel
locator can be used to click on the <Select />
.
Sorry @tracy-french, I suggested using the aria-label
along with the getByTestIdOrAriaLabel
function for the form fields in your previous E2E PR, but I think Sarah's suggestion is a better one for us to follow since an accessible label already exists and can be connected with htmlFor
and inputId
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated all of the locators to use page.getByLabel
and updated the JSX to use inputId
where needed.
}, | ||
}); | ||
|
||
export { test, expect }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm.... Maybe this is a personal style preference and a lack of familiarity with playwright conventions but I am not sure this abstraction is easier to read/write tests with? It definitely dries up the code, but if a test does fail or you need to write your own test you now need to know to look in a helper file to find this fixture and then look at queryeditorpage and then there might be a worry that a small change in one could affect other tests?
I guess when it comes to tests I almost don't mind a bit of redundancy if it makes them easier to read. But I don't want to block for a personal preference.
Idk what do you think @kevinwcyu in your research does this kind of best practice for playwright you think? I'm happy to go with whatever you all think makes the most sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely, makes sense. I'm a fan of using fixtures, but this is indeed a very simple fixture and does not currently add much value beyond preventing you from having to instantiate the page object model.
As the test cases are expanded, something which may add a lot of value are test fixtures which reduce setup boilerplate when we're trying to test a particular state of the query editor multiple times. For instance, a getPropertyValueQueryEditor
providing a query editor with the "Get property value" query pre-selected and exposing a page object model with the locators for form elements specific to only that query (i.e., no resolution/aggregation/etc.). Or even more valuable would be a fixture with an asset property (or multiple) already selected so that you can perform a series a tests without explicitly going through the flow of selecting an asset and then selecting a property in every test.
But those more valuable features don't need what I did in this PR now lol. If we want to wait until the value is clear, I am fine removing the fixture from this change. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this structure provides a good foundation for code standard/style 👍 We might not see the value on the current scale but doesn't hurt to keep it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's useful to include this for interacting with the different select elements in the query editor, especially for the select elements that load options asynchronously. I'd be happy to keep it in since it does follow Playwright conventions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok cool, let's give it a go, and see how it works out for us!
@sarahzinger Thank you for reviewing! :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Lay down an excellent foundation and setting the code style for tests
}, | ||
}); | ||
|
||
export { test, expect }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this structure provides a good foundation for code standard/style 👍 We might not see the value on the current scale but doesn't hurt to keep it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, the page object model for the query editor looks really good. Just a few minor suggestions.
@@ -102,6 +102,7 @@ export class ListAssetsQueryEditor extends PureComponent<Props, State> { | |||
<div className="gf-form"> | |||
<InlineField label="Model ID" labelWidth={firstLabelWith} grow={true}> | |||
<Select | |||
aria-label="Model ID" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @sarahzinger, that's a good call out.
I found some additional docs around testing that suggest using htmlFor
on the label component, <InlineField />
in this case, and using inputId
on the <Select />
component.
I tried it out and the label
does have the correct association to the input
element when using htmlFor
and inputId
. The getByLabel
locator can be used to click on the <Select />
.
Sorry @tracy-french, I suggested using the aria-label
along with the getByTestIdOrAriaLabel
function for the form fields in your previous E2E PR, but I think Sarah's suggestion is a better one for us to follow since an accessible label already exists and can be connected with htmlFor
and inputId
.
}, | ||
}); | ||
|
||
export { test, expect }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's useful to include this for interacting with the different select elements in the query editor, especially for the select elements that load options asynchronously. I'd be happy to keep it in since it does follow Playwright conventions.
tests/queryEditor.page.ts
Outdated
* Query Editor page object model testing utility providing properties and | ||
* methods for common locators and actions. | ||
*/ | ||
export class QueryEditorPage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export class QueryEditorPage { | |
export class QueryEditor { |
Minor nit: can this be named QueryEditor
since it's a component within the PanelEditPage
. It would be good to name this file queryEditor.model.ts
along with this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
127ea79
to
f64f4e4
Compare
What this PR does / why we need it: This change includes happy path playwright query tests for all seven queries exposed by the query editor. The work includes:
QueryEditor
page object model test utility used to reduce duplication within tests and make it easier to write and maintain tests.queryEditor
test fixture to remove the need to instantiate theQueryEditor
object model explicitly in every test.Next steps: