-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plugin E2E: Add isFeatureToggleEnabled fixture (#612)
- Loading branch information
Showing
5 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/plugin-e2e/src/fixtures/isFeatureToggleEnabled.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { TestFixture } from '@playwright/test'; | ||
import { PluginFixture, PluginOptions } from '../api'; | ||
import { PlaywrightCombinedArgs } from './types'; | ||
|
||
type FeatureToggleFixture = TestFixture< | ||
<T = object>(featureToggle: keyof T) => Promise<boolean>, | ||
PluginFixture & PluginOptions & PlaywrightCombinedArgs | ||
>; | ||
|
||
const isFeatureToggleEnabled: FeatureToggleFixture = async ({ page }, use) => { | ||
await use(async <T = object>(featureToggle: keyof T) => { | ||
const featureToggles: T = await page.evaluate('window.grafanaBootData.settings.featureToggles'); | ||
return Boolean(featureToggles[featureToggle]); | ||
}); | ||
}; | ||
|
||
export default isFeatureToggleEnabled; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/plugin-e2e/tests/datasource/featuretoggles/queryDataHandler.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { expect, test } from '../../../src'; | ||
import { ProvisionFile } from '../../../src/types'; | ||
|
||
test('query data handler', async ({ selectors, panelEditPage, page, readProvision, isFeatureToggleEnabled }) => { | ||
const provisionFile = await readProvision<ProvisionFile>({ filePath: 'datasources/redshift.yaml' }); | ||
await panelEditPage.datasource.set(provisionFile.datasources[0].name!); | ||
await panelEditPage.timeRange.set({ from: '2020-01-31', to: '2020-02-20' }); | ||
|
||
await page.waitForFunction(() => (window as any).monaco); | ||
await panelEditPage.getByTestIdOrAriaLabel(selectors.components.CodeEditor.container).click(); | ||
await page.keyboard.insertText('select * from long_format_example limit 100'); | ||
|
||
const asyncQueryDataHandlerEnabled = await isFeatureToggleEnabled('redshiftAsyncQueryDataSupport'); | ||
if (asyncQueryDataHandlerEnabled) { | ||
// the async query data handler polls the backend until it receives a status of "finished" | ||
const queryStatedResponse = panelEditPage.waitForQueryDataResponse( | ||
(response) => response.ok() && response.body().then((body) => body.includes(`"status":"started"`)) | ||
); | ||
const queryFinishedResponse = panelEditPage.waitForQueryDataResponse( | ||
(response) => response.ok() && response.body().then((body) => body.includes(`"status":"finished"`)) | ||
); | ||
await panelEditPage.refreshPanel(); | ||
await expect(await queryStatedResponse).toBeTruthy(); | ||
await expect(await queryFinishedResponse).toBeTruthy(); | ||
} else { | ||
await expect(panelEditPage.refreshPanel()).toBeOK(); | ||
} | ||
}); |