Skip to content

Commit

Permalink
Fixing up PR to allow for all cases of sepcial chars.
Browse files Browse the repository at this point in the history
  • Loading branch information
nataliecarey committed Jul 8, 2021
1 parent 831996c commit e324147
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/govuk/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ export function generateUniqueID () {

export function getSelectorForID (id) {
if (id && id.replace) {
return '#' + (id).replace(/\./g, '\\.')
return '#' + (id).replace(/([.:\][])/g, '\\$1')
}
}
22 changes: 11 additions & 11 deletions src/govuk/components/checkboxes/checkboxes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ describe('Checkboxes with conditional reveals', () => {
const isExpanded = await waitForVisibleSelector('.govuk-checkboxes__item:first-child .govuk-checkboxes__input[aria-expanded=true]')
expect(isExpanded).toBeTruthy()
})
// it('indicates when conditional content is collapsed or revealed with full stop in ID', async () => {
// await goToAndGetComponent('checkboxes', 'with-conditional-items-with-full-stop-in-id')
//
// const isNotExpanded = await waitForVisibleSelector('.govuk-checkboxes__item:first-child .govuk-checkboxes__input[aria-expanded=false]')
// expect(isNotExpanded).toBeTruthy()
//
// await page.click('.govuk-checkboxes__item:first-child .govuk-checkboxes__input')
//
// const isExpanded = await waitForVisibleSelector('.govuk-checkboxes__item:first-child .govuk-checkboxes__input[aria-expanded=true]')
// expect(isExpanded).toBeTruthy()
// })
it('indicates when conditional content is collapsed or revealed with all special chars in the ID', async () => {
await goToAndGetComponent('checkboxes', 'with-conditional-items-with-all-special-chars-in-id')

const isNotExpanded = await waitForVisibleSelector('.govuk-checkboxes__item:first-child .govuk-checkboxes__input[aria-expanded=false]')
expect(isNotExpanded).toBeTruthy()

await page.click('.govuk-checkboxes__item:first-child .govuk-checkboxes__input')

const isExpanded = await waitForVisibleSelector('.govuk-checkboxes__item:first-child .govuk-checkboxes__input[aria-expanded=true]')
expect(isExpanded).toBeTruthy()
})
it('toggles the conditional content when clicking an input', async () => {
const $ = await goToAndGetComponent('checkboxes', 'with-conditional-items')
const $component = $('.govuk-checkboxes')
Expand Down
12 changes: 6 additions & 6 deletions src/govuk/components/checkboxes/checkboxes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -416,31 +416,31 @@ examples:
<label class="govuk-label" for="contact-text-message">Mobile phone number</label>
<input class="govuk-input govuk-!-width-one-third" name="contact-text-message" type="text" id="contact-text-message">
- name: with conditional items with full stop in id
- name: with conditional items with all special chars in id
data:
name: with-conditional-items-with-full-stop-in-id
idPrefix: with-conditional-items-with-full-stop-in-id
name: with-conditional-items-with-all-special-chars-in-id
idPrefix: with-conditional-items-with-all-special-chars-in-id
fieldset:
legend:
text: How do you want to be contacted?
items:
- value: email
text: Email
id: option.email
id: option-1:choice.condition[email]
conditional:
html: |
<label class="govuk-label" for="context-email">Email address</label>
<input class="govuk-input govuk-!-width-one-third" name="context-email" type="text" id="context-email">
- value: phone
text: Phone
id: option.phone
id: option-1:choice.condition[phone]
conditional:
html: |
<label class="govuk-label" for="contact-phone">Phone number</label>
<input class="govuk-input govuk-!-width-one-third" name="contact-phone" type="text" id="contact-phone">
- value: text
text: Text message
id: option.text
id: option-1:choice.condition[text]
conditional:
html: |
<label class="govuk-label" for="contact-text-message">Mobile phone number</label>
Expand Down
4 changes: 2 additions & 2 deletions src/govuk/components/radios/radios.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ describe('Radios with conditional reveals', () => {
const isExpanded = await waitForVisibleSelector('.govuk-radios__item:first-child .govuk-radios__input[aria-expanded=true]')
expect(isExpanded).toBeTruthy()
})
it('indicates when conditional content is collapsed or revealed with a full stop in the ID', async () => {
await goToAndGetComponent('radios', 'with-conditional-items-with-full-stop-in-id')
it('indicates when conditional content is collapsed or revealed with all special chars in the ID', async () => {
await goToAndGetComponent('radios', 'with-conditional-items-with-all-special-chars-in-id')

const isNotExpanded = await waitForVisibleSelector('.govuk-radios__item:first-child .govuk-radios__input[aria-expanded=false]')
expect(isNotExpanded).toBeTruthy()
Expand Down
12 changes: 6 additions & 6 deletions src/govuk/components/radios/radios.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -321,31 +321,31 @@ examples:
<label class="govuk-label" for="contact-text-message">Mobile phone number</label>
<input class="govuk-input govuk-!-width-one-third" name="contact-text-message" type="text" id="contact-text-message">
- name: with conditional items with full stop in id
- name: with conditional items with all special chars in id
data:
idPrefix: with-conditional-items-with-full-stop-in-id
name: with-conditional-items-with-full-stop-in-id
idPrefix: with-conditional-items-with-all-special-chars-in-id
name: with-conditional-items-with-all-special-chars-in-id
fieldset:
legend:
text: How do you want to be contacted?
items:
- value: email
text: Email
id: option.email
id: option-1:choice.condition[email]
conditional:
html: |
<label class="govuk-label" for="context-email">Email address</label>
<input class="govuk-input govuk-!-width-one-third" name="context-email" type="text" id="context-email">
- value: phone
text: Phone
id: option.phone
id: option-1:choice.condition[phone]
conditional:
html: |
<label class="govuk-label" for="contact-phone">Phone number</label>
<input class="govuk-input govuk-!-width-one-third" name="contact-phone" type="text" id="contact-phone">
- value: text
text: Text message
id: option.text
id: option-1:choice.condition[text]
conditional:
html: |
<label class="govuk-label" for="contact-text-message">Mobile phone number</label>
Expand Down

0 comments on commit e324147

Please sign in to comment.