BigW Consortium Gitlab

collapsed_sidebar_todo_spec.js 3.69 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 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
/* global Sidebar */
/* eslint-disable no-new */
import _ from 'underscore';
import '~/right_sidebar';

describe('Issuable right sidebar collapsed todo toggle', () => {
  const fixtureName = 'issues/open-issue.html.raw';
  const jsonFixtureName = 'todos/todos.json';

  preloadFixtures(fixtureName);
  preloadFixtures(jsonFixtureName);

  beforeEach(() => {
    const todoData = getJSONFixture(jsonFixtureName);
    new Sidebar();
    loadFixtures(fixtureName);

    document.querySelector('.js-right-sidebar')
      .classList.toggle('right-sidebar-expanded');
    document.querySelector('.js-right-sidebar')
      .classList.toggle('right-sidebar-collapsed');

    spyOn(jQuery, 'ajax').and.callFake((res) => {
      const d = $.Deferred();
      const response = _.clone(todoData);

      if (res.type === 'DELETE') {
        delete response.delete_path;
      }

      d.resolve(response);
      return d.promise();
    });
  });

  it('shows add todo button', () => {
    expect(
      document.querySelector('.js-issuable-todo.sidebar-collapsed-icon'),
    ).not.toBeNull();

    expect(
      document.querySelector('.js-issuable-todo.sidebar-collapsed-icon .fa-plus-square'),
    ).not.toBeNull();

    expect(
      document.querySelector('.js-issuable-todo.sidebar-collapsed-icon .todo-undone'),
    ).toBeNull();
  });

  it('sets default tooltip title', () => {
    expect(
      document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').getAttribute('title'),
    ).toBe('Add todo');
  });

  it('toggle todo state', () => {
    document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').click();

    expect(
      document.querySelector('.js-issuable-todo.sidebar-collapsed-icon .todo-undone'),
    ).not.toBeNull();

    expect(
      document.querySelector('.js-issuable-todo.sidebar-collapsed-icon .fa-check-square'),
    ).not.toBeNull();
  });

  it('toggle todo state of expanded todo toggle', () => {
    document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').click();

    expect(
      document.querySelector('.issuable-sidebar-header .js-issuable-todo').textContent.trim(),
    ).toBe('Mark done');
  });

  it('toggles todo button tooltip', () => {
    document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').click();

    expect(
      document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').getAttribute('data-original-title'),
    ).toBe('Mark done');
  });

  it('marks todo as done', () => {
    document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').click();

    expect(
      document.querySelector('.js-issuable-todo.sidebar-collapsed-icon .todo-undone'),
    ).not.toBeNull();

    document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').click();

    expect(
      document.querySelector('.js-issuable-todo.sidebar-collapsed-icon .todo-undone'),
    ).toBeNull();

    expect(
      document.querySelector('.issuable-sidebar-header .js-issuable-todo').textContent.trim(),
    ).toBe('Add todo');
  });

  it('updates aria-label to mark done', () => {
    document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').click();

    expect(
      document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').getAttribute('aria-label'),
    ).toBe('Mark done');
  });

  it('updates aria-label to add todo', () => {
    document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').click();

    expect(
      document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').getAttribute('aria-label'),
    ).toBe('Mark done');

    document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').click();

    expect(
      document.querySelector('.js-issuable-todo.sidebar-collapsed-icon').getAttribute('aria-label'),
    ).toBe('Add todo');
  });
});