BigW Consortium Gitlab

modal_store_spec.js 3.16 KB
Newer Older
Phil Hughes committed
1 2
/* global ListIssue */

3 4 5 6 7
import '~/boards/models/issue';
import '~/boards/models/label';
import '~/boards/models/list';
import '~/boards/models/assignee';
import '~/boards/stores/modal_store';
Phil Hughes committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

describe('Modal store', () => {
  let issue;
  let issue2;
  const Store = gl.issueBoards.ModalStore;

  beforeEach(() => {
    // Setup default state
    Store.store.issues = [];
    Store.store.selectedIssues = [];

    issue = new ListIssue({
      title: 'Testing',
      iid: 1,
      confidential: false,
      labels: [],
24
      assignees: [],
Phil Hughes committed
25 26 27 28 29 30
    });
    issue2 = new ListIssue({
      title: 'Testing',
      iid: 2,
      confidential: false,
      labels: [],
31
      assignees: [],
Phil Hughes committed
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
    });
    Store.store.issues.push(issue);
    Store.store.issues.push(issue2);
  });

  it('returns selected count', () => {
    expect(Store.selectedCount()).toBe(0);
  });

  it('toggles the issue as selected', () => {
    Store.toggleIssue(issue);

    expect(issue.selected).toBe(true);
    expect(Store.selectedCount()).toBe(1);
  });

  it('toggles the issue as un-selected', () => {
    Store.toggleIssue(issue);
    Store.toggleIssue(issue);

    expect(issue.selected).toBe(false);
    expect(Store.selectedCount()).toBe(0);
  });

  it('toggles all issues as selected', () => {
    Store.toggleAll();

    expect(issue.selected).toBe(true);
    expect(issue2.selected).toBe(true);
    expect(Store.selectedCount()).toBe(2);
  });

  it('toggles all issues as un-selected', () => {
    Store.toggleAll();
    Store.toggleAll();

    expect(issue.selected).toBe(false);
    expect(issue2.selected).toBe(false);
    expect(Store.selectedCount()).toBe(0);
  });

  it('toggles all if a single issue is selected', () => {
    Store.toggleIssue(issue);
    Store.toggleAll();

    expect(issue.selected).toBe(true);
    expect(issue2.selected).toBe(true);
    expect(Store.selectedCount()).toBe(2);
  });

  it('adds issue to selected array', () => {
Phil Hughes committed
83
    issue.selected = true;
Phil Hughes committed
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
    Store.addSelectedIssue(issue);

    expect(Store.selectedCount()).toBe(1);
  });

  it('removes issue from selected array', () => {
    Store.addSelectedIssue(issue);
    Store.removeSelectedIssue(issue);

    expect(Store.selectedCount()).toBe(0);
  });

  it('returns selected issue index if present', () => {
    Store.toggleIssue(issue);

    expect(Store.selectedIssueIndex(issue)).toBe(0);
  });

  it('returns -1 if issue is not selected', () => {
    expect(Store.selectedIssueIndex(issue)).toBe(-1);
  });

  it('finds the selected issue', () => {
    Store.toggleIssue(issue);

    expect(Store.findSelectedIssue(issue)).toBe(issue);
  });

  it('does not find a selected issue', () => {
    expect(Store.findSelectedIssue(issue)).toBe(undefined);
  });
Phil Hughes committed
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132

  it('does not remove from selected issue if tab is not all', () => {
    Store.store.activeTab = 'selected';

    Store.toggleIssue(issue);
    Store.toggleIssue(issue);

    expect(Store.store.selectedIssues.length).toBe(1);
    expect(Store.selectedCount()).toBe(0);
  });

  it('gets selected issue array with only selected issues', () => {
    Store.toggleIssue(issue);
    Store.toggleIssue(issue2);
    Store.toggleIssue(issue2);

    expect(Store.getSelectedIssues().length).toBe(1);
  });
Phil Hughes committed
133
});