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

show_ml_model_spec.js « apps « model_registry « ml « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bc4770976a9d0d6b908fb1393e67250f5919b0d5 (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
import { GlBadge, GlTab } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { ShowMlModel } from '~/ml/model_registry/apps';
import TitleArea from '~/vue_shared/components/registry/title_area.vue';
import MetadataItem from '~/vue_shared/components/registry/metadata_item.vue';
import { NO_VERSIONS_LABEL } from '~/ml/model_registry/translations';
import { MODEL, makeModel } from '../mock_data';

let wrapper;
const createWrapper = (model = MODEL) => {
  wrapper = shallowMount(ShowMlModel, { propsData: { model } });
};

const findDetailTab = () => wrapper.findAllComponents(GlTab).at(0);
const findVersionsTab = () => wrapper.findAllComponents(GlTab).at(1);
const findVersionsCountBadge = () => findVersionsTab().findComponent(GlBadge);
const findCandidateTab = () => wrapper.findAllComponents(GlTab).at(2);
const findCandidatesCountBadge = () => findCandidateTab().findComponent(GlBadge);
const findTitleArea = () => wrapper.findComponent(TitleArea);
const findVersionCountMetadataItem = () => findTitleArea().findComponent(MetadataItem);

describe('ShowMlModel', () => {
  describe('Title', () => {
    beforeEach(() => createWrapper());

    it('title is set to model name', () => {
      expect(findTitleArea().props('title')).toBe(MODEL.name);
    });

    it('subheader is set to description', () => {
      expect(findTitleArea().text()).toContain(MODEL.description);
    });

    it('sets version metadata item to version count', () => {
      expect(findVersionCountMetadataItem().props('text')).toBe(`${MODEL.versionCount} versions`);
    });
  });

  describe('Details', () => {
    beforeEach(() => createWrapper());

    it('has a details tab', () => {
      expect(findDetailTab().attributes('title')).toBe('Details');
    });

    describe('when it has latest version', () => {
      it('displays the version', () => {
        expect(findDetailTab().text()).toContain(MODEL.latestVersion.version);
      });
    });

    describe('when it does not have latest version', () => {
      beforeEach(() => {
        createWrapper(makeModel({ latestVersion: null }));
      });

      it('shows no version message', () => {
        expect(findDetailTab().text()).toContain(NO_VERSIONS_LABEL);
      });
    });
  });

  describe('Versions tab', () => {
    beforeEach(() => createWrapper());

    it('shows the number of versions in the tab', () => {
      expect(findVersionsCountBadge().text()).toBe(MODEL.versionCount.toString());
    });
  });

  describe('Candidates tab', () => {
    beforeEach(() => createWrapper());

    it('shows the number of candidates in the tab', () => {
      expect(findCandidatesCountBadge().text()).toBe(MODEL.candidateCount.toString());
    });
  });
});