Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add details.polyfill.js #426

Merged
merged 6 commits into from
Oct 3, 2017
Merged

Add details.polyfill.js #426

merged 6 commits into from
Oct 3, 2017

Conversation

alex-ju
Copy link
Contributor

@alex-ju alex-ju commented Jul 13, 2017

Make details.polyfill.js available to anyone using govuk_frontend_toolkit; fixes Issue #400.

Make details.polyfill.js available to anyone using govuk_frontend_toolkit
@frankieroberto
Copy link
Contributor

Useful. 👍

@gemmaleigh
Copy link
Contributor

@alex-ju
Copy link
Contributor Author

alex-ju commented Aug 4, 2017

Updated

  • follows govuk coding standards
  • includes unit test

Copy link
Contributor

@36degrees 36degrees left a comment

Choose a reason for hiding this comment

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

Generally looking really good, but I think the tests could be improved by only testing one thing at a time rather than lumping multiple assertions together.

this.$content.remove()
})

describe('when details element follows the specified structure', function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't seen describe blocks used in this nested manner before – I guess it's just trying to describe the context, but I'm not convinced it's required. Most of it seems pretty self explanatory. Are there other benefits to using them that I'm not understanding?

Copy link
Contributor Author

@alex-ju alex-ju Sep 28, 2017

Choose a reason for hiding this comment

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

I'm not used with this way of nesting descriptions, I just followed other tests' structure in the frontend_toolkit. I can flatten them down.

Copy link
Contributor

Choose a reason for hiding this comment

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

Aah, sorry – for some reason I didn't even think to look at how the other specs were written. If we're broadly following the conventions of the other specs, let's leave them as they are and re-visit this when we look at moving this into Frontend.


describe('when details element follows the specified structure', function () {
describe('and when details.polyfill is initialised', function () {
describe('and when we have native details support', function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

When we don't have native support? Surely if we have native support this doesn't do anything?


it('should make the hidden content visible if its summary is clicked', function (done) {
// Initialise again
this.detailsPolyfill = GOVUK.details.addDetailsPolyfill()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed?

GOVUK.details.started = false
})
it('should add the aria attributes to summary', function () {
expect(this.$summary1.attr('role')).toBe('button')
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we try and have one expectation per it block? For example 'it should add the button role to the summary', 'it should associate the summary with the content using aria-controls', 'it should indicate the collapsed state using aria-expanded'


// Trigger click on summary
this.$summary1.click()
expect(this.$content.attr('open')).toBe('open')
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to rework this to have one expectation per it block as well. Perhaps

describe: when the summary is clicked
it: should make the content visible
it: should indicate the expanded state of the summary using aria-expanded
it: should indicate the visible state of the content using aria-hidden

// Add to page
$(document.body).append(this.$content)

setTimeout(function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good to add a comment as to why this is needed.

Copy link
Contributor Author

@alex-ju alex-ju Sep 28, 2017

Choose a reason for hiding this comment

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

Essentially I needed to do asynchronous testing because of how the events are being chained.
I can avoid doing so, but I have to do more rewriting on the polyfill first. Let me know if you want me to try and get rid of the async test.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

- Flatten the nested describe blocks
- Test one expectation per ‘it’ block
- Remove multiple initialisation
Copy link
Contributor

@36degrees 36degrees left a comment

Choose a reason for hiding this comment

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

A couple of description nit-picks but generally this is looking great.

this.$content.remove()
})

describe('and when details.polyfill is initialised', function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest just "When the polyfill is initialised" – there's no real prior statement to connect the 'and' to.

expect(this.$hiddenContent1.attr('id')).toBe('details-content-0')
})

it('should set aria-hidden true to hidden content', function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't scan very well to me. I'd suggest something like 'should present the content as hidden using aria-hidden'

Copy link
Contributor

@36degrees 36degrees left a comment

Choose a reason for hiding this comment

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

👏

@36degrees 36degrees merged commit 70d2453 into alphagov:master Oct 3, 2017
36degrees added a commit that referenced this pull request Oct 3, 2017
Promote the details polyfill to Frontend Toolkit from GOV.UK Elements – PR #426
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Details polyfill not available in any of the gov repos when npm install'ed
4 participants