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

commit_spec.js « environments « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 32eb4b77528e136818cbfddb9724f6533ea3c00f (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
import { mountExtended } from 'helpers/vue_test_utils_helper';
import Commit from '~/environments/components/commit.vue';
import { resolvedEnvironment } from './graphql/mock_data';

describe('~/environments/components/commit.vue', () => {
  let commit;
  let wrapper;

  beforeEach(() => {
    commit = resolvedEnvironment.lastDeployment.commit;
  });

  const createWrapper = ({ propsData = {} } = {}) =>
    mountExtended(Commit, {
      propsData: {
        commit,
        ...propsData,
      },
    });

  afterEach(() => {
    wrapper?.destroy();
  });

  describe('with gitlab user', () => {
    beforeEach(() => {
      wrapper = createWrapper();
    });

    it('links to the user profile', () => {
      const link = wrapper.findByRole('link', { name: commit.author.name });
      expect(link.attributes('href')).toBe(commit.author.path);
    });

    it('displays the user avatar', () => {
      const avatar = wrapper.findByRole('img', { name: 'avatar' });
      expect(avatar.attributes('src')).toBe(commit.author.avatarUrl);
    });

    it('links the commit message to the commit', () => {
      const message = wrapper.findByRole('link', { name: commit.message });

      expect(message.attributes('href')).toBe(commit.commitPath);
    });
  });
  describe('without gitlab user', () => {
    beforeEach(() => {
      commit = {
        ...commit,
        author: null,
      };
      wrapper = createWrapper();
    });

    it('links to the user profile', () => {
      const link = wrapper.findByRole('link', { name: commit.authorName });
      expect(link.attributes('href')).toBe(`mailto:${commit.authorEmail}`);
    });

    it('displays the user avatar', () => {
      const avatar = wrapper.findByRole('img', { name: 'avatar' });
      expect(avatar.attributes('src')).toBe(commit.authorGravatarUrl);
    });

    it('displays the commit message', () => {
      const message = wrapper.findByRole('link', { name: commit.message });

      expect(message.attributes('href')).toBe(commit.commitPath);
    });
  });
});