Welcome to mirror list, hosted at ThFree Co, Russian Federation.

commit_info_spec.js « components « repository « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 34e941aa858f2493cb34a0495f81ed83f9e2d185 (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
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
import { nextTick } from 'vue';
import { GlButton } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import CommitInfo from '~/repository/components/commit_info.vue';
import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue';

let wrapper;
const commit = {
  title: 'Commit title',
  titleHtml: 'Commit title html',
  message: 'Commit message',
  authoredDate: '2019-01-01',
  authorName: 'Test authorName',
  author: { name: 'Test name', avatarUrl: 'https://test.com', webPath: '/test' },
};

const findTextExpander = () => wrapper.findComponent(GlButton);
const findUserLink = () => wrapper.findByText(commit.author.name);
const findUserAvatarLink = () => wrapper.findComponent(UserAvatarLink);
const findAuthorName = () => wrapper.findByText(`${commit.authorName} authored`);
const findCommitRowDescription = () => wrapper.find('pre');
const findTitleHtml = () => wrapper.findByText(commit.titleHtml);

const createComponent = async ({ commitMock = {} } = {}) => {
  wrapper = shallowMountExtended(CommitInfo, {
    propsData: { commit: { ...commit, ...commitMock } },
  });

  await nextTick();
};

describe('Repository last commit component', () => {
  it('renders author info', () => {
    createComponent();

    expect(findUserLink().exists()).toBe(true);
    expect(findUserAvatarLink().exists()).toBe(true);
  });

  it('hides author component when author does not exist', () => {
    createComponent({ commitMock: { author: null } });

    expect(findUserLink().exists()).toBe(false);
    expect(findUserAvatarLink().exists()).toBe(false);
    expect(findAuthorName().exists()).toBe(true);
  });

  it('does not render description expander when description is null', () => {
    createComponent();

    expect(findTextExpander().exists()).toBe(false);
    expect(findCommitRowDescription().exists()).toBe(false);
  });

  describe('when the description is present', () => {
    beforeEach(() => {
      createComponent({ commitMock: { descriptionHtml: '
Update ADOPTERS.md' } });
    });

    it('strips the first newline of the description', () => {
      expect(findCommitRowDescription().html()).toBe(
        '<pre class="commit-row-description gl-mb-3 gl-white-space-pre-line">Update ADOPTERS.md</pre>',
      );
    });

    it('renders commit description collapsed by default', () => {
      expect(findCommitRowDescription().classes('gl-display-block!')).toBe(false);
      expect(findTextExpander().classes('open')).toBe(false);
      expect(findTextExpander().props('selected')).toBe(false);
    });

    it('expands commit description when clicking expander', async () => {
      findTextExpander().vm.$emit('click');
      await nextTick();

      expect(findCommitRowDescription().classes('gl-display-block!')).toBe(true);
      expect(findTextExpander().classes('open')).toBe(true);
      expect(findTextExpander().props('selected')).toBe(true);
    });
  });

  it('sets correct CSS class if the commit message is empty', () => {
    createComponent({ commitMock: { message: '' } });

    expect(findTitleHtml().classes()).toContain('gl-font-style-italic');
  });
});