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

ml_experiment_spec.js « components « experiment_tracking « ml « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: abcaf17303fd1597d344325f8dc7c4f38486c628 (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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { GlAlert, GlPagination } from '@gitlab/ui';
import { mountExtended } from 'helpers/vue_test_utils_helper';
import MlExperiment from '~/ml/experiment_tracking/components/ml_experiment.vue';

describe('MlExperiment', () => {
  let wrapper;

  const createWrapper = (
    candidates = [],
    metricNames = [],
    paramNames = [],
    pagination = { page: 1, isLastPage: false, per_page: 2, totalItems: 0 },
  ) => {
    return mountExtended(MlExperiment, {
      provide: { candidates, metricNames, paramNames, pagination },
    });
  };

  const findAlert = () => wrapper.findComponent(GlAlert);

  const findEmptyState = () => wrapper.findByText('This experiment has no logged candidates');

  it('shows incubation warning', () => {
    wrapper = createWrapper();

    expect(findAlert().exists()).toBe(true);
  });

  describe('no candidates', () => {
    it('shows empty state', () => {
      wrapper = createWrapper();

      expect(findEmptyState().exists()).toBe(true);
    });

    it('does not show pagination', () => {
      wrapper = createWrapper();

      expect(wrapper.findComponent(GlPagination).exists()).toBe(false);
    });
  });

  describe('with candidates', () => {
    const defaultPagination = { page: 1, isLastPage: false, per_page: 2, totalItems: 5 };

    const createWrapperWithCandidates = (pagination = defaultPagination) => {
      return createWrapper(
        [
          {
            rmse: 1,
            l1_ratio: 0.4,
            details: 'link_to_candidate1',
            artifact: 'link_to_artifact',
            name: 'aCandidate',
            created_at: '2023-01-05T14:07:02.975Z',
            user: { username: 'root', path: '/root' },
          },
          {
            auc: 0.3,
            l1_ratio: 0.5,
            details: 'link_to_candidate2',
            created_at: '2023-01-05T14:07:02.975Z',
            name: null,
            user: null,
          },
          {
            auc: 0.3,
            l1_ratio: 0.5,
            details: 'link_to_candidate3',
            created_at: '2023-01-05T14:07:02.975Z',
            name: null,
            user: null,
          },
          {
            auc: 0.3,
            l1_ratio: 0.5,
            details: 'link_to_candidate4',
            created_at: '2023-01-05T14:07:02.975Z',
            name: null,
            user: null,
          },
          {
            auc: 0.3,
            l1_ratio: 0.5,
            details: 'link_to_candidate5',
            created_at: '2023-01-05T14:07:02.975Z',
            name: null,
            user: null,
          },
        ],
        ['rmse', 'auc', 'mae'],
        ['l1_ratio'],
        pagination,
      );
    };

    it('renders correctly', () => {
      wrapper = createWrapperWithCandidates();

      expect(wrapper.element).toMatchSnapshot();
    });

    describe('Pagination behaviour', () => {
      it('should show', () => {
        wrapper = createWrapperWithCandidates();

        expect(wrapper.findComponent(GlPagination).exists()).toBe(true);
      });

      it('should get the page number from the URL', () => {
        wrapper = createWrapperWithCandidates({ ...defaultPagination, page: 2 });

        expect(wrapper.findComponent(GlPagination).props().value).toBe(2);
      });

      it('should not have a prevPage if the page is 1', () => {
        wrapper = createWrapperWithCandidates();

        expect(wrapper.findComponent(GlPagination).props().prevPage).toBe(null);
      });

      it('should set the prevPage to 1 if the page is 2', () => {
        wrapper = createWrapperWithCandidates({ ...defaultPagination, page: 2 });

        expect(wrapper.findComponent(GlPagination).props().prevPage).toBe(1);
      });

      it('should not have a nextPage if isLastPage is true', async () => {
        wrapper = createWrapperWithCandidates({ ...defaultPagination, isLastPage: true });

        expect(wrapper.findComponent(GlPagination).props().nextPage).toBe(null);
      });

      it('should set the nextPage to 2 if the page is 1', () => {
        wrapper = createWrapperWithCandidates();

        expect(wrapper.findComponent(GlPagination).props().nextPage).toBe(2);
      });
    });
  });
});