Skip to content

Commit

Permalink
Merge pull request #71 from SFDigitalServices/release-6.0.4
Browse files Browse the repository at this point in the history
Release 6.0.4
  • Loading branch information
shawnbot authored Aug 11, 2020
2 parents 2662c45 + 1cf0239 commit acfc0f7
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:

- run: npm ci
- run: npm run lint
- run: npm test
- run: npm run build
env:
NODE_ENV: production
- run: npm test

- uses: primer/publish@v2.0.0
env:
Expand Down
51 changes: 51 additions & 0 deletions __tests__/a11y.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* eslint-env jest */
import { createForm, destroyForm } from '../lib/test-helpers'
import '../dist/formio-sfds.standalone.js'

describe('a11y', () => {
describe('input labels', () => {
it('textfield inputs have associated labels', async () => {
const form = await createForm({
type: 'form',
display: 'form',
components: [
{
type: 'textfield',
key: 'name',
label: 'Name',
input: true
},
{
type: 'container',
key: 'nested',
components: [
{
type: 'number',
key: 'age',
label: 'Age',
input: true
}
]
}
]
}, {})

const inputs = form.element.querySelectorAll('input')
const labels = form.element.querySelectorAll('label:not(.control-label--hidden)')
expect(inputs).toHaveLength(2)
expect(labels).toHaveLength(2)

const [nameField, ageField] = inputs
const [nameLabel, ageLabel] = labels
expect(nameField.name).toBe('data[name]')
expect(nameField.id).toBe(`input-${nameField.name}`)
expect(nameLabel.getAttribute('for')).toBe(nameField.id)

expect(ageField.name).toBe('data[nested][age]')
expect(ageField.id).toBe(`input-${ageField.name}`)
expect(ageLabel.getAttribute('for')).toBe(ageField.id)

destroyForm(form)
})
})
})
37 changes: 27 additions & 10 deletions __tests__/patch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-env jest */
import 'regenerator-runtime'
import loadTranslations from '../src/i18n/load'
import patch from '../src/patch'
import { createElement, createForm, destroyForm, sleep } from '../lib/test-helpers'
Expand All @@ -15,13 +14,6 @@ const SENTINEL_I18N_KEY = 'derp'
const SENTINEL_I18N_VALUE = 'DERP!'
defaultTranslations.en[SENTINEL_I18N_KEY] = SENTINEL_I18N_VALUE

// jsdom doesn't provide an implementation for these, and it throws an error if
// you call them directly. Thankfully, Jest can spy on and mock them. See:
// <https://github.com/jsdom/jsdom/issues/1422>
const scroll = jest.fn()
jest.spyOn(window, 'scroll').mockImplementation(scroll)
jest.spyOn(window, 'scrollTo').mockImplementation(scroll)

describe('patch()', () => {
beforeAll(() => {
patch(Formio)
Expand Down Expand Up @@ -172,21 +164,46 @@ describe('patch()', () => {
* is the first test that actually tries to access them, so it could be
* that the createForm() helper function isn't working properly.
*/
xit('gets .widget = "html5" by default', async () => {
it('gets .widget = "html5" by default', async () => {
const form = await createForm({
type: 'form',
display: 'form',
components: [
{
key: 'heyo',
type: 'select',
widget: 'choicesjs',
input: true,
data: { values: [] }
}
]
})
expect(form.components.length).toBeGreaterThanOrEqual(1)
const [select] = form.components
expect(select.type).toEqual('select')
expect(select.component.widget).toEqual('html5')
destroyForm(form)
})

it('does not set .widget = "html5" if "autocomplete" tag is present', async () => {
const form = await createForm({
type: 'form',
display: 'form',
components: [
{
key: 'heyo',
type: 'select',
tags: ['autocomplete'],
widget: 'choicesjs',
input: true,
data: { values: [] }
}
]
})
// expect(form.components[0].type).toEqual('html5')
expect(form.components.length).toBeGreaterThanOrEqual(1)
const [select] = form.components
expect(select.type).toEqual('select')
expect(select.component.widget).toEqual('choicesjs')
destroyForm(form)
})
})
Expand Down
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
bail: 1
bail: 1,
setupFiles: ['<rootDir>/lib/test-setup.js']
}
6 changes: 3 additions & 3 deletions lib/test-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function createForm (form = {}, options = {}) {
id: `form-${Date.now().toString(36)}`
})
document.body.appendChild(el)
return global.Formio.createForm(el, options)
return global.Formio.createForm(el, form, options)
}

function destroyForm (form) {
Expand All @@ -27,8 +27,8 @@ function destroyForm (form) {
element.remove()
}

function sleep (ms) {
function sleep (ms = 1) {
return new Promise(resolve => {
setTimeout(resolve, 10)
setTimeout(resolve, ms)
})
}
10 changes: 10 additions & 0 deletions lib/test-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-env jest */
import 'regenerator-runtime'
import 'formiojs/dist/formio.full.min.js'

// jsdom doesn't provide an implementation for these, and it throws an error if
// you call them directly. Thankfully, Jest can spy on and mock them. See:
// <https://github.com/jsdom/jsdom/issues/1422>
const scroll = jest.fn()
jest.spyOn(window, 'scroll').mockImplementation(scroll)
jest.spyOn(window, 'scrollTo').mockImplementation(scroll)
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "formio-sfds",
"version": "6.0.3",
"version": "6.0.4",
"description": "form.io templates for the SF Design System",
"module": "src/index.js",
"main": "dist/formio-sfds.cjs.js",
Expand Down
4 changes: 2 additions & 2 deletions src/templates/file/form.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
{% } %}
<td class="remove text-align-right pr-0">
{% if (!ctx.disabled) { %}
<button ref="removeLink" aria-label="Remove"
<button ref="removeLink" aria-label="{{ ctx.t('Remove') }}"
class="m-0 p-1 bg-blue fg-white border-0 d-flex flex-items-center">
<span data-icon="delete" class="d-flex flex-items-center"></span>
</button>
Expand All @@ -119,7 +119,7 @@
</td>
<td class="remove text-align-right pr-0">
{% if (!ctx.disabled) { %}
<button ref="fileStatusRemove" aria-label="Remove"
<button ref="fileStatusRemove" aria-label="{{ ctx.t('Remove') }}"
class="m-0 p-1 bg-blue fg-white border-0 d-flex flex-items-center">
<span data-icon="delete" class="d-flex flex-items-center"></span>
</button>
Expand Down
1 change: 1 addition & 0 deletions src/templates/input/form.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<div class="form-input">
<{{ctx.input.type}}
ref="{{ctx.input.ref ? ctx.input.ref : 'input'}}"
id="input-{{ ctx.input.attr.name }}"
{% for (var attr in ctx.input.attr) { %}
{{attr}}="{{ctx.input.attr[attr]}}"
{% } %}
Expand Down
2 changes: 1 addition & 1 deletion src/templates/label/form.ejs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% if (!ctx.component.hideLabel && ['checkbox', 'radio'].indexOf(ctx.component.type) === -1) { %}
<label class="{{ ctx.label.className }}">
<label class="{{ ctx.label.className }}" for="input-{{ ctx.self.options.name }}">
{{ ctx.t([`${ctx.component.key}_label`, ctx.component.label]) }}
<!--
{% if (ctx.component.tooltip) { %}
Expand Down
3 changes: 2 additions & 1 deletion src/templates/multiValueRow/form.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<div class="mr-1">{{ ctx.element }}</div>
{% if (!ctx.disabled) { %}
<div>
<button type="button" class="btn bg-slate-65" ref="removeRow">
<button type="button" class="btn bg-slate-65" ref="removeRow"
aria-label="{{ ctx.t('Remove') }}">
<span data-icon="delete"></span>
</button>
</div>
Expand Down

1 comment on commit acfc0f7

@vercel
Copy link

@vercel vercel bot commented on acfc0f7 Aug 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.