-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added block selection utils for remote control
commit_hash:9800f8c104370b217547e5f42cdeff3c0ea0fb35
- Loading branch information
1 parent
6e54872
commit 7a13012
Showing
7 changed files
with
169 additions
and
19 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
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,27 +1,65 @@ | ||
import { getElementPath } from 'src/utils/dom'; | ||
import { getElementPath, getElementCSSSelector } from 'src/utils/dom'; | ||
import { JSDOMWrapper } from 'src/__tests__/utils/jsdom'; | ||
import chai from 'chai'; | ||
|
||
describe('Element', () => { | ||
const { window } = new JSDOMWrapper(`<span id="ignored"></span> | ||
<span> | ||
<div> | ||
<b id="id">Hello!</b> | ||
</div> | ||
</span>`); | ||
describe('getElementPath', () => { | ||
const { window } = new JSDOMWrapper(`<span id="ignored"></span> | ||
<span> | ||
<div> | ||
<b id="id">Hello!</b> | ||
</div> | ||
</span>`); | ||
|
||
it('get path', () => { | ||
const el = window.document.querySelector('#id') as HTMLElement; | ||
it('get path', () => { | ||
const el = window.document.querySelector('#id') as HTMLElement; | ||
|
||
chai.expect(getElementPath(window, el)).eq('<AW1'); | ||
chai.expect(getElementPath(window, el)).eq('<AW1'); | ||
}); | ||
|
||
it('ignore element', () => { | ||
const el = window.document.querySelector('#id') as HTMLElement; | ||
const ignored = window.document.querySelector( | ||
'#ignored', | ||
) as HTMLElement; | ||
|
||
chai.expect(getElementPath(window, el, ignored)).eq('<AW'); | ||
}); | ||
}); | ||
|
||
it('ignore element', () => { | ||
const el = window.document.querySelector('#id') as HTMLElement; | ||
const ignored = window.document.querySelector( | ||
'#ignored', | ||
) as HTMLElement; | ||
describe('getElementCSSSelector', () => { | ||
it('returns null if it is impossible to get unique selector', () => { | ||
const { window } = new JSDOMWrapper(` | ||
<div> | ||
<div class="non-unique"> | ||
</div> | ||
<div class="non-unique"> | ||
</div> | ||
</div> | ||
`); | ||
|
||
const element = window.document.querySelector( | ||
'.non-unique', | ||
) as HTMLElement; | ||
const result = getElementCSSSelector(window, element); | ||
chai.expect(result).to.be.null; | ||
}); | ||
|
||
chai.expect(getElementPath(window, el, ignored)).eq('<AW'); | ||
it('returns unique multi-component selector with id', () => { | ||
const { window } = new JSDOMWrapper(` | ||
<div> | ||
<div id="unique"> | ||
<div class="non-unique"></div> | ||
</div> | ||
<div class="non-unique"> | ||
</div> | ||
</div> | ||
`); | ||
const element = window.document.querySelector( | ||
'#unique .non-unique', | ||
) as HTMLElement; | ||
const result = getElementCSSSelector(window, element); | ||
chai.expect(result).to.equal('#unique .non-unique'); | ||
}); | ||
}); | ||
}); |
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,15 @@ | ||
import { bindArg } from '../function'; | ||
import { closest } from './closest'; | ||
import { CSS, PATH, getData } from './identifiers'; | ||
import { select } from './select'; | ||
|
||
const BLOCK_SELECTOR = | ||
'div,span,main,section,p,b,h1,h2,h3,h4,h5,h6,td,small,a,i,td,li,q'; | ||
|
||
export const getClosestTextContainer = bindArg(BLOCK_SELECTOR, closest); | ||
export const selectTextContainer = bindArg(BLOCK_SELECTOR, select); | ||
export const getTextContainerData = ( | ||
ctx: Window, | ||
form: HTMLElement, | ||
ignored?: HTMLElement, | ||
) => getData(ctx, form, [PATH, CSS], undefined, ignored); |
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