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

tokens_app_spec.js « components « access_tokens « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d7acfbb47eb0be383aa395e84836a89cc6707dc2 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import { merge } from 'lodash';

import { mountExtended, extendedWrapper } from 'helpers/vue_test_utils_helper';

import TokensApp from '~/access_tokens/components/tokens_app.vue';
import { FEED_TOKEN, INCOMING_EMAIL_TOKEN, STATIC_OBJECT_TOKEN } from '~/access_tokens/constants';

describe('TokensApp', () => {
  let wrapper;

  const defaultProvide = {
    tokenTypes: {
      [FEED_TOKEN]: {
        enabled: true,
        token: 'DUKu345VD73Py7zz3z89',
        resetPath: '/-/profile/reset_feed_token',
      },
      [INCOMING_EMAIL_TOKEN]: {
        enabled: true,
        token: 'az4a2l5f8ssa0zvdfbhidbzlx',
        resetPath: '/-/profile/reset_incoming_email_token',
      },
      [STATIC_OBJECT_TOKEN]: {
        enabled: true,
        token: 'QHXwGHYioHTgxQnAcyZ-',
        resetPath: '/-/profile/reset_static_object_token',
      },
    },
  };

  const createComponent = (options = {}) => {
    wrapper = mountExtended(TokensApp, merge({}, { provide: defaultProvide }, options));
  };

  const expectTokenRendered = ({
    testId,
    expectedLabel,
    expectedDescription,
    expectedInputDescription,
    expectedResetPath,
    expectedResetConfirmMessage,
    expectedProps,
  }) => {
    const container = extendedWrapper(wrapper.findByTestId(testId));

    expect(container.findByText(expectedLabel, { selector: 'h4' }).exists()).toBe(true);
    expect(container.findByText(expectedDescription).exists()).toBe(true);
    expect(container.findByText(expectedInputDescription, { exact: false }).exists()).toBe(true);
    expect(container.findByText('reset this token').attributes()).toMatchObject({
      'data-confirm': expectedResetConfirmMessage,
      'data-method': 'put',
      href: expectedResetPath,
    });
    expect(container.props()).toMatchObject(expectedProps);
  };

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

  it('renders all enabled tokens', () => {
    createComponent();

    expectTokenRendered({
      testId: TokensApp.htmlAttributes[FEED_TOKEN].containerTestId,
      expectedLabel: TokensApp.i18n[FEED_TOKEN].label,
      expectedDescription: TokensApp.i18n[FEED_TOKEN].description,
      expectedInputDescription:
        'Keep this token secret. Anyone who has it can read activity and issue RSS feeds or your calendar feed as if they were you.',
      expectedResetPath: defaultProvide.tokenTypes[FEED_TOKEN].resetPath,
      expectedResetConfirmMessage: TokensApp.i18n[FEED_TOKEN].resetConfirmMessage,
      expectedProps: {
        token: defaultProvide.tokenTypes[FEED_TOKEN].token,
        inputId: TokensApp.htmlAttributes[FEED_TOKEN].inputId,
        inputLabel: TokensApp.i18n[FEED_TOKEN].label,
        copyButtonTitle: TokensApp.i18n[FEED_TOKEN].copyButtonTitle,
      },
    });

    expectTokenRendered({
      testId: TokensApp.htmlAttributes[INCOMING_EMAIL_TOKEN].containerTestId,
      expectedLabel: TokensApp.i18n[INCOMING_EMAIL_TOKEN].label,
      expectedDescription: TokensApp.i18n[INCOMING_EMAIL_TOKEN].description,
      expectedInputDescription:
        'Keep this token secret. Anyone who has it can create issues as if they were you.',
      expectedResetPath: defaultProvide.tokenTypes[INCOMING_EMAIL_TOKEN].resetPath,
      expectedResetConfirmMessage: TokensApp.i18n[INCOMING_EMAIL_TOKEN].resetConfirmMessage,
      expectedProps: {
        token: defaultProvide.tokenTypes[INCOMING_EMAIL_TOKEN].token,
        inputId: TokensApp.htmlAttributes[INCOMING_EMAIL_TOKEN].inputId,
        inputLabel: TokensApp.i18n[INCOMING_EMAIL_TOKEN].label,
        copyButtonTitle: TokensApp.i18n[INCOMING_EMAIL_TOKEN].copyButtonTitle,
      },
    });

    expectTokenRendered({
      testId: TokensApp.htmlAttributes[STATIC_OBJECT_TOKEN].containerTestId,
      expectedLabel: TokensApp.i18n[STATIC_OBJECT_TOKEN].label,
      expectedDescription: TokensApp.i18n[STATIC_OBJECT_TOKEN].description,
      expectedInputDescription:
        'Keep this token secret. Anyone who has it can access repository static objects as if they were you.',
      expectedResetPath: defaultProvide.tokenTypes[STATIC_OBJECT_TOKEN].resetPath,
      expectedResetConfirmMessage: TokensApp.i18n[STATIC_OBJECT_TOKEN].resetConfirmMessage,
      expectedProps: {
        token: defaultProvide.tokenTypes[STATIC_OBJECT_TOKEN].token,
        inputId: TokensApp.htmlAttributes[STATIC_OBJECT_TOKEN].inputId,
        inputLabel: TokensApp.i18n[STATIC_OBJECT_TOKEN].label,
        copyButtonTitle: TokensApp.i18n[STATIC_OBJECT_TOKEN].copyButtonTitle,
      },
    });
  });

  it("doesn't render disabled tokens", () => {
    createComponent({
      provide: {
        tokenTypes: {
          [FEED_TOKEN]: {
            enabled: false,
          },
        },
      },
    });

    expect(
      wrapper.findByTestId(TokensApp.htmlAttributes[FEED_TOKEN].containerTestId).exists(),
    ).toBe(false);
  });

  describe('when there are tokens missing an `i18n` definition', () => {
    it('renders without errors', () => {
      createComponent({
        provide: {
          tokenTypes: {
            fooBar: {
              enabled: true,
              token: 'rewjoa58dfm54jfkdlsdf',
              resetPath: '/-/profile/foo_bar',
            },
          },
        },
      });

      expect(
        wrapper.findByTestId(TokensApp.htmlAttributes[FEED_TOKEN].containerTestId).exists(),
      ).toBe(true);
    });
  });
});