pagination_spec.js.es6 3.49 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
//= require vue
//= require vue_pagination/index

describe('Pagination component', () => {
  let component;

  const changeChanges = {
    one: '',
    two: '',
  };

  const change = (one, two) => {
    changeChanges.one = one;
    changeChanges.two = two;
  };

Regis's avatar
Regis committed
17
  it('should render and start at page 1', () => {
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
    fixture.set('<div class="test-pagination-container"></div>');

    component = new window.gl.VueGlPagination({
      el: document.querySelector('.test-pagination-container'),
      propsData: {
        pageInfo: {
          totalPages: 10,
          nextPage: 2,
          previousPage: '',
        },
        change,
      },
    });

    expect(component.$el.classList).toContain('gl-pagination');

    component.changepage({ target: { innerText: '1' } });

    expect(changeChanges.one).toEqual(1);
    expect(changeChanges.two).toEqual('all');
  });
Regis's avatar
Regis committed
39

Regis's avatar
Regis committed
40
  it('should go to the previous page', () => {
Regis's avatar
Regis committed
41 42 43 44 45 46 47
    fixture.set('<div class="test-pagination-container"></div>');

    component = new window.gl.VueGlPagination({
      el: document.querySelector('.test-pagination-container'),
      propsData: {
        pageInfo: {
          totalPages: 10,
Regis's avatar
Regis committed
48 49
          nextPage: 3,
          previousPage: 1,
Regis's avatar
Regis committed
50 51 52 53 54
        },
        change,
      },
    });

Regis's avatar
Regis committed
55
    component.changepage({ target: { innerText: 'Prev' } });
Regis's avatar
Regis committed
56

Regis's avatar
Regis committed
57
    expect(changeChanges.one).toEqual(1);
Regis's avatar
Regis committed
58
    expect(changeChanges.two).toEqual('all');
Regis's avatar
Regis committed
59
  });
Regis's avatar
Regis committed
60

Regis's avatar
Regis committed
61 62
  it('should go to the next page', () => {
    fixture.set('<div class="test-pagination-container"></div>');
Regis's avatar
Regis committed
63

Regis's avatar
Regis committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
    component = new window.gl.VueGlPagination({
      el: document.querySelector('.test-pagination-container'),
      propsData: {
        pageInfo: {
          totalPages: 10,
          nextPage: 5,
          previousPage: 3,
        },
        change,
      },
    });

    component.changepage({ target: { innerText: 'Next' } });

    expect(changeChanges.one).toEqual(5);
Regis's avatar
Regis committed
79 80
    expect(changeChanges.two).toEqual('all');
  });
Regis's avatar
Regis committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143

  it('should go to the last page', () => {
    fixture.set('<div class="test-pagination-container"></div>');

    component = new window.gl.VueGlPagination({
      el: document.querySelector('.test-pagination-container'),
      propsData: {
        pageInfo: {
          totalPages: 10,
          nextPage: 5,
          previousPage: 3,
        },
        change,
      },
    });

    component.changepage({ target: { innerText: 'Last >>' } });

    expect(changeChanges.one).toEqual(10);
    expect(changeChanges.two).toEqual('all');
  });

  it('should go to the first page', () => {
    fixture.set('<div class="test-pagination-container"></div>');

    component = new window.gl.VueGlPagination({
      el: document.querySelector('.test-pagination-container'),
      propsData: {
        pageInfo: {
          totalPages: 10,
          nextPage: 5,
          previousPage: 3,
        },
        change,
      },
    });

    component.changepage({ target: { innerText: '<< First' } });

    expect(changeChanges.one).toEqual(1);
    expect(changeChanges.two).toEqual('all');
  });

  it('should do nothing', () => {
    fixture.set('<div class="test-pagination-container"></div>');

    component = new window.gl.VueGlPagination({
      el: document.querySelector('.test-pagination-container'),
      propsData: {
        pageInfo: {
          totalPages: 10,
          nextPage: 2,
          previousPage: '',
        },
        change,
      },
    });

    component.changepage({ target: { innerText: '...' } });

    expect(changeChanges.one).toEqual(1);
    expect(changeChanges.two).toEqual('all');
  });
144
});