environment_item_spec.js.es6 6.7 KB
Newer Older
F
Filipa Lacerda 已提交
1 2 3 4 5 6 7 8 9 10 11
//= require vue
//= require environments/components/environment_item

describe('Environment item', () => {
  fixture.preload('environments/table.html');
  beforeEach(() => {
    fixture.load('environments/table.html');
  });

  describe('When item is folder', () => {
    let mockItem;
F
Filipa Lacerda 已提交
12
    let component;
F
Filipa Lacerda 已提交
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

    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',
          },
        ],
      };

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

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

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

  describe('when item is not folder', () => {
F
Filipa Lacerda 已提交
61
    let environment;
F
Filipa Lacerda 已提交
62
    let component;
F
Filipa Lacerda 已提交
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

    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',
            ref_url: 'http://localhost:3000/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: {
              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_url: 'http://localhost:3000/root/ci-folders/tree/500aabcb17c97bdcf2d0c410b70cb8556f0362dd',
          },
          deployable: {
            id: 1279,
            name: 'deploy',
            build_url: 'http://localhost:3000/root/ci-folders/builds/1279',
            retry_url: 'http://localhost:3000/root/ci-folders/builds/1279/retry',
          },
          manual_actions: [
            {
              name: 'action',
              play_url: 'http://localhost:3000/play',
            },
          ],
        },
        'stoppable?': true,
        environment_url: 'http://localhost:3000/root/ci-folders/environments/31',
        created_at: '2016-11-07T11:11:16.525Z',
        updated_at: '2016-11-10T15:55:58.778Z',
      };

F
Filipa Lacerda 已提交
126
      component = new window.gl.environmentsList.EnvironmentItem({
F
Filipa Lacerda 已提交
127 128 129 130
        el: document.querySelector('tr#environment-row'),
        propsData: {
          model: environment,
          toggleRow: () => {},
F
Filipa Lacerda 已提交
131 132
          canCreateDeployment: true,
          canReadEnvironment: true,
F
Filipa Lacerda 已提交
133 134
        },
      });
F
Filipa Lacerda 已提交
135
    });
F
Filipa Lacerda 已提交
136

F
Filipa Lacerda 已提交
137 138
    it('should render environment name', () => {
      expect(component.$el.querySelector('.environment-name').textContent).toEqual(environment.name);
F
Filipa Lacerda 已提交
139 140 141 142
    });

    describe('With deployment', () => {
      it('should render deployment internal id', () => {
F
Filipa Lacerda 已提交
143 144 145
        expect(
          component.$el.querySelector('.deployment-column span').textContent
        ).toContain(environment.last_deployment.iid);
F
Filipa Lacerda 已提交
146

F
Filipa Lacerda 已提交
147 148 149
        expect(
          component.$el.querySelector('.deployment-column span').textContent
        ).toContain('#');
F
Filipa Lacerda 已提交
150 151 152 153
      });

      describe('With user information', () => {
        it('should render user avatar with link to profile', () => {
F
Filipa Lacerda 已提交
154 155 156
          expect(
            component.$el.querySelector('.js-deploy-user-container').getAttribute('href')
          ).toEqual(environment.last_deployment.user.web_url);
F
Filipa Lacerda 已提交
157 158 159 160 161
        });
      });

      describe('With build url', () => {
        it('Should link to build url provided', () => {
F
Filipa Lacerda 已提交
162 163 164
          expect(
            component.$el.querySelector('.build-link').getAttribute('href')
          ).toEqual(environment.last_deployment.deployable.build_url);
F
Filipa Lacerda 已提交
165 166 167
        });

        it('Should render deployable name and id', () => {
F
Filipa Lacerda 已提交
168 169 170
          expect(
            component.$el.querySelector('.build-link').getAttribute('href')
          ).toEqual(environment.last_deployment.deployable.build_url);
F
Filipa Lacerda 已提交
171 172 173 174
        });
      });

      describe('With commit information', () => {
F
Filipa Lacerda 已提交
175 176 177 178 179
        it('should render commit component', () => {
          expect(
            component.$el.querySelector('.js-commit-component')
          ).toBeDefined();
        });
F
Filipa Lacerda 已提交
180 181 182 183
      });
    });

    describe('With manual actions', () => {
F
Filipa Lacerda 已提交
184 185 186 187
      it('Should render actions component', () => {
        expect(
          component.$el.querySelector('.js-manual-actions-container')
        ).toBeDefined();
F
Filipa Lacerda 已提交
188 189 190 191 192
      });
    });

    describe('With external URL', () => {
      it('should render external url component', () => {
F
Filipa Lacerda 已提交
193 194 195
        expect(
          component.$el.querySelector('.js-external-url-container')
        ).toBeDefined();
F
Filipa Lacerda 已提交
196 197 198 199
      });
    });

    describe('With stop action', () => {
F
Filipa Lacerda 已提交
200 201 202 203
      it('Should render stop action component', () => {
        expect(
          component.$el.querySelector('.js-stop-component-container')
        ).toBeDefined();
F
Filipa Lacerda 已提交
204 205 206 207
      });
    });

    describe('With retry action', () => {
F
Filipa Lacerda 已提交
208 209 210 211
      it('Should render rollback component', () => {
        expect(
          component.$el.querySelector('.js-rollback-component-container')
        ).toBeDefined();
F
Filipa Lacerda 已提交
212 213 214 215
      });
    });
  });
});