|
| 1 | +/* eslint-env mocha */ |
| 2 | +const expect = require('chai').expect; |
| 3 | +const View = require('../src/view.js'); |
| 4 | +const Model = require('../src/model.js'); |
| 5 | + |
| 6 | +describe('View >', () => { |
| 7 | + const range = 'm3'; |
| 8 | + |
| 9 | + it('CreateElement', () => { |
| 10 | + const dom = View.CreateElement(); |
| 11 | + const nodes = dom.childNodes; |
| 12 | + |
| 13 | + expect(nodes[0].nodeName).to.equal('SPAN'); |
| 14 | + expect(nodes[7].nodeName).to.equal('SPAN'); |
| 15 | + |
| 16 | + for (let i = 0; i < Model.TERM.length; ++i) { |
| 17 | + const key = i + 1; |
| 18 | + expect(nodes[key].nodeName).to.equal('A'); |
| 19 | + expect(nodes[key].textContent).to.equal(Model.TERM[i].text); |
| 20 | + expect(nodes[key].getAttribute('data')).to.equal(Model.TERM[i].data); |
| 21 | + } |
| 22 | + }); |
| 23 | + |
| 24 | + it('BindElement', () => { |
| 25 | + const dom = View.CreateElement(); |
| 26 | + View.BindElement(dom); |
| 27 | + const target = document.querySelector('div#ucs > .quick-custom-gsearch'); |
| 28 | + expect(target.nodeName).to.equal('DIV'); |
| 29 | + }); |
| 30 | + |
| 31 | + it('SetCssState', () => { |
| 32 | + View.SetCssState(range); |
| 33 | + const target = document.querySelector(`.quick-custom-gsearch a[data=${range}]`); |
| 34 | + expect(target.className).to.equal('active'); |
| 35 | + }); |
| 36 | + |
| 37 | + it('QuickChange', () => { |
| 38 | + const elm = document.createElement('a'); |
| 39 | + elm.setAttribute('data', Model.TERM[0].data); |
| 40 | + elm.appendChild(document.createTextNode(Model.TERM[0].text)); |
| 41 | + const event = View.QuickChange.bind(elm); |
| 42 | + const result = event(); |
| 43 | + expect(result).to.equal('/search?hl=ja&site=webhp&biw=810&bih=1306&q=duckduckgo&oq=duckduckgo&ie=UTF-8&tbm='); |
| 44 | + }); |
| 45 | +}); |
0 commit comments