Sha256: f35e1f8d1e667af85a4ca1b32daea85b0179bf3f4b7bb03b981fa1567d37d1eb

Contents?: true

Size: 1.74 KB

Versions: 62

Compression:

Stored size: 1.74 KB

Contents

describe('primary-links', function(){
  var shortList, mediumList, longList;

  beforeEach(function () {
    shortList = $('<ul><li class="primary">one</li><li>two</li></ul>');
    mediumList = $('<ul><li class="primary">one</li><li>two</li><li>three</li></ul>');
    longList = $('<ul><li class="primary">one</li><li class="primary">two</li><li>three</li><li>four</li></ul>');
  });

  it('visually hides extra links', function(){
    var list = new GOVUK.PrimaryList(mediumList, '.primary');
    
    expect(mediumList.find('.visuallyhidden').length).toBe(2);
  });

  it('creates appropriate toggle text', function(){
    var short = new GOVUK.PrimaryList(shortList, '.primary');
    var medium = new GOVUK.PrimaryList(mediumList, '.primary');
    
    expect(short.toggleText()).toEqual('+1 other');
    expect(medium.toggleText()).toEqual('+2 others');
  });

  it('add a toggle link', function(){
    var container = $('<div>').append(mediumList);
    var list = new GOVUK.PrimaryList(mediumList, '.primary');

    expect(container.find('a').length).toBe(1);
  });

  it('show extra links when toggled', function(){
    var list = new GOVUK.PrimaryList(mediumList, '.primary');
    var event = { preventDefault: function(){} };
    spyOn(event, 'preventDefault');
    spyOn(list, 'showExtraLinks');

    list.toggleLinks(event);
    expect(event.preventDefault).toHaveBeenCalled();
    expect(list.showExtraLinks).toHaveBeenCalled();
  });

  it('only adds toggle if more than one extra link', function(){
    var short = new GOVUK.PrimaryList(shortList, '.primary');
    var medium = new GOVUK.PrimaryList(mediumList, '.primary');
    
    expect(shortList.find('.visuallyhidden').length).toBe(0);
    expect(mediumList.find('.visuallyhidden').length).toBe(2);
  });
});

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
govuk_frontend_toolkit-4.18.3 app/assets/spec/unit/primary-links.spec.js
govuk_frontend_toolkit-4.18.2 app/assets/spec/unit/primary-links.spec.js
govuk_frontend_toolkit-4.18.1 app/assets/spec/unit/primary-links.spec.js
govuk_frontend_toolkit-4.18.0 app/assets/spec/unit/primary-links.spec.js
govuk_frontend_toolkit-4.17.0 app/assets/spec/unit/primary-links.spec.js
govuk_frontend_toolkit-4.16.1 app/assets/spec/unit/primary-links.spec.js
govuk_frontend_toolkit-4.16.0 app/assets/spec/unit/primary-links.spec.js
govuk_frontend_toolkit-4.15.0 app/assets/spec/unit/primary-links.spec.js
govuk_frontend_toolkit-4.14.1 app/assets/spec/unit/primary-links.spec.js
govuk_frontend_toolkit-4.14.0 app/assets/spec/unit/primary-links.spec.js
govuk_frontend_toolkit-4.13.0 app/assets/spec/unit/primary-links.spec.js
govuk_frontend_toolkit-4.12.0 app/assets/spec/unit/primary-links.spec.js
govuk_frontend_toolkit-4.11.0 app/assets/spec/unit/primary-links.spec.js
govuk_frontend_toolkit-4.10.0 app/assets/spec/unit/primary-links.spec.js
govuk_frontend_toolkit-4.9.1 app/assets/spec/unit/primary-links.spec.js
govuk_frontend_toolkit-4.9.0 app/assets/spec/unit/primary-links.spec.js
govuk_frontend_toolkit-4.8.2 app/assets/spec/unit/primary-links.spec.js
govuk_frontend_toolkit-4.8.1 app/assets/spec/unit/primary-links.spec.js
govuk_frontend_toolkit-4.8.0 app/assets/spec/unit/primary-links.spec.js
govuk_frontend_toolkit-4.7.0 app/assets/spec/unit/primary-links.spec.js