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

utils.js « contribution_events « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6e97455582db38ec1babc6eaa6d2bb39a049c690 (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
import events from 'test_fixtures/controller/users/activity.json';
import {
  EVENT_TYPE_APPROVED,
  EVENT_TYPE_EXPIRED,
  EVENT_TYPE_JOINED,
  EVENT_TYPE_LEFT,
  EVENT_TYPE_PUSHED,
  EVENT_TYPE_PRIVATE,
  EVENT_TYPE_MERGED,
  PUSH_EVENT_REF_TYPE_BRANCH,
  PUSH_EVENT_REF_TYPE_TAG,
} from '~/contribution_events/constants';

const findEventByAction = (action) => events.find((event) => event.action === action);

export const eventApproved = () => findEventByAction(EVENT_TYPE_APPROVED);

export const eventExpired = () => findEventByAction(EVENT_TYPE_EXPIRED);

export const eventJoined = () => findEventByAction(EVENT_TYPE_JOINED);

export const eventLeft = () => findEventByAction(EVENT_TYPE_LEFT);

export const eventMerged = () => findEventByAction(EVENT_TYPE_MERGED);

const findPushEvent = ({
  isNew = false,
  isRemoved = false,
  refType = PUSH_EVENT_REF_TYPE_BRANCH,
  commitCount = 1,
} = {}) => () =>
  events.find(
    ({ action, ref, commit }) =>
      action === EVENT_TYPE_PUSHED &&
      ref.is_new === isNew &&
      ref.is_removed === isRemoved &&
      ref.type === refType &&
      commit.count === commitCount,
  );

export const eventPushedNewBranch = findPushEvent({ isNew: true });
export const eventPushedNewTag = findPushEvent({ isNew: true, refType: PUSH_EVENT_REF_TYPE_TAG });
export const eventPushedBranch = findPushEvent();
export const eventPushedTag = findPushEvent({ refType: PUSH_EVENT_REF_TYPE_TAG });
export const eventPushedRemovedBranch = findPushEvent({ isRemoved: true });
export const eventPushedRemovedTag = findPushEvent({
  isRemoved: true,
  refType: PUSH_EVENT_REF_TYPE_TAG,
});
export const eventBulkPushedBranch = findPushEvent({ commitCount: 5 });

export const eventPrivate = () => ({ ...events[0], action: EVENT_TYPE_PRIVATE });