100
100
expect(menu.hasClass('collapsing')).to.be.true;
103
describe('search', function () {
105
it('should have added a search icon', function () {
106
expect(Y.one('[data-qa="navbar-search"] .ues-icon-search-bordered')).to.exist;
109
it('should have a search form with collapse plugin plugged in', function () {
110
var search = Y.one('[data-qa="navbar-search"] .ues-navbar-collapse.search');
111
expect(search.collapse).to.exist;
114
it('should open search when search icon clicked', function (done) {
115
var searchIcon = Y.one('[data-qa="navbar-search"] .ues-navbar-header > .ues-icon-search-bordered');
116
var search = Y.one('[data-qa="navbar-search"] .ues-navbar-collapse.search');
118
var event = search.collapse.on('stateChange', function (e, done) {
119
expect(this.hasClass('in')).to.be.false;
120
expect(this.hasClass('collapse')).to.be.true;
121
expect(this.hasClass('collapsing')).to.be.false;
127
searchIcon.simulate('click');
128
// transition is 300ms, so this should immediately be true
129
expect(search.hasClass('collapsing')).to.be.true;
132
it('should close an open search when search icon clicked', function (done) {
133
var searchIcon = Y.one('[data-qa="navbar-search"] .ues-navbar-header > .ues-icon-search-bordered');
134
var search = Y.one('[data-qa="navbar-search"] .ues-navbar-collapse.search');
136
var event = search.collapse.on('stateChange', function (e, done) {
137
expect(this.hasClass('in')).to.be.true;
138
expect(this.hasClass('collapse')).to.be.true;
139
expect(this.hasClass('collapsing')).to.be.false;
145
searchIcon.simulate('click');
146
// transition is 300ms, so this should immediately be true
147
expect(search.hasClass('collapsing')).to.be.true;
152
describe('both search and menu together', function () {
154
it('should open search', function (done) {
155
var searchIcon = Y.one('[data-qa="navbar-search"] .ues-navbar-header > .ues-icon-search-bordered');
156
var search = Y.one('[data-qa="navbar-search"] .ues-navbar-collapse.search');
158
var event = search.collapse.on('stateChange', function (e, done) {
163
searchIcon.simulate('click');
167
it('should close an open search when menu icon clicked', function (done) {
169
var hamburger = Y.one('[data-qa="navbar-search"] .ues-navbar-header > .ues-icon-menu');
170
var menu = Y.one('[data-qa="navbar-search"] .ues-navbar-collapse');
172
var search = Y.one('[data-qa="navbar-search"] .ues-navbar-collapse.search');
174
var menuEvent = menu.collapse.on('stateChange', function (e) {
175
expect(this.hasClass('in')).to.be.false;
176
expect(this.hasClass('collapse')).to.be.true;
177
expect(this.hasClass('collapsing')).to.be.false;
179
// this would start collapsing search
180
expect(search.hasClass('collapsing')).to.be.true;
186
var searchEvent = search.collapse.on('stateChange', function (e, done) {
187
expect(this.hasClass('in')).to.be.true;
188
expect(this.hasClass('collapse')).to.be.true;
189
expect(this.hasClass('collapsing')).to.be.false;
191
searchEvent.detach();
195
hamburger.simulate('click');
196
// transition is 300ms, so this should immediately be true
197
expect(menu.hasClass('collapsing')).to.be.true;
200
it('should close an open menu when search icon clicked', function (done) {
202
var menu = Y.one('[data-qa="navbar-search"] .ues-navbar-collapse');
204
var search = Y.one('[data-qa="navbar-search"] .ues-navbar-collapse.search');
205
var searchIcon = Y.one('[data-qa="navbar-search"] .ues-navbar-header > .ues-icon-search-bordered');
207
var menuEvent = menu.collapse.on('stateChange', function (e) {
208
expect(this.hasClass('in')).to.be.true;
209
expect(this.hasClass('collapse')).to.be.true;
210
expect(this.hasClass('collapsing')).to.be.false;
218
var searchEvent = search.collapse.on('stateChange', function (e, done) {
219
expect(this.hasClass('in')).to.be.false;
220
expect(this.hasClass('collapse')).to.be.true;
221
expect(this.hasClass('collapsing')).to.be.false;
223
// this would start collapsing menu
224
expect(menu.hasClass('collapsing')).to.be.true;
226
searchEvent.detach();
229
searchIcon.simulate('click');
230
// transition is 300ms, so this should immediately be true
231
expect(search.hasClass('collapsing')).to.be.true;
242
describe('navbar-autocomplete', function () {
245
beforeEach(function (done) {
247
'navbar', 'navbar-autocomplete', 'node-event-simulate', function (Y) {
248
input = Y.one('.autocomplete input');
253
afterEach(function () {
259
Y.all('.ues-icon-menu, .ues-icon-search-bordered').remove(true);
263
it('should plug autocomplete input node', function () {
264
Y.one('.autocomplete input').hasPlugin('ac');
267
describe('autocollapse implementation tests', function () {
269
var autoCompleteQuery = function () {
272
input.set('value', '');
273
input.ac._onInputValueChange({newVal: ''});
275
input.set('value', val);
276
input.ac._onInputValueChange({newVal: val});
279
var autoCompleteClear = function () {
282
input.set('value', val);
283
input.ac._onInputValueChange({newVal: val});
285
input.set('value', '');
286
input.ac._onInputValueChange({newVal: ''});
291
beforeEach(function (done) {
293
wrapper = Y.one('.autocomplete');
294
wrapper.collapse.set('duration', 0);
296
var openEvent = wrapper.collapse.on('open', function (e, done) {
303
wrapper.collapse.open();
307
it('should resize to fit input etc as well as autocomplete list on results', function (done) {
309
input.ac.set('source', [
310
{ text: 'Facebook' },
314
var baseHeight = wrapper.get('scrollHeight');
318
var checkAutoComplete = function () {
319
var listNodeHeight = input.ac.get('listNode').get('scrollHeight');
320
var wrapperHeight = wrapper.get('scrollHeight');
321
var targetHeight = baseHeight + listNodeHeight;
323
// estimates are good enough here
324
expect(wrapperHeight).to.be.within(targetHeight, targetHeight + 10);
328
// wait for autocomplete to act
329
window.setTimeout(checkAutoComplete, 100);
333
it('should resize back to normal on clear', function (done) {
335
input.ac.set('source', [
336
{ text: 'Facebook' },
340
var baseHeight = wrapper.get('scrollHeight');
344
var checkAutoComplete = function () {
345
var wrapperHeight = wrapper.get('scrollHeight');
347
// estimates are good enough here
348
expect(wrapperHeight).to.be.within(baseHeight, baseHeight + 10);
352
// wait for autocomplete to act
353
window.setTimeout(checkAutoComplete, 100);
361
describe('navbar-autocomplete (loaded disorderly)', function () {
363
it('should not throw errors even if loaded before navbar', function () {
365
var fun = function () {
367
'navbar-autocomplete', 'navbar', function (Y) {
371
expect(fun).to.not.throw(/./);