summaryrefslogtreecommitdiff
path: root/spec/javascripts/vue_shared/components/identicon_spec.js
blob: 647680f00f76ae93b9283318105f2abb7406a015 (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
import Vue from 'vue';
import identiconComponent from '~/vue_shared/components/identicon.vue';

const createComponent = (sizeClass) => {
  const Component = Vue.extend(identiconComponent);

  return new Component({
    propsData: {
      entityId: 1,
      entityName: 'entity-name',
      sizeClass,
    },
  }).$mount();
};

describe('IdenticonComponent', () => {
  describe('computed', () => {
    let vm;

    beforeEach(() => {
      vm = createComponent();
    });

    afterEach(() => {
      vm.$destroy();
    });

    describe('identiconStyles', () => {
      it('should return styles attribute value with `background-color` property', () => {
        vm.entityId = 4;

        expect(vm.identiconStyles).toBeDefined();
        expect(vm.identiconStyles.indexOf('background-color: #E0F2F1;') > -1).toBeTruthy();
      });

      it('should return styles attribute value with `color` property', () => {
        vm.entityId = 4;

        expect(vm.identiconStyles).toBeDefined();
        expect(vm.identiconStyles.indexOf('color: #555;') > -1).toBeTruthy();
      });
    });

    describe('identiconTitle', () => {
      it('should return first letter of entity title in uppercase', () => {
        vm.entityName = 'dummy-group';

        expect(vm.identiconTitle).toBeDefined();
        expect(vm.identiconTitle).toBe('D');
      });
    });
  });

  describe('template', () => {
    it('should render identicon', () => {
      const vm = createComponent();

      expect(vm.$el.nodeName).toBe('DIV');
      expect(vm.$el.classList.contains('identicon')).toBeTruthy();
      expect(vm.$el.classList.contains('s40')).toBeTruthy();
      expect(vm.$el.getAttribute('style').indexOf('background-color') > -1).toBeTruthy();
      vm.$destroy();
    });

    it('should render identicon with provided sizing class', () => {
      const vm = createComponent('s32');

      expect(vm.$el.classList.contains('s32')).toBeTruthy();
      vm.$destroy();
    });
  });
});