Refactor toast message by test subj (#176889)

## Summary

Refactor `toastMessageByTestSubj` method to two methods, instead of
being nested.


## Why

We feel that the this method is not ergonomic to our purposes.
So, let's simplify it so that our devs can make use of it, easily.
This is apart of myriad efforts to clean things up and centralize.

Lastly, it's a follow up pr to [[FTR] Refactor toasts svc
](https://github.com/elastic/kibana/pull/174222)

Note: The flaky runner was [run against the only config that uses these
two additional methods,
successfully](https://github.com/elastic/kibana/pull/176889#issuecomment-1943740147).

Resolves https://github.com/elastic/kibana/issues/176570

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Dzmitry Lemechko <dzmitry.lemechko@elastic.co>
This commit is contained in:
Tre 2024-02-19 09:34:57 +00:00 committed by GitHub
parent 31517ef141
commit 445f4bc288
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 22 deletions

View file

@ -39,20 +39,6 @@ export class ToastsService extends FtrService {
return { title, message };
}
public async toastMessageByTestSubj(testSubj = 'csp:toast-success') {
const testSubjSvc = this.testSubjects;
return {
async getElement(): Promise<WebElementWrapper> {
return await testSubjSvc.find(testSubj);
},
async clickToastMessageLink(linkTestSubj = 'csp:toast-success-link') {
const element = await this.getElement();
const link = await element.findByTestSubject(linkTestSubj);
await link.click();
},
};
}
/**
* Dismiss a specific toast from the toast list. Since toasts usually should time out themselves,
* you only need to call this for permanent toasts (e.g. error toasts).
@ -123,7 +109,7 @@ export class ToastsService extends FtrService {
});
}
public async getElementByIndex(index: number): Promise<WebElementWrapper> {
public async getElementByIndex(index: number = 1): Promise<WebElementWrapper> {
return await (await this.getGlobalList()).findByCssSelector(`.euiToast:nth-child(${index})`);
}

View file

@ -156,13 +156,15 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await misconfigurationsFlyout.getVisibleText('csp:findings-flyout-detection-rule-count')
).to.be('1 detection rule');
const toastMessage = await (await toasts.toastMessageByTestSubj()).getElement();
expect(toastMessage).to.be.ok();
const toastMessageElement = await toasts.getElementByIndex();
expect(toastMessageElement).to.be.ok();
const toastMessageTitle = await toastMessage.findByTestSubject('csp:toast-success-title');
const toastMessageTitle = await toastMessageElement.findByTestSubject(
'csp:toast-success-title'
);
expect(await toastMessageTitle.getVisibleText()).to.be(ruleName1);
await (await toasts.toastMessageByTestSubj()).clickToastMessageLink();
await testSubjects.click('csp:toast-success-link');
const rulePageTitle = await testSubjects.find('header-page-title');
expect(await rulePageTitle.getVisibleText()).to.be(ruleName1);
@ -183,13 +185,13 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await misconfigurationsFlyout.getVisibleText('csp:findings-flyout-detection-rule-count')
).to.be('1 detection rule');
const toastMessage = await (await toasts.toastMessageByTestSubj()).getElement();
const toastMessage = await toasts.getElementByIndex();
expect(toastMessage).to.be.ok();
const toastMessageTitle = await toastMessage.findByTestSubject('csp:toast-success-title');
expect(await toastMessageTitle.getVisibleText()).to.be(ruleName1);
await (await toasts.toastMessageByTestSubj()).clickToastMessageLink();
await testSubjects.click('csp:toast-success-link');
const rulePageTitle = await testSubjects.find('header-page-title');
expect(await rulePageTitle.getVisibleText()).to.be(ruleName1);
@ -200,7 +202,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await latestFindingsTable.openFlyoutAt(0);
await misconfigurationsFlyout.clickTakeActionCreateRuleButton();
await (await toasts.toastMessageByTestSubj()).clickToastMessageLink();
await testSubjects.click('csp:toast-success-link');
const rulePageDescription = await testSubjects.find(
'stepAboutRuleDetailsToggleDescriptionText'