summaryrefslogtreecommitdiff
path: root/spec/frontend/batch_comments/components/drafts_count_spec.js
blob: 5f74de9c014d3d3abf7cd916a216ec1d62a2f2cf (plain)
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
import Vue from 'vue';
import { mountComponentWithStore } from 'helpers/vue_mount_component_helper';
import DraftsCount from '~/batch_comments/components/drafts_count.vue';
import { createStore } from '~/batch_comments/stores';

describe('Batch comments drafts count component', () => {
  let vm;
  let Component;

  beforeAll(() => {
    Component = Vue.extend(DraftsCount);
  });

  beforeEach(() => {
    const store = createStore();

    store.state.batchComments.drafts.push('comment');

    vm = mountComponentWithStore(Component, { store });
  });

  afterEach(() => {
    vm.$destroy();
  });

  it('renders count', () => {
    expect(vm.$el.textContent).toContain('1');
  });

  it('renders screen reader text', (done) => {
    const el = vm.$el.querySelector('.sr-only');

    expect(el.textContent).toContain('draft');

    vm.$store.state.batchComments.drafts.push('comment 2');

    vm.$nextTick(() => {
      expect(el.textContent).toContain('drafts');

      done();
    });
  });
});