it('should append the button to widget when the necessary config is given', (done) => { render(root, {}, () => { expect(root.querySelector('.btn')) .to.be.an.instanceof(HTMLElement) done() }) })
it('should callback with widget', (done) => { render(root, {}, (widget) => { expect(widget) .to.be.an.instanceof(HTMLElement) done() }) })
it('should append the button with the default icon', (done) => { render(root, {}, () => { expect(root.querySelector('.btn').querySelector('.octicon.octicon-mark-github')) .to.be.an.instanceof(SVGElement) done() }) })
it('should render stylesheet', (done) => { render(root, {}, () => { expect(root.querySelector('style')) .to.be.an.instanceof(HTMLElement) done() }) })
it('should add lg to widget.className when data-size is large', (done) => { render(root, { 'data-size': 'large' }, () => { expect(root.querySelector('.widget.lg')) .to.be.an.instanceof(HTMLElement) done() }) })
it('should create a widget with className widget', (done) => { render(root, {}, () => { expect(root.querySelector('.widget')) .to.be.an.instanceof(HTMLElement) expect(root.querySelector('.widget.lg')) .to.be.null done() }) })
it('should append the button with the default if given icon is invalid', (done) => { render(root, { 'data-icon': 'null' }, () => { expect(root.querySelector('.btn').querySelector('.octicon.octicon-mark-github')) .to.be.an.instanceof(SVGElement) done() }) })
it('should append the button with given icon', (done) => { render(root, { 'data-icon': 'octicon-star' }, () => { expect(root.querySelector('.btn').querySelector('.octicon.octicon-star')) .to.be.an.instanceof(SVGElement) done() }) })
it('should append the button with given href', (done) => { const config = { 'href': 'https://ntkme.github.com/' } render(root, config, () => { expect(root.querySelector('.btn').getAttribute('href')) .to.equal(config.href) done() }) })
it('should append the button with given aria label', (done) => { const config = { 'aria-label': 'GitHub' } render(root, config, () => { expect(root.querySelector('.btn').getAttribute('aria-label')) .to.equal(config['aria-label']) done() }) })
it('should append the button with given text', (done) => { const config = { 'data-text': 'Follow' } render(root, config, () => { expect(root.querySelector('.btn').lastChild.innerHTML) .to.equal(config['data-text']) done() }) })
].map(href => new Promise(resolve => { render(root, { href }, (widget) => { expect(widget.querySelector('.btn').href) .to.equal(href) expect(widget.querySelector('.btn').target) .to.equal('_top') resolve() }) })))
it('should append the count when a known button type is given', (done) => { const config = { 'href': 'https://github.com/ntkme', 'data-show-count': 'true' } render(root, config, (widget) => { expect(widget.querySelector('.social-count')) .to.be.an.instanceof(HTMLElement) done() }) })
it('should not append the count for unknown button type', (done) => { const config = { 'href': 'https://github.com/', 'data-show-count': 'true' } render(root, config, (widget) => { expect(widget.querySelector('.social-count')) .to.be.null done() }) })
it('should create a button with href # if domain is not github', (done) => { render(root, { 'href': 'https://twitter/ntkme' }, () => { expect(root.querySelector('.btn').href) .to.equal(document.location.href + '#') expect(root.querySelector('.btn').target) .to.equal('_self') done() }) })
].map(href => new Promise(resolve => { render(root, { href }, (widget) => { expect(widget.querySelector('.btn').href) .to.equal(document.location.href + '#') expect(widget.querySelector('.btn').target) .to.equal('_self') resolve() }) })))
it('should append the count for button whose link has a tailing slash, a query, and a hash', (done) => { const config = { 'href': 'https://github.com/ntkme/?tab=repositories#github-buttons', 'data-show-count': 'true' } render(root, config, (widget) => { const count = widget.querySelector('.social-count') expect(count.href) .to.equal('https://github.com/ntkme/followers') done() }) })
it('should append button without count when count has error', (done) => { const config = { 'href': 'https://github.com/404', 'data-show-count': 'true' } render(root, config, (widget) => { const btn = widget.querySelector('.btn') expect(btn.href) .to.equal(config.href) expect(widget.querySelector('.social-count')) .to.be.null done() }) })
it('should append the count for fork button', (done) => { const config = { 'href': 'https://github.com/ntkme/github-buttons/fork', 'data-show-count': 'true' } render(root, config, (widget) => { const count = widget.querySelector('.social-count') expect(count.href) .to.equal('https://github.com/ntkme/github-buttons/network') expect(count.lastChild.innerHTML) .to.equal('94') expect(count.getAttribute('aria-label')) .to.equal('94 forks on GitHub') done() }) })
it('should append the count for issue button when it links to new issue', (done) => { const config = { 'href': 'https://github.com/ntkme/github-buttons/issues/new', 'data-show-count': 'true' } render(root, config, (widget) => { const count = widget.querySelector('.social-count') expect(count.href) .to.equal('https://github.com/ntkme/github-buttons/issues') expect(count.lastChild.innerHTML) .to.equal('1') expect(count.getAttribute('aria-label')) .to.equal('1 open issue on GitHub') done() }) })
it('should work', () => { render(root, {}) })