-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(build/ui): move screenshot definitions into isolated js scripts
- Loading branch information
Showing
8 changed files
with
140 additions
and
47 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,51 @@ | ||
const { chromium } = require('playwright'); | ||
const { exec } = require('child_process'); | ||
const fs = require('fs'); | ||
|
||
const fliptAddr = process.env.FLIPT_ADDRESS ?? 'http://localhost:8080'; | ||
|
||
const go = async (page, path) => { | ||
await page.goto(fliptAddr+path); | ||
}; | ||
|
||
const screenshot = async (page, name) => { | ||
await page.screenshot({ path: 'screenshots/'+name }); | ||
}; | ||
|
||
const sleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay)); | ||
|
||
(async () => { | ||
const capture = async function(name, fn) { | ||
try { | ||
const path = `${__dirname}/screenshot/fixtures/${name}.yml`; | ||
if (fs.existsSync(path)) { | ||
exec(`flipt import --address=${fliptAddr} ${path}`, (error, stdout, stderr) => { | ||
if (error) { | ||
console.error(`error: ${error.message}`); | ||
return; | ||
} | ||
|
||
if (stderr) { | ||
console.error(`stderr: ${stderr}`); | ||
return; | ||
} | ||
|
||
console.log(`stdout:\n${stdout}`); | ||
}) | ||
} | ||
} catch (err) { | ||
// ignore and we will just skip seeding | ||
console.debug(err); | ||
} | ||
|
||
const browser = await chromium.launch({ headless: true }); | ||
const context = await browser.newContext({ | ||
viewport: { width: 1280, height: 720 }, | ||
}); | ||
const page = await context.newPage(); | ||
|
||
// Create Flag | ||
await go(page, '/'); | ||
await page.getByRole('button', { name: 'New Flag' }).click(); | ||
await page.getByLabel('Name').fill('New Login'); | ||
await page.getByLabel('Key').fill('new-login'); | ||
await page.getByLabel('Description').fill('Enables the new login page for users'); | ||
await screenshot(page, 'create_flag.png'); | ||
|
||
await page.getByRole('button', { name: 'Create' }).click(); | ||
|
||
// Create Variant | ||
await page.getByRole('button', { name: 'New Variant' }).click(); | ||
await page | ||
.getByRole('dialog', { name: 'New Variant' }) | ||
.locator('#key') | ||
.fill('big-blue-login-button'); | ||
await page | ||
.getByRole('dialog', { name: 'New Variant' }) | ||
.locator('#name') | ||
.fill('Big Blue Login Button'); | ||
|
||
await page.goto(fliptAddr); | ||
await fn(page); | ||
await sleep(2000); | ||
|
||
await screenshot(page, 'create_variant.png'); | ||
await page.getByRole('button', { name: 'Create' }).click(); | ||
|
||
await page.getByRole('link', { name: 'Segments' }).click(); | ||
await page.getByRole('button', { name: 'New Segment' }).click(); | ||
await page.getByLabel('Name').fill('All Users'); | ||
await page.getByLabel('Key').fill('all-users'); | ||
|
||
await sleep(2000); | ||
|
||
await screenshot(page, 'create_segment.png'); | ||
await screenshot(page, `${name}.png`); | ||
|
||
await context.close(); | ||
await browser.close(); | ||
})(); | ||
}; | ||
|
||
module.exports = { capture }; |
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,16 @@ | ||
const { capture } = require('../screenshot.js'); | ||
|
||
(async() => { | ||
await capture('create_constraint', async (page) => { | ||
await page.getByRole('link', { name: 'Segments' }).click(); | ||
await page.getByRole('link', { name: 'all-users' }).click(); | ||
await page.getByRole('button', { name: 'New Constraint' }).click(); | ||
await page.getByLabel('Property').fill('admin'); | ||
await page | ||
.getByRole('combobox', { name: 'Type' }) | ||
.selectOption('BOOLEAN_COMPARISON_TYPE'); | ||
await page | ||
.getByRole('combobox', { name: 'Operator' }) | ||
.selectOption('notpresent'); | ||
}); | ||
})(); |
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,10 @@ | ||
const { capture } = require('../screenshot.js'); | ||
|
||
(async() => { | ||
await capture('create_flag', async (page) => { | ||
await page.getByRole('button', { name: 'New Flag' }).click(); | ||
await page.getByLabel('Name').fill('New Login'); | ||
await page.getByLabel('Key').fill('new-login'); | ||
await page.getByLabel('Description').fill('Enables the new login page for users'); | ||
}); | ||
})(); |
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,10 @@ | ||
const { capture } = require('../screenshot.js'); | ||
|
||
(async() => { | ||
await capture('create_segment', async (page) => { | ||
await page.getByRole('link', { name: 'Segments' }).click(); | ||
await page.getByRole('button', { name: 'New Segment' }).click(); | ||
await page.getByLabel('Name').fill('All Users'); | ||
await page.getByLabel('Key').fill('all-users'); | ||
}); | ||
})(); |
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,16 @@ | ||
const { capture } = require('../screenshot.js'); | ||
|
||
(async() => { | ||
await capture('create_variant', async (page) => { | ||
await page.getByRole('link', { name: 'new-login' }).click(); | ||
await page.getByRole('button', { name: 'New Variant' }).click(); | ||
await page | ||
.getByRole('dialog', { name: 'New Variant' }) | ||
.locator('#key') | ||
.fill('big-blue-login-button'); | ||
await page | ||
.getByRole('dialog', { name: 'New Variant' }) | ||
.locator('#name') | ||
.fill('Big Blue Login Button'); | ||
}); | ||
})(); |
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,4 @@ | ||
namespace: default | ||
segments: | ||
- key: all-users | ||
name: All Users |
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,5 @@ | ||
namespace: default | ||
flags: | ||
- key: new-login | ||
name: New Login | ||
description: Enables the new login page for users |