BigW Consortium Gitlab

environment_item_spec.js.es6 7.12 KB
Newer Older
Filipa Lacerda committed
1
//= require vue
2
//= require timeago
Filipa Lacerda committed
3 4 5
//= require environments/components/environment_item

describe('Environment item', () => {
6
  preloadFixtures('static/environments/table.html.raw');
Filipa Lacerda committed
7
  beforeEach(() => {
8
    loadFixtures('static/environments/table.html.raw');
Filipa Lacerda committed
9 10 11 12
  });

  describe('When item is folder', () => {
    let mockItem;
Filipa Lacerda committed
13
    let component;
Filipa Lacerda committed
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

    beforeEach(() => {
      mockItem = {
        name: 'review',
        children: [
          {
            name: 'review-app',
            id: 1,
            state: 'available',
            external_url: '',
            last_deployment: {},
            created_at: '2016-11-07T11:11:16.525Z',
            updated_at: '2016-11-10T15:55:58.778Z',
          },
          {
            name: 'production',
            id: 2,
            state: 'available',
            external_url: '',
            last_deployment: {},
            created_at: '2016-11-07T11:11:16.525Z',
            updated_at: '2016-11-10T15:55:58.778Z',
          },
        ],
      };

Filipa Lacerda committed
40
      component = new window.gl.environmentsList.EnvironmentItem({
Filipa Lacerda committed
41 42 43
        el: document.querySelector('tr#environment-row'),
        propsData: {
          model: mockItem,
Filipa Lacerda committed
44
          toggleRow: () => {},
Filipa Lacerda committed
45 46
          canCreateDeployment: false,
          canReadEnvironment: true,
Filipa Lacerda committed
47 48
        },
      });
Filipa Lacerda committed
49
    });
Filipa Lacerda committed
50

Filipa Lacerda committed
51
    it('Should render folder icon and name', () => {
Filipa Lacerda committed
52 53
      expect(component.$el.querySelector('.folder-name').textContent).toContain(mockItem.name);
      expect(component.$el.querySelector('.folder-icon')).toBeDefined();
Filipa Lacerda committed
54 55 56
    });

    it('Should render the number of children in a badge', () => {
Filipa Lacerda committed
57
      expect(component.$el.querySelector('.folder-name .badge').textContent).toContain(mockItem.children.length);
Filipa Lacerda committed
58 59 60 61
    });
  });

  describe('when item is not folder', () => {
Filipa Lacerda committed
62
    let environment;
Filipa Lacerda committed
63
    let component;
Filipa Lacerda committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77

    beforeEach(() => {
      environment = {
        id: 31,
        name: 'production',
        state: 'stopped',
        external_url: 'http://external.com',
        environment_type: null,
        last_deployment: {
          id: 66,
          iid: 6,
          sha: '500aabcb17c97bdcf2d0c410b70cb8556f0362dd',
          ref: {
            name: 'master',
Filipa Lacerda committed
78
            ref_path: 'root/ci-folders/tree/master',
Filipa Lacerda committed
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
          },
          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: {
              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
106
            commit_path: '/root/ci-folders/tree/500aabcb17c97bdcf2d0c410b70cb8556f0362dd',
Filipa Lacerda committed
107 108 109 110
          },
          deployable: {
            id: 1279,
            name: 'deploy',
Filipa Lacerda committed
111 112
            build_path: '/root/ci-folders/builds/1279',
            retry_path: '/root/ci-folders/builds/1279/retry',
113 114
            created_at: '2016-11-29T18:11:58.430Z',
            updated_at: '2016-11-29T18:11:58.430Z',
Filipa Lacerda committed
115 116 117 118
          },
          manual_actions: [
            {
              name: 'action',
Filipa Lacerda committed
119
              play_path: '/play',
Filipa Lacerda committed
120 121 122 123
            },
          ],
        },
        'stoppable?': true,
Filipa Lacerda committed
124
        environment_path: 'root/ci-folders/environments/31',
Filipa Lacerda committed
125 126 127 128
        created_at: '2016-11-07T11:11:16.525Z',
        updated_at: '2016-11-10T15:55:58.778Z',
      };

Filipa Lacerda committed
129
      component = new window.gl.environmentsList.EnvironmentItem({
Filipa Lacerda committed
130 131 132 133
        el: document.querySelector('tr#environment-row'),
        propsData: {
          model: environment,
          toggleRow: () => {},
Filipa Lacerda committed
134 135
          canCreateDeployment: true,
          canReadEnvironment: true,
Filipa Lacerda committed
136 137
        },
      });
Filipa Lacerda committed
138
    });
Filipa Lacerda committed
139

Filipa Lacerda committed
140
    it('should render environment name', () => {
Filipa Lacerda committed
141
      expect(component.$el.querySelector('.environment-name').textContent).toContain(environment.name);
Filipa Lacerda committed
142 143 144 145
    });

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

Filipa Lacerda committed
150
        expect(
151
          component.$el.querySelector('.deployment-column span').textContent,
Filipa Lacerda committed
152
        ).toContain('#');
Filipa Lacerda committed
153 154
      });

155 156 157
      it('should render last deployment date', () => {
        const timeagoInstance = new timeago(); // eslint-disable-line
        const formatedDate = timeagoInstance.format(
158
          environment.last_deployment.deployable.created_at,
159 160 161
        );

        expect(
162
          component.$el.querySelector('.environment-created-date-timeago').textContent,
163 164 165
        ).toContain(formatedDate);
      });

Filipa Lacerda committed
166 167
      describe('With user information', () => {
        it('should render user avatar with link to profile', () => {
Filipa Lacerda committed
168
          expect(
169
            component.$el.querySelector('.js-deploy-user-container').getAttribute('href'),
Filipa Lacerda committed
170
          ).toEqual(environment.last_deployment.user.web_url);
Filipa Lacerda committed
171 172 173 174 175
        });
      });

      describe('With build url', () => {
        it('Should link to build url provided', () => {
Filipa Lacerda committed
176
          expect(
177
            component.$el.querySelector('.build-link').getAttribute('href'),
Filipa Lacerda committed
178
          ).toEqual(environment.last_deployment.deployable.build_path);
Filipa Lacerda committed
179 180 181
        });

        it('Should render deployable name and id', () => {
Filipa Lacerda committed
182
          expect(
183
            component.$el.querySelector('.build-link').getAttribute('href'),
Filipa Lacerda committed
184
          ).toEqual(environment.last_deployment.deployable.build_path);
Filipa Lacerda committed
185 186 187 188
        });
      });

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

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

    describe('With external URL', () => {
      it('should render external url component', () => {
Filipa Lacerda committed
207
        expect(
208
          component.$el.querySelector('.js-external-url-container'),
Filipa Lacerda committed
209
        ).toBeDefined();
Filipa Lacerda committed
210 211 212 213
      });
    });

    describe('With stop action', () => {
Filipa Lacerda committed
214 215
      it('Should render stop action component', () => {
        expect(
216
          component.$el.querySelector('.js-stop-component-container'),
Filipa Lacerda committed
217
        ).toBeDefined();
Filipa Lacerda committed
218 219 220 221
      });
    });

    describe('With retry action', () => {
Filipa Lacerda committed
222 223
      it('Should render rollback component', () => {
        expect(
224
          component.$el.querySelector('.js-rollback-component-container'),
Filipa Lacerda committed
225
        ).toBeDefined();
Filipa Lacerda committed
226 227 228 229
      });
    });
  });
});