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

helpers.js « editor « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 252d783ad6db0a752462f46b67d3d9ab79bc05a5 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* eslint-disable max-classes-per-file */

// Helpers
export const spyOnApi = (extension, spiesObj = {}) => {
  const origApi = extension.api;
  if (extension?.obj) {
    jest.spyOn(extension.obj, 'provides').mockReturnValue({
      ...origApi,
      ...spiesObj,
    });
  }
};

// Dummy Extensions
export class SEClassExtension {
  static get extensionName() {
    return 'SEClassExtension';
  }

  // eslint-disable-next-line class-methods-use-this
  provides() {
    return {
      shared: () => 'extension',
      classExtMethod: () => 'class own method',
    };
  }
}

export function SEFnExtension() {
  return {
    extensionName: 'SEFnExtension',
    fnExtMethod: () => 'fn own method',
    provides: () => {
      return {
        fnExtMethod: () => 'class own method',
      };
    },
  };
}

export const SEConstExt = () => {
  return {
    extensionName: 'SEConstExt',
    provides: () => {
      return {
        constExtMethod: () => 'const own method',
      };
    },
  };
};

export class SEWithSetupExt {
  static get extensionName() {
    return 'SEWithSetupExt';
  }
  // eslint-disable-next-line class-methods-use-this
  onSetup(instance, setupOptions = {}) {
    if (setupOptions && !Array.isArray(setupOptions)) {
      Object.entries(setupOptions).forEach(([key, value]) => {
        Object.assign(instance, {
          [key]: value,
        });
      });
    }
  }
  provides() {
    return {
      returnInstanceAndProps: (instance, stringProp, objProp = {}) => {
        return [stringProp, objProp, instance];
      },
      returnInstance: (instance) => {
        return instance;
      },
      giveMeContext: () => {
        return this;
      },
    };
  }
}

export const conflictingExtensions = {
  WithInstanceExt: () => {
    return {
      extensionName: 'WithInstanceExt',
      provides: () => {
        return {
          use: () => 'A conflict with instance',
          ownMethod: () => 'Non-conflicting method',
        };
      },
    };
  },
  WithAnotherExt: () => {
    return {
      extensionName: 'WithAnotherExt',
      provides: () => {
        return {
          shared: () => 'A conflict with extension',
          ownMethod: () => 'Non-conflicting method',
        };
      },
    };
  },
};