-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adapt buildDescription for selector naming
- Loading branch information
Showing
2 changed files
with
35 additions
and
135 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,117 +1,51 @@ | ||
import { | ||
buildDescription, | ||
describeDoc, | ||
} from '../../src/build-code/buildDescription'; | ||
import { Step } from '../../src/types'; | ||
import { Doc } from '@jperl/html-parse-stringify'; | ||
import { buildDescription } from '../../src/build-code/buildDescription'; | ||
|
||
const baseStep: Step = { | ||
action: 'click', | ||
htmlSelector: '', | ||
target: { | ||
name: 'input', | ||
type: 'tag', | ||
}, | ||
index: 0, | ||
page: 0, | ||
}; | ||
|
||
const doc = (attrs: object): Doc => ({ | ||
const doc = (attrs: object = {}): Doc => ({ | ||
attrs, | ||
name: 'input', | ||
type: 'tag', | ||
voidElement: false, | ||
}); | ||
|
||
describe('buildDescription', () => { | ||
it('excludes target name if it does not exist', () => { | ||
expect(buildDescription(baseStep)).toBe('click input'); | ||
}); | ||
|
||
it('uses alt attribute if no other attributes specified', () => { | ||
const step: Step = { | ||
...baseStep, | ||
target: { | ||
attrs: { | ||
alt: 'spirit', | ||
}, | ||
name: 'img', | ||
type: 'tag', | ||
}, | ||
}; | ||
|
||
expect(buildDescription(step)).toBe('click "spirit" img'); | ||
}); | ||
|
||
it('formats clear input', () => { | ||
const step: Step = { | ||
...baseStep, | ||
action: 'fill', | ||
value: null, | ||
}; | ||
|
||
expect(buildDescription(step)).toEqual('clear input'); | ||
}); | ||
|
||
it('formats type input', () => { | ||
const step: Step = { | ||
...baseStep, | ||
action: 'type', | ||
value: 'something', | ||
}; | ||
|
||
expect(buildDescription(step)).toEqual('type into input'); | ||
}); | ||
|
||
it('formats scroll action', () => { | ||
const step: Step = { | ||
...baseStep, | ||
action: 'scroll', | ||
}; | ||
|
||
expect(buildDescription(step)).toBe(''); | ||
}); | ||
|
||
it('formats select action', () => { | ||
const step: Step = { | ||
...baseStep, | ||
action: 'select', | ||
}; | ||
it('escapes single quotes', () => { | ||
expect(buildDescription(doc({ labels: "someone's" }))).toBe( | ||
'someones_input', | ||
); | ||
|
||
expect(buildDescription(step)).toBe('select'); | ||
expect(buildDescription(doc({ labels: "'" }))).toBe('input'); | ||
}); | ||
|
||
it('skips formatting press', () => { | ||
const step: Step = { | ||
...baseStep, | ||
action: 'press', | ||
value: 'Enter', | ||
}; | ||
|
||
expect(buildDescription(step)).toEqual(''); | ||
it('excludes target name if it does not exist', () => { | ||
expect(buildDescription(doc())).toBe('input'); | ||
}); | ||
}); | ||
|
||
describe('describeDoc', () => { | ||
it('formats labels', () => { | ||
expect(describeDoc(doc({ labels: 'name username' }))).toBe( | ||
' "name username"', | ||
expect(buildDescription(doc({ labels: 'name username' }))).toBe( | ||
'name_username_input', | ||
); | ||
}); | ||
|
||
it('shortens target name if needed', () => { | ||
expect(describeDoc(doc({ innertext: `sign in${'x'.repeat(200)}` }))).toBe( | ||
' "sign inxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx..."', | ||
); | ||
expect( | ||
buildDescription(doc({ innertext: `sign in${'x'.repeat(100)}` })), | ||
).toBe('sign_inxxxxxxxx_input'); | ||
}); | ||
|
||
it('escapes single quotes', () => { | ||
expect(describeDoc(doc({ labels: "someone's" }))).toBe(` "someones"`); | ||
|
||
expect(describeDoc(doc({ labels: "'" }))).toBe(''); | ||
it('removes invisible characters', () => { | ||
expect(buildDescription(doc({ labels: '' }))).toBe('input'); | ||
}); | ||
|
||
it('removes invisible characters', () => { | ||
expect(describeDoc(doc({ labels: '' }))).toBe(''); | ||
it('uses alt attribute if no other attributes specified', () => { | ||
expect( | ||
buildDescription({ | ||
attrs: { | ||
alt: 'spirit', | ||
}, | ||
name: 'img', | ||
type: 'tag', | ||
}), | ||
).toBe('spirit_img'); | ||
}); | ||
}); |