-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: making progressions more efficient
- Loading branch information
Ryan Huellen
committed
Sep 17, 2024
1 parent
3969551
commit e73f744
Showing
4 changed files
with
48 additions
and
55 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,62 +1,58 @@ | ||
import type { Locator } from '@playwright/test'; | ||
import type { Page } from '@playwright/test'; | ||
import type { ModifiedField } from '../types/ModifiableField'; | ||
import type { TestOptions } from '../types/TestOptions'; | ||
|
||
import { replaceLast } from './utils/replaceLast'; | ||
|
||
export const progress = async ( | ||
element: Locator, | ||
{ timeout }: TestOptions['decisions']['progressions'], | ||
) => | ||
element.evaluate( | ||
(element) => { | ||
const annotation = element.getAttribute('x-pretzelduck-annotation'); | ||
export const progress = async (page: Page, selector: string) => | ||
page.evaluate((selector) => { | ||
const element = document.querySelector(selector); | ||
|
||
if (annotation == null) { | ||
return; | ||
} | ||
|
||
element.removeAttribute('x-pretzelduck-annotation'); | ||
if (element == null) { | ||
return; | ||
} | ||
|
||
const modifiedField = element.getAttribute( | ||
'x-pretzelduck-modified-field', | ||
) as ModifiedField; | ||
const annotation = element.getAttribute('x-pretzelduck-annotation'); | ||
|
||
switch (modifiedField) { | ||
case 'text-content': { | ||
const { textContent } = element; | ||
if (annotation == null) { | ||
return; | ||
} | ||
|
||
if (textContent == null) { | ||
return; | ||
} | ||
element.removeAttribute('x-pretzelduck-annotation'); | ||
|
||
const newTextContent = replaceLast(textContent, annotation, ''); | ||
const modifiedField = element.getAttribute( | ||
'x-pretzelduck-modified-field', | ||
) as ModifiedField; | ||
|
||
element.textContent = newTextContent; | ||
switch (modifiedField) { | ||
case 'text-content': { | ||
const { textContent } = element; | ||
|
||
break; | ||
if (textContent == null) { | ||
return; | ||
} | ||
case 'placeholder': | ||
case 'value': { | ||
const attribute = modifiedField; | ||
|
||
const attributeValue = element.getAttribute(attribute); | ||
const newTextContent = replaceLast(textContent, annotation, ''); | ||
|
||
if (attributeValue == null) { | ||
return; | ||
} | ||
element.textContent = newTextContent; | ||
|
||
const lastAnnotationIndex = attributeValue.lastIndexOf(annotation); | ||
const newValue = attributeValue.slice(0, lastAnnotationIndex); | ||
break; | ||
} | ||
case 'placeholder': | ||
case 'value': { | ||
const attribute = modifiedField; | ||
|
||
element.setAttribute(attribute, newValue); | ||
const attributeValue = element.getAttribute(attribute); | ||
|
||
break; | ||
if (attributeValue == null) { | ||
return; | ||
} | ||
|
||
const lastAnnotationIndex = attributeValue.lastIndexOf(annotation); | ||
const newValue = attributeValue.slice(0, lastAnnotationIndex); | ||
|
||
element.setAttribute(attribute, newValue); | ||
|
||
break; | ||
} | ||
}, | ||
undefined, | ||
{ | ||
timeout, | ||
}, | ||
); | ||
} | ||
}, selector); |
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