Skip to content

Commit

Permalink
feat: introduce more commands to formatter (#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshshanmugam authored Sep 27, 2021
1 parent 12539fd commit 8a84711
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
10 changes: 6 additions & 4 deletions __tests__/formatter/__snapshots__/javascript.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
exports[`Synthetics JavaScript formatter inline journeys 1`] = `
"step('Go to https://vigneshh.in/', async () => {
await page.goto('https://vigneshh.in/');
await page.click('a:has-text(\\"Go to bag\\")');
expect(await page.textContent('text=Babel Minify')).toBe('babel');
expect(await page.isVisible('text=Babel Minify')).toBeTruthy();
expect(await page.isEditable('text=Babel Minify')).toBeTruthy();
expect(await page.textContent('text=Babel Minify')).toMatch('Babel');
});
step('Click text=Babel Minify', async () => {
const [page1] = await Promise.all([
Expand All @@ -25,8 +26,9 @@ exports[`Synthetics JavaScript formatter suite journeys 1`] = `
journey('Recorded journey', async ({ page, context }) => {
step('Go to https://vigneshh.in/', async () => {
await page.goto('https://vigneshh.in/');
await page.click('a:has-text(\\"Go to bag\\")');
expect(await page.textContent('text=Babel Minify')).toBe('babel');
expect(await page.isVisible('text=Babel Minify')).toBeTruthy();
expect(await page.isEditable('text=Babel Minify')).toBeTruthy();
expect(await page.textContent('text=Babel Minify')).toMatch('Babel');
});
step('Click text=Babel Minify', async () => {
const [page1] = await Promise.all([
Expand Down
24 changes: 17 additions & 7 deletions __tests__/formatter/javascript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,24 @@ const recorderActions: Array<ActionInContext> = [
isMainFrame: true,
frameUrl: 'https://vigneshh.in/',
action: {
name: 'click',
selector: 'a:has-text("Go to bag")',
name: 'assert',
isAssert: true,
command: 'isVisible',
selector: 'text=Babel Minify',
signals: [],
},
},
{
pageAlias: 'page',
isMainFrame: true,
frameUrl: 'https://vigneshh.in/',
action: {
name: 'assert',
isAssert: true,
command: 'isEditable',
selector: 'text=Babel Minify',
signals: [],
button: 'left',
modifiers: 0,
clickCount: 1,
},
committed: true,
},
{
pageAlias: 'page',
Expand All @@ -73,7 +83,7 @@ const recorderActions: Array<ActionInContext> = [
isAssert: true,
command: 'textContent',
selector: 'text=Babel Minify',
value: 'babel',
value: 'Babel',
signals: [],
},
},
Expand Down
7 changes: 6 additions & 1 deletion src/formatter/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,16 @@ function toAssertCall(pageAlias, action) {
const { command, selector, value } = action;
switch (command) {
case 'textContent':
case 'innerText':
return `expect(await ${pageAlias}.${command}(${quote(
selector
)})).toBe(${quote(value)});`;
)})).toMatch(${quote(value)});`;
case 'isVisible':
case 'isHidden':
case 'isChecked':
case 'isEditable':
case 'isEnabled':
case 'isDisabled':
return `expect(await ${pageAlias}.${command}(${quote(
selector
)})).toBeTruthy();`;
Expand Down

0 comments on commit 8a84711

Please sign in to comment.