Share
Embed
Annual Pro sale · Save $30
Have presentations of your own?
Share with private links, password protection, and more control over your work.
Transcript
103 slides
-
“ https://www.w3.org/2001/tag/doc/leastPower.html Tim Berners-Lee & Noah Mendelsohn The Rule of
Least Power Expressing constraints, relationships and processing instructions in less powerful languages increases the flexibility with which information can be reused: the less powerful the language, the more you can do with the data stored in that language.” -
test('filing an issue', async function(assert) { await visit('/issues/new'); await fillIn('input[name="title"]',
'Example'); await fillIn('textarea[name="body"]', 'This is my issue…'); await fillIn('select[name="assignees"]', 'Alice'); await fillIn('select[name="labels"]', 'Feature'); await fillIn('select[name="project"]', 'Some Project'); await fillIn('select[name="milestone"]', 'v1'); await click('button[type="submit"]'); assert.dom('h1').hasText('Example'); }); -
test('filing an issue', async function(assert) { await visit('/issues/new'); await fillIn('input[name="title"]',
'Example'); await fillIn('textarea[name="body"]', 'This is my issue…'); await fillIn('select[name="assignees"]', 'Alice'); await fillIn('select[name="labels"]', 'Feature'); await fillIn('select[name="project"]', 'Some Project'); await fillIn('select[name="milestone"]', 'v1'); await click('button[type="submit"]'); assert.dom('h1').hasText('Example'); }); Access via accessibility A less powerful language Say more -
test('filing an issue', async function(assert) { await visit('/issues/new'); await fillIn('input[name="title"]',
'Example'); await fillIn('textarea[name="body"]', 'This is my issue…'); await fillIn('select[name="assignees"]', 'Alice'); await fillIn('select[name="labels"]', 'Feature'); await fillIn('select[name="project"]', 'Some Project'); await fillIn('select[name="milestone"]', 'v1'); await click('button[type="submit"]'); assert.dom('h1').hasText('Example'); }); -
test('filing an issue', async function(assert) { await visit('/issues/new'); await fillIn('Title',
'Example'); await fillIn('Body', 'This is my issue…'); await fillIn('Assignees', 'Alice'); await fillIn('Labels', 'Feature'); await fillIn('Project', 'Some Project'); await fillIn('Milestone', 'v1'); await click('button[type="submit"]'); assert.dom('h1').hasText('Example'); }); -
test('filing an issue', async function(assert) { await visit('/issues/new'); await fillIn('Title',
'Example'); await fillIn('Body', 'This is my issue…'); await fillIn('Assignees', 'Alice'); await fillIn('Labels', 'Feature'); await fillIn('Project', 'Some Project'); await fillIn('Milestone', 'v1'); await click('button[type="submit"]'); assert.dom('h1').hasText('Example'); }); -
Acceptance | say more: filing an issue ✘ Promise rejected
during "filing an issue": Could not find a form control labelled "Body" -
Acceptance | say more: filing an issue ✔ Element h1
has text "Example" -
import { fillIn } from '@ember/test-helpers'; export default function fillInByLabel(label,
value) { let control = findControlForLabel(label); return fillIn(control, value); } -
function findControlForLabel(text) { let label = findLabel(text); if (label &&
label.control) { return label.control; } let control = findControl(text); if (control) { return control; } if (label && !label.control) { throw new Error(`Found the label "${label.innerText}" but no associated form control`); } throw new Error(`Could not find a form control labelled "${text}"`); } -
import { findAll } from '@ember/test-helpers'; function findLabel(text) { return
findAll('label').find(label => label.innerText.includes(text)); } -
import { find } from '@ember/test-helpers'; function findControl(text) { let
selectors = []; for (let tag of ['input', 'textarea', 'select']) { for (let attr of ['title', 'aria-label', 'placeholder']) { selectors.push(`${tag}[${attr}="${text}"]`); } } return find(selectors.join(',')); } -
test('filing an issue', async function(assert) { await visit('/issues/new'); await fillIn('Title',
'Example'); await fillIn('Body', 'This is my issue…'); await fillIn('Assignees', 'Alice'); await fillIn('Labels', 'Feature'); await fillIn('Project', 'Some Project'); await fillIn('Milestone', 'v1'); await click('button[type="submit"]'); assert.dom('h1').hasText('Example'); }); -
test('filing an issue', async function(assert) { await visit('/issues/new'); await fillIn('Title',
'Example'); await fillIn('Body', 'This is my issue…'); await fillIn('Assignees', 'Alice'); await fillIn('Labels', 'Feature'); await fillIn('Project', 'Some Project'); await fillIn('Milestone', 'v1'); await click('button[type="submit"]'); assert.dom('h1').hasText('Example'); }); -
test('filing an issue', async function(assert) { await visit('/issues/new'); await fillIn('Title',
'Example'); await fillIn('Body', 'This is my issue…'); await fillIn('Assignees', 'Alice'); await fillIn('Labels', 'Feature'); await fillIn('Project', 'Some Project'); await fillIn('Milestone', 'v1'); await click('Submit'); assert.dom('h1').hasText('Example'); }); -
Acceptance | say more: filing an issue ✘ Promise rejected
during "filing an issue": Could not find a button containing "Submit" -
Acceptance | say more: filing an issue ✔ Element h1
has text "Example" -
import { click } from '@ember/test-helpers'; export default function clickByLabel(text)
{ let element = findElement(text); if (!element) { throw new Error(`Could not find a button containing "${text}"`); } return click(element); } -
import { findAll } from '@ember/test-helpers'; function findElement(text) { let
selector = 'button,a[href],[role="button"]'; let element = findAll(selector).find(matches(text)); return element; } -
function matches(text) { return element => matchesInnerText(element, text) || matchesTitle(element,
text) || matchesAriaLabel(element, text); } -
function matchesInnerText(element, text) { return element.innerText.includes(text); } function matchesTitle(element, text)
{ return element.title && element.title.includes(text); } function matchesAriaLabel(element, text) { let ariaLabel = element.getAttribute('aria-label'); return ariaLabel && ariaLabel.includes(text); } -
test('filing an issue', async function(assert) { await visit('/issues/new'); await fillIn('Title',
'Example'); await fillIn('Body', 'This is my issue…'); await fillIn('Assignees', 'Alice'); await fillIn('Labels', 'Feature'); await fillIn('Project', 'Some Project'); await fillIn('Milestone', 'v1'); await click('Submit'); assert.dom('h1').hasText('Example'); }); -
test('filing an issue', async function(assert) { await visit('/issues/new'); await fillIn('Title',
'Example'); await fillIn('Body', 'This is my issue…'); await fillIn('Assignees', 'Alice'); await fillIn('Labels', 'Feature'); await fillIn('Project', 'Some Project'); await fillIn('Milestone', 'v1'); await click('Submit'); assert.dom('h1').hasText('Example'); }); -
Acceptance | say more: filing an issue ✘ Promise rejected
during "filing an issue": The user would have to tab backwards to reach the button containing "Submit" -
<div> <button type="submit">Submit</button> </div> <form> <div> <label for="title">Title</label> <input id="title"
name="title" type="text"> </div> <div> <label for="body">Body</label> <textarea id="body" name="body"></textarea> </div> <div> <label for="assignees">Assignees</label> <select id="assignees" name="assignees" multiple> <option>Alice</option> -
<div> <button type="submit">Submit</button> </div> <form> <div> <label for="title">Title</label> <input id="title"
name="title" type="text"> </div> <div> <label for="body">Body</label> <textarea id="body" name="body"></textarea> </div> <div> <label for="assignees">Assignees</label> <select id="assignees" name="assignees" multiple> <option>Alice</option> -
<option>Some Other Project</option> </select> </div> <div> <label for="milestone">Milestone</label> <select id="milestone"
name="milestone"> <option value="">No milestone</option> <option>v1</option> <option>v2</option> </select> </div> </form> <div> <button type="submit">Submit</button> </div> -
<option>Some Other Project</option> </select> </div> <div> <label for="milestone">Milestone</label> <select id="milestone"
name="milestone"> <option value="">No milestone</option> <option>v1</option> <option>v2</option> </select> </div> </form> <div> <button type="submit">Submit</button> </div> -
Acceptance | say more: filing an issue ✔ Element h1
has text "Example" -
let tabs = calculateTabsTo(element); if (tabs < 0) { throw
new Error(`The user would have to tab backwards to reach the button containing "${text}"`); } return click(element); } import { calculateTabsTo } from './tabbability'; export default function clickByLabel(text) { let element = findElement(text); if (!element) { throw new Error(`Could not find a button containing "${text}"`); } -
let tabs = calculateTabsTo(element); if (tabs < 0) { throw
new Error(`The user would have to tab backwards to reach the button containing "${text}"`); } return click(element); } import { calculateTabsTo } from './tabbability'; export default function clickByLabel(text) { let element = findElement(text); if (!element) { throw new Error(`Could not find a button containing "${text}"`); } -
import { findAll } from '@ember/test-helpers'; export function calculateTabsTo(targetElement) {
let { activeElement } = document; // TODO: Make this less naive let tabbables = findAll('*').filter(e => e.tabIndex >= 0); let activeIndex = tabbables.indexOf(activeElement); let targetIndex = tabbables.indexOf(targetElement); if (targetIndex === -1) { throw new Error('The target element is not tabbable, \ try setting tabindex'); } return targetIndex - activeIndex; } -
test('filing an issue', async function(assert) { await visit('/issues/new'); await fillIn('Title',
'Example'); await fillIn('Body', 'This is my issue…'); await fillIn('Assignees', 'Alice'); await fillIn('Labels', 'Feature'); await fillIn('Project', 'Some Project'); await fillIn('Milestone', 'v1'); await click('Submit'); assert.dom('h1').hasText('Example'); }); -
test('filing an issue', async function(assert) { await visit('/issues/new'); await fillIn('Title',
'Example'); await fillIn('Body', 'This is my issue…'); await fillIn('Assignees', 'Alice'); await fillIn('Labels', 'Feature'); await fillIn('Project', 'Some Project'); await fillIn('Milestone', 'v1'); await click('Submit'); // <-- Press return assert.dom('h1').hasText('Example'); }); -
Acceptance | say more: filing an issue (with keyboard) ✘
Element h1 exists -
<form> <div> <label for="title">Title</label> <input id="title" name="title" type="text"> </div> .
. . <div> <button onclick={{action submit}}>Submit</button> </div> </form> -
<form onsubmit={{action submit}}> <div> <label for="title">Title</label> <input id="title" name="title" type="text">
</div> . . . <div> <button type="submit">Submit</button> </div> </form> -
Acceptance | say more: filing an issue (with keyboard) ✔
Element h1 has text "Example" -
import { focus, triggerKeyEvent } from '@ember/test-helpers'; import findButton from
'./find-button'; import { calculateTabsTo } from './tabbability'; const KEY_RETURN = 13; export default async function keyboardClick(text) { let element = findButton(text); if (!element) { throw new Error(`Could not find a button containing "${text}"`); } let tabs = calculateTabsTo(element); if (tabs < 0) { throw new Error(`The user would have to tab backwards to reach the button containing "${text}"`); } await focus(element); await triggerKeyEvent(element, 'keydown', KEY_RETURN); await triggerKeyEvent(element, 'keypress', KEY_RETURN); await triggerKeyEvent(element, 'keyup', KEY_RETURN); } -
await focus(element); await triggerKeyEvent(element, 'keydown', KEY_RETURN); await triggerKeyEvent(element, 'keypress', KEY_RETURN);
await triggerKeyEvent(element, 'keyup', KEY_RETURN); if (element.type === 'submit' && element.form) { await triggerEvent(element.form, 'submit'); } -
test('filing an issue', async function(assert) { await visit('/issues/new'); await fillIn('Title',
'Example'); await fillIn('Body', 'This is my issue…'); await fillIn('Assignees', 'Alice'); await fillIn('Labels', 'Feature'); await fillIn('Project', 'Some Project'); await fillIn('Milestone', 'v1'); await click('Submit'); assert.dom('h1').hasText('Example'); }); -
test('filing an issue (with keyboard)', async function(assert) { await visit('/issues/new');
await fillIn('Title', 'Example'); await fillIn('Body', 'This is my issue…'); await fillIn('Assignees', 'Alice'); await fillIn('Labels', 'Feature'); await fillIn('Project', 'Some Project'); await fillIn('Milestone', 'v1'); await keyboardClick('Submit'); assert.dom('h1').hasText('Example'); }); -
test('filing an issue', async function(assert) { await visit('/issues/new'); await fillIn('Title',
'Example'); await fillIn('Body', 'This is my issue…'); await fillIn('Assignees', 'Alice'); await fillIn('Labels', 'Feature'); await fillIn('Project', 'Some Project'); await fillIn('Milestone', 'v1'); await click('Submit'); assert.dom('h1').hasText('Example'); }); -
test('filing an issue', async function(assert) { await visit('/issues/new'); await fillIn('Title',
'Example'); await fillIn('Body', 'This is my issue…'); await fillIn('Assignees', 'Alice'); await fillIn('Labels', 'Feature'); await fillIn('Project', 'Some Project'); await fillIn('Milestone', 'v1'); await click('Submit'); assert.dom('h1').hasText('Example'); }); -
test('filing an issue', async function(assert) { await visit('/issues/new'); await fillIn('Title',
'Example'); await fillIn('Body', 'This is my issue…'); await fillIn('Assignees', 'Alice'); await fillIn('Labels', 'Feature'); await fillIn('Project', 'Some Project'); await fillIn('Milestone', 'v1'); await click('Submit'); // <-- What’s the network up to? assert.dom('h1').hasText('Example'); }); -
Acceptance | say more: filing an issue ✘ Promise rejected
during "filing an issue": The application made 3 requests after clicking "Submit" ==> POST /issues with { "data": { ... } } ==> GET /issues/1/labels ==> GET /issues/1?include=labels -
createIssue: task(function * (attrs) { let store = this.get('store'); attrs.labels
= attrs.labels .map(id => store.peekRecord('label', id)); let issue = store.createRecord('issue', attrs); yield issue.save(); this.transitionToRoute('issues.issue', issue.get('id')); }).drop() -
createIssue: task(function * (attrs) { let store = this.get('store'); attrs.labels
= attrs.labels .map(id => store.peekRecord('label', id)); let issue = store.createRecord('issue', attrs); yield issue.save(); this.transitionToRoute('issues.issue', issue.get('id')); }).drop() ^^^^^^^^^^ -
createIssue: task(function * (attrs) { let store = this.get('store'); attrs.labels
= attrs.labels .map(id => store.peekRecord('label', id)); let issue = store.createRecord('issue', attrs); yield issue.save(); this.transitionToRoute('issues.issue', issue); }).drop() -
Acceptance | say more: filing an issue ✘ Promise rejected
during "filing an issue": The application made 2 requests after clicking "Submit" ==> POST /issues with { "data": { ... } } ==> GET /issues/1/labels -
// mirage/serializers/issue.js import ApplicationSerializer from './application'; export default ApplicationSerializer.extend({ include:
[], links(issue) { return { labels: { related: `/issues/${issue.id}/labels` } }; } }); -
// mirage/serializers/issue.js import ApplicationSerializer from './application'; export default ApplicationSerializer.extend({ include:
['labels'], links(issue) { return { labels: { related: `/issues/${issue.id}/labels` } }; } }); -
Acceptance | say more: filing an issue ✔ Element h1
has text "Example" -
export default function clickByLabel(text) { let element = findElement(text); if
(!element) { throw new Error(`Could not find a button containing "${text}"`); } let tabs = calculateTabsTo(element); if (tabs < 0) { throw new Error(`The user would have to tab backwards to reach the button containing "${text}"`); } return click(element); } -
export default async function clickByLabel(text) { . . . return
click(element); } -
export default async function clickByLabel(text) { . . . await
click(element); } -
import { trackRequests } from './mirage'; export default async function
clickByLabel(text) { . . . await click(element); } -
import { trackRequests } from './mirage'; export default async function
clickByLabel(text) { . . . let requests = await trackRequests(() => click(element)); } -
import { trackRequests, inspectRequests } from './mirage'; export default async
function clickByLabel(text) { . . . let requests = await trackRequests(() => click(element)); if (requests.length > 1) { let msg = `The application made ${requests.length} requests after clicking "${text}"`; msg += '\n'; msg += inspectRequests(requests); throw new Error(msg); } } -
export async function trackRequests(block) { let { handledRequests } =
server.pretender; let n = handledRequests.length; await block(); let result = handledRequests.slice(n); return result; } -
export function inspectRequest(request) { let result = `==> ${request.method} ${request.url}`;
if (request.requestBody) { result += ` with ${request.requestBody}`; } return result; } -
Acceptance | say more: filing an issue ✘ Promise rejected
during "filing an issue": The application made 3 requests after clicking "Submit" ==> POST /issues with { "data": { ... } } ==> GET /issues/1/labels ==> GET /issues/1?include=labels -
test('filing an issue', async function(assert) { await visit('/issues/new'); await fillIn('input[name="title"]',
'Example'); await fillIn('textarea[name="body"]', 'This is my issue…'); await fillIn('select[name="assignees"]', 'Alice'); await fillIn('select[name="labels"]', 'Feature'); await fillIn('select[name="project"]', 'Some Project'); await fillIn('select[name="milestone"]', 'v1'); await click('button[type="submit"]'); assert.dom('h1').hasText('Example'); }); -
test('filing an issue', async function(assert) { await visit('/issues/new'); await fillIn('input[name="title"]',
'Example'); await fillIn('textarea[name="body"]', 'This is my issue…'); await fillIn('select[name="assignees"]', 'Alice'); await fillIn('select[name="labels"]', 'Feature'); await fillIn('select[name="project"]', 'Some Project'); await fillIn('select[name="milestone"]', 'v1'); await click('button[type="submit"]'); assert.dom('h1').hasText('Example'); }); Access via accessibility A less powerful language Say more -
test('filing an issue', async function(assert) { await visit('/issues/new'); await fillIn('Title',
'Example'); await fillIn('Body', 'This is my issue…'); await fillIn('Assignees', 'Alice'); await fillIn('Labels', 'Feature'); await fillIn('Project', 'Some Project'); await fillIn('Milestone', 'v1'); await click('Submit'); assert.dom('h1').hasText('Example'); }); -
test('filing an issue', async function(assert) { await visit('/issues/new'); await fillIn('Title',
'Example'); await fillIn('Body', 'This is my issue…'); await fillIn('Assignees', 'Alice'); await fillIn('Labels', 'Feature'); await fillIn('Project', 'Some Project'); await fillIn('Milestone', 'v1'); await click('Submit'); assert.dom('h1').hasText('Example'); }); ✅ Semantically labelled -
test('filing an issue', async function(assert) { await visit('/issues/new'); await fillIn('Title',
'Example'); await fillIn('Body', 'This is my issue…'); await fillIn('Assignees', 'Alice'); await fillIn('Labels', 'Feature'); await fillIn('Project', 'Some Project'); await fillIn('Milestone', 'v1'); await click('Submit'); assert.dom('h1').hasText('Example'); }); ✅ Semantically labelled ✅ Tabbable -
test('filing an issue', async function(assert) { await visit('/issues/new'); await fillIn('Title',
'Example'); await fillIn('Body', 'This is my issue…'); await fillIn('Assignees', 'Alice'); await fillIn('Labels', 'Feature'); await fillIn('Project', 'Some Project'); await fillIn('Milestone', 'v1'); await click('Submit'); assert.dom('h1').hasText('Example'); }); ✅ Semantically labelled ✅ Tabbable ✅ Supports keyboard interaction -
test('filing an issue', async function(assert) { await visit('/issues/new'); await fillIn('Title',
'Example'); await fillIn('Body', 'This is my issue…'); await fillIn('Assignees', 'Alice'); await fillIn('Labels', 'Feature'); await fillIn('Project', 'Some Project'); await fillIn('Milestone', 'v1'); await click('Submit'); assert.dom('h1').hasText('Example'); }); ✅ Semantically labelled ✅ Tabbable ✅ Supports keyboard interaction ✅ Uses the network sparingly