BigW Consortium Gitlab

environment_item_spec.js 6.48 KB
Newer Older
1 2
import 'timeago.js';
import Vue from 'vue';
3
import environmentItemComp from '~/environments/components/environment_item.vue';
Filipa Lacerda committed
4

5
describe('Environment item', () => {
6 7
  let EnvironmentItem;

Filipa Lacerda committed
8
  beforeEach(() => {
9
    EnvironmentItem = Vue.extend(environmentItemComp);
Filipa Lacerda committed
10 11 12 13
  });

  describe('When item is folder', () => {
    let mockItem;
Filipa Lacerda committed
14
    let component;
Filipa Lacerda committed
15 16 17 18

    beforeEach(() => {
      mockItem = {
        name: 'review',
Filipa Lacerda committed
19
        folderName: 'review',
Filipa Lacerda committed
20 21
        size: 3,
        isFolder: true,
Filipa Lacerda committed
22
        environment_path: 'url',
Filipa Lacerda committed
23 24
      };

25
      component = new EnvironmentItem({
Filipa Lacerda committed
26 27
        propsData: {
          model: mockItem,
Filipa Lacerda committed
28 29
          canCreateDeployment: false,
          canReadEnvironment: true,
30
          service: {},
Filipa Lacerda committed
31
        },
32
      }).$mount();
Filipa Lacerda committed
33
    });
Filipa Lacerda committed
34

Filipa Lacerda committed
35
    it('Should render folder icon and name', () => {
Filipa Lacerda committed
36 37
      expect(component.$el.querySelector('.folder-name').textContent).toContain(mockItem.name);
      expect(component.$el.querySelector('.folder-icon')).toBeDefined();
Filipa Lacerda committed
38 39 40
    });

    it('Should render the number of children in a badge', () => {
41
      expect(component.$el.querySelector('.folder-name .badge').textContent).toContain(mockItem.size);
Filipa Lacerda committed
42 43 44 45
    });
  });

  describe('when item is not folder', () => {
Filipa Lacerda committed
46
    let environment;
Filipa Lacerda committed
47
    let component;
Filipa Lacerda committed
48 49 50 51

    beforeEach(() => {
      environment = {
        name: 'production',
52
        size: 1,
Filipa Lacerda committed
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
        state: 'stopped',
        external_url: 'http://external.com',
        environment_type: null,
        last_deployment: {
          id: 66,
          iid: 6,
          sha: '500aabcb17c97bdcf2d0c410b70cb8556f0362dd',
          ref: {
            name: 'master',
            ref_path: 'root/ci-folders/tree/master',
          },
          tag: true,
          'last?': true,
          user: {
            name: 'Administrator',
            username: 'root',
            id: 1,
            state: 'active',
            avatar_url: 'http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon',
            web_url: 'http://localhost:3000/root',
          },
          commit: {
            id: '500aabcb17c97bdcf2d0c410b70cb8556f0362dd',
            short_id: '500aabcb',
            title: 'Update .gitlab-ci.yml',
            author_name: 'Administrator',
            author_email: 'admin@example.com',
            created_at: '2016-11-07T18:28:13.000+00:00',
            message: 'Update .gitlab-ci.yml',
            author: {
Filipa Lacerda committed
83 84 85 86 87 88 89
              name: 'Administrator',
              username: 'root',
              id: 1,
              state: 'active',
              avatar_url: 'http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon',
              web_url: 'http://localhost:3000/root',
            },
Filipa Lacerda committed
90
            commit_path: '/root/ci-folders/tree/500aabcb17c97bdcf2d0c410b70cb8556f0362dd',
91
          },
Filipa Lacerda committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105
          deployable: {
            id: 1279,
            name: 'deploy',
            build_path: '/root/ci-folders/builds/1279',
            retry_path: '/root/ci-folders/builds/1279/retry',
            created_at: '2016-11-29T18:11:58.430Z',
            updated_at: '2016-11-29T18:11:58.430Z',
          },
          manual_actions: [
            {
              name: 'action',
              play_path: '/play',
            },
          ],
Filipa Lacerda committed
106
        },
Filipa Lacerda committed
107 108 109 110
        'stop_action?': true,
        environment_path: 'root/ci-folders/environments/31',
        created_at: '2016-11-07T11:11:16.525Z',
        updated_at: '2016-11-10T15:55:58.778Z',
Filipa Lacerda committed
111 112
      };

113
      component = new EnvironmentItem({
Filipa Lacerda committed
114 115
        propsData: {
          model: environment,
Filipa Lacerda committed
116 117
          canCreateDeployment: true,
          canReadEnvironment: true,
118
          service: {},
Filipa Lacerda committed
119
        },
120
      }).$mount();
Filipa Lacerda committed
121
    });
Filipa Lacerda committed
122

Filipa Lacerda committed
123
    it('should render environment name', () => {
Filipa Lacerda committed
124
      expect(component.$el.querySelector('.environment-name').textContent).toContain(environment.name);
Filipa Lacerda committed
125 126 127 128
    });

    describe('With deployment', () => {
      it('should render deployment internal id', () => {
Filipa Lacerda committed
129
        expect(
130
          component.$el.querySelector('.deployment-column span').textContent,
Filipa Lacerda committed
131
        ).toContain(environment.last_deployment.iid);
Filipa Lacerda committed
132

Filipa Lacerda committed
133
        expect(
134
          component.$el.querySelector('.deployment-column span').textContent,
Filipa Lacerda committed
135
        ).toContain('#');
Filipa Lacerda committed
136 137
      });

138 139 140
      it('should render last deployment date', () => {
        const timeagoInstance = new timeago(); // eslint-disable-line
        const formatedDate = timeagoInstance.format(
Filipa Lacerda committed
141
          environment.last_deployment.deployable.created_at,
142 143 144
        );

        expect(
145
          component.$el.querySelector('.environment-created-date-timeago').textContent,
146 147 148
        ).toContain(formatedDate);
      });

Filipa Lacerda committed
149 150
      describe('With user information', () => {
        it('should render user avatar with link to profile', () => {
Filipa Lacerda committed
151
          expect(
152
            component.$el.querySelector('.js-deploy-user-container').getAttribute('href'),
Filipa Lacerda committed
153
          ).toEqual(environment.last_deployment.user.web_url);
Filipa Lacerda committed
154 155 156 157 158
        });
      });

      describe('With build url', () => {
        it('Should link to build url provided', () => {
Filipa Lacerda committed
159
          expect(
160
            component.$el.querySelector('.build-link').getAttribute('href'),
Filipa Lacerda committed
161
          ).toEqual(environment.last_deployment.deployable.build_path);
Filipa Lacerda committed
162 163 164
        });

        it('Should render deployable name and id', () => {
Filipa Lacerda committed
165
          expect(
166
            component.$el.querySelector('.build-link').getAttribute('href'),
Filipa Lacerda committed
167
          ).toEqual(environment.last_deployment.deployable.build_path);
Filipa Lacerda committed
168 169 170 171
        });
      });

      describe('With commit information', () => {
Filipa Lacerda committed
172 173
        it('should render commit component', () => {
          expect(
174
            component.$el.querySelector('.js-commit-component'),
Filipa Lacerda committed
175 176
          ).toBeDefined();
        });
Filipa Lacerda committed
177 178 179 180
      });
    });

    describe('With manual actions', () => {
Filipa Lacerda committed
181 182
      it('Should render actions component', () => {
        expect(
183
          component.$el.querySelector('.js-manual-actions-container'),
Filipa Lacerda committed
184
        ).toBeDefined();
Filipa Lacerda committed
185 186 187 188 189
      });
    });

    describe('With external URL', () => {
      it('should render external url component', () => {
Filipa Lacerda committed
190
        expect(
191
          component.$el.querySelector('.js-external-url-container'),
Filipa Lacerda committed
192
        ).toBeDefined();
Filipa Lacerda committed
193 194 195 196
      });
    });

    describe('With stop action', () => {
Filipa Lacerda committed
197 198
      it('Should render stop action component', () => {
        expect(
199
          component.$el.querySelector('.js-stop-component-container'),
Filipa Lacerda committed
200
        ).toBeDefined();
Filipa Lacerda committed
201 202 203 204
      });
    });

    describe('With retry action', () => {
Filipa Lacerda committed
205 206
      it('Should render rollback component', () => {
        expect(
207
          component.$el.querySelector('.js-rollback-component-container'),
Filipa Lacerda committed
208
        ).toBeDefined();
Filipa Lacerda committed
209 210 211 212
      });
    });
  });
});