Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
183 changes: 97 additions & 86 deletions lib/tags/requirements.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ module.exports = function yields (hexo, args) {
// {% requirements dom .click %}
// {% requirements dom .children %}

const type = args[0]
const cmd = `<code>${args[1]}()</code>`

const focus = `${cmd} requires the element to be able to receive focus`

const parentCmd = `${cmd} requires being chained off of <code>cy</code>`
const childCmd = `${cmd} requires being chained off a previous command`
const childCmdDom = `${cmd} requires being chained off a command that yields DOM element(s)`
const dualCmd = `${cmd} can be chained off of <code>cy</code> or off another command`
const parentCmd = `${cmd} requires being chained off of <code>cy</code>`

const parentOrChild = () => {
return (args[1] === 'cy.get' || args[1] === 'cy.focused') ? parentCmd : childCmdDom
}
const type = args[0]

const none = () => {
const blurability = () => {
return `<ul>
<li><p>${cmd} has no requirements or default assertions.</p></li>
<li><p>${childCmdDom}.</p></li>
<li><p>${cmd} requires the element to currently have focus.</p></li>
<li><p>${focus}.</p></li>
</ul>`
}

Expand All @@ -31,129 +31,132 @@ module.exports = function yields (hexo, args) {
</ul>`
}

const dom = () => {
const clearability = () => {
return `<ul>
<li><p>${parentOrChild()}.</p></li>
<li><p>${childCmdDom}.</p></li>
<li><p>${cmd} requires the element to be an <code>input</code> or <code>textarea</code>.</p></li>
</ul>`
}

const parent = () => {
const checkability = () => {
return `<ul>
<li><p>${parentCmd}.</p></li>
<li><p>${childCmdDom}.</p></li>
<li><p>${cmd} requires the element to have type <code>checkbox</code> or <code>radio</code>.</p></li>
</ul>`
}

const blurability = () => {
const dom = () => {
return `<ul>
<li><p>${childCmdDom}.</p></li>
<li><p>${cmd} requires the element to currently have focus.</p></li>
<li><p>${focus}.</p></li>
<li><p>${parentOrChild()}.</p></li>
</ul>`
}

const focusability = () => {
const dual = () => {
return `<ul>
<li><p>${childCmdDom}.</p></li>
<li><p>${focus}.</p></li>
<li><p>${cmd} ${dualCmd}</p></li>
</ul>`
}

const clearability = () => {
const dualExistence = () => {
return `<ul>
<li><p>${childCmdDom}.</p></li>
<li><p>${cmd} requires the element to be an <code>input</code> or <code>textarea</code>.</p></li>
<li><p>${cmd} can be chained off of <code>cy</code> or off a command that yields DOM element(s).</p></li>
</ul>`
}

const checkability = () => {
const dualExistenceSingleDom = () => {
return `<ul>
<li><p>${childCmdDom}.</p></li>
<li><p>${cmd} requires the element to have type <code>checkbox</code> or <code>radio</code>.</p></li>
<li><p>${cmd} can be chained off of <code>cy</code> or off a command that yields a single DOM element.</p></li>
</ul>`
}

const selectability = () => {
const exec = () => {
return `<ul>
<li><p>${childCmdDom}.</p></li>
<li><p>${cmd} requires the element to be a <code>select</code>.</p></li>
<li><p>${parentCmd}.</p></li>
<li><p>${cmd} requires the executed system command to eventually exit.</p></li>
<li><p>${cmd} requires that the exit code be <code>0</code> when <code>failOnNonZeroExit</code> is <code>true</code>.</p></li>
</ul>`
}

const scrollability = () => {
const focusability = () => {
return `<ul>
<li><p>${childCmdDom}.</p></li>
<li><p>${cmd} requires the element to be scrollable.</p></li>
<li><p>${focus}.</p></li>
</ul>`
}

const submitability = () => {
const none = () => {
return `<ul>
<li><p>${childCmdDom}.</p></li>
<li><p>${cmd} requires the element to be a <code>form</code>.</p></li>
<li><p>${cmd} has no requirements or default assertions.</p></li>
</ul>`
}

const dual = () => {
const page = () => {
return `<ul>
<li><p>${cmd} can be chained off of <code>cy</code> or off another command.</p></li>
<li><p>${parentCmd}.</p></li>
<li><p>${cmd} requires the response to be <code>content-type: text/html</code>.</p></li>
<li><p>${cmd} requires the response code to be <code>2xx</code> after following redirects.</p></li>
<li><p>${cmd} requires the load <code>load</code> event to eventually fire.</p></li>
</ul>`
}

const dualExistence = () => {
const parent = () => {
return `<ul>
<li><p>${cmd} can be chained off of <code>cy</code> or off a command that yields DOM element(s).</p></li>
<li><p>${parentCmd}.</p></li>
</ul>`
}

const dualExistenceSingleDom = () => {
const parentOrChild = () => {
return (args[1] === 'cy.get' || args[1] === 'cy.focused') ? parentCmd : childCmdDom
}

const readFile = () => {
return `<ul>
<li><p>${cmd} can be chained off of <code>cy</code> or off a command that yields a single DOM element.</p></li>
<li><p>${parentCmd}.</p></li>
<li><p>${cmd} requires the file must exist.</p></li>
<li><p>${cmd} requires the file be successfully read from disk. Anything preventing this such as OS permission issues will cause it to fail.</p></li>
</ul>`
}

const spread = () => {
const request = () => {
return `<ul>
<li><p>${childCmd}.</p></li>
<li><p>${cmd} requires being chained off of a command that yields an array-like structure.</p></li>
<li><p>${parentCmd}.</p></li>
<li><p>${cmd} requires that the server send a response.</p></li>
<li><p>${cmd} requires that the response status code be <code>2xx</code> or <code>3xx</code> when <code>failOnStatusCode</code> is <code>true</code>.</p></li>
</ul>`
}

const exec = () => {
const scrollability = () => {
return `<ul>
<li><p>${parentCmd}.</p></li>
<li><p>${cmd} requires the executed system command to eventually exit.</p></li>
<li><p>${cmd} requires that the exit code be <code>0</code> when <code>failOnNonZeroExit</code> is <code>true</code>.</p></li>
<li><p>${childCmdDom}.</p></li>
<li><p>${cmd} requires the element to be scrollable.</p></li>
</ul>`
}

const task = () => {
const selectability = () => {
return `<ul>
<li><p>${parentCmd}.</p></li>
<li><p>${cmd} requires the task to eventually end.</p></li>
<li><p>${childCmdDom}.</p></li>
<li><p>${cmd} requires the element to be a <code>select</code>.</p></li>
</ul>`
}

const writeFile = () => {
const spread = () => {
return `<ul>
<li><p>${parentCmd}.</p></li>
<li><p>${cmd} requires the file be successfully written to disk. Anything preventing this such as OS permission issues will cause it to fail.</p></li>
<li><p>${childCmd}.</p></li>
<li><p>${cmd} requires being chained off of a command that yields an array-like structure.</p></li>
</ul>`
}

const readFile = () => {
const submitability = () => {
return `<ul>
<li><p>${parentCmd}.</p></li>
<li><p>${cmd} requires the file must exist.</p></li>
<li><p>${cmd} requires the file be successfully read from disk. Anything preventing this such as OS permission issues will cause it to fail.</p></li>
<li><p>${childCmdDom}.</p></li>
<li><p>${cmd} requires the element to be a <code>form</code>.</p></li>
</ul>`
}

const page = () => {
const task = () => {
return `<ul>
<li><p>${parentCmd}.</p></li>
<li><p>${cmd} requires the response to be <code>content-type: text/html</code>.</p></li>
<li><p>${cmd} requires the response code to be <code>2xx</code> after following redirects.</p></li>
<li><p>${cmd} requires the load <code>load</code> event to eventually fire.</p></li>
<li><p>${cmd} requires the task to eventually end.</p></li>
</ul>`
}

Expand All @@ -164,21 +167,29 @@ module.exports = function yields (hexo, args) {
</ul>`
}

const request = () => {
const wait = () => {
return `<ul>
<li><p>When passed a <code>time</code> argument ${dualCmd}.</p></li>
<li><p>When passed an <code>alias</code> argument ${parentCmd}.</p></li>
</ul>`
}

const writeFile = () => {
return `<ul>
<li><p>${parentCmd}.</p></li>
<li><p>${cmd} requires that the server send a response.</p></li>
<li><p>${cmd} requires that the response status code be <code>2xx</code> or <code>3xx</code> when <code>failOnStatusCode</code> is <code>true</code>.</p></li>
<li><p>${cmd} requires the file be successfully written to disk. Anything preventing this such as OS permission issues will cause it to fail.</p></li>
</ul>`
}

switch (type) {
case 'none':
return none()
case 'parent':
return parent()
case 'blurability':
return blurability()
case 'checkability':
return checkability()
case 'child':
return child()
case 'clearability':
return clearability()
case 'dom':
return dom()
case 'dual':
Expand All @@ -187,36 +198,36 @@ module.exports = function yields (hexo, args) {
return dualExistence()
case 'dual_existence_single_dom':
return dualExistenceSingleDom()
case 'clearability':
return clearability()
case 'blurability':
return blurability()
case 'exec':
return exec()
case 'focusability':
return focusability()
case 'checkability':
return checkability()
case 'selectability':
return selectability()
case 'none':
return none()
case 'parent':
return parent()
case 'page':
return page()
case 'read_file':
return readFile()
case 'request':
return request()
case 'scrollability':
return scrollability()
case 'submitability':
return submitability()
case 'selectability':
return selectability()
case 'spread':
return spread()
case 'exec':
return exec()
case 'submitability':
return submitability()
case 'task':
return task()
case 'read_file':
return readFile()
case 'write_file':
return writeFile()
case 'page':
return page()
case 'tick':
return tick()
case 'request':
return request()
case 'wait':
return wait()
case 'write_file':
return writeFile()
default:
// error when an invalid usage option was provided
throw new Error(`{% requirements %} tag helper was provided an invalid option: ${type}`)
Expand Down
2 changes: 1 addition & 1 deletion source/api/commands/wait.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ This gives you the best of both worlds - a fast error feedback loop when request

## Requirements {% helper_icon requirements %}

{% requirements parent cy.wait %}
{% requirements wait cy.wait %}

## Assertions {% helper_icon assertions %}

Expand Down
2 changes: 1 addition & 1 deletion source/ja/api/commands/wait.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ This gives you the best of both worlds - a fast error feedback loop when request

## Requirements {% helper_icon requirements %}

{% requirements parent cy.wait %}
{% requirements wait cy.wait %}

## Assertions {% helper_icon assertions %}

Expand Down
2 changes: 1 addition & 1 deletion source/zh-cn/api/commands/wait.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ This gives you the best of both worlds - a fast error feedback loop when request

## Requirements {% helper_icon requirements %}

{% requirements parent cy.wait %}
{% requirements wait cy.wait %}

## Assertions {% helper_icon assertions %}

Expand Down