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

search_type_indicator_spec.js « components « topbar « search « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d69ca6dfb16e8aa4c8cdaaf4f7486f36eed4a9d6 (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
import Vue from 'vue';
// eslint-disable-next-line no-restricted-imports
import Vuex from 'vuex';
import { GlSprintf } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { MOCK_QUERY } from 'jest/search/mock_data';
import SearchTypeIndicator from '~/search/topbar/components/search_type_indicator.vue';

Vue.use(Vuex);

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

  const actionSpies = {
    applyQuery: jest.fn(),
    setQuery: jest.fn(),
    preloadStoredFrequentItems: jest.fn(),
  };

  const createComponent = (initialState = {}) => {
    const store = new Vuex.Store({
      state: {
        query: MOCK_QUERY,
        ...initialState,
      },
      actions: actionSpies,
    });

    wrapper = shallowMountExtended(SearchTypeIndicator, {
      store,
      stubs: {
        GlSprintf,
      },
    });
  };

  const findIndicator = (id) => wrapper.findAllByTestId(id);
  const findDocsLink = () => wrapper.findComponentByTestId('docs-link');
  const findSyntaxDocsLink = () => wrapper.findComponentByTestId('syntax-docs-link');

  // searchType and search level params cobination in this test reflects
  // all possible combinations

  describe.each`
    searchType    | searchLevel  | repository  | showSearchTypeIndicator
    ${'advanced'} | ${'project'} | ${'master'} | ${'advanced-enabled'}
    ${'advanced'} | ${'project'} | ${'v0.1'}   | ${'advanced-disabled'}
    ${'advanced'} | ${'group'}   | ${'master'} | ${'advanced-enabled'}
    ${'advanced'} | ${'global'}  | ${'master'} | ${'advanced-enabled'}
    ${'zoekt'}    | ${'project'} | ${'master'} | ${'zoekt-enabled'}
    ${'zoekt'}    | ${'project'} | ${'v0.1'}   | ${'zoekt-disabled'}
    ${'zoekt'}    | ${'group'}   | ${'master'} | ${'zoekt-enabled'}
  `(
    'search type indicator for $searchType $searchLevel',
    ({ searchType, repository, showSearchTypeIndicator, searchLevel }) => {
      beforeEach(() => {
        createComponent({
          query: { repository_ref: repository },
          searchType,
          searchLevel,
          defaultBranchName: 'master',
        });
      });
      it('renders correctly', () => {
        expect(findIndicator(showSearchTypeIndicator).exists()).toBe(true);
      });
    },
  );

  describe.each`
    searchType | repository  | showSearchTypeIndicator
    ${'basic'} | ${'master'} | ${true}
    ${'basic'} | ${'v0.1'}   | ${true}
  `(
    'search type indicator for $searchType and $repository',
    ({ searchType, repository, showSearchTypeIndicator }) => {
      beforeEach(() => {
        createComponent({
          query: { repository_ref: repository },
          searchType,
          defaultBranchName: 'master',
        });
      });
      it.each(['zoekt-enabled', 'zoekt-disabled', 'advanced-enabled', 'advanced-disabled'])(
        'renders correct indicator %s',
        () => {
          expect(findIndicator(searchType).exists()).toBe(showSearchTypeIndicator);
        },
      );
    },
  );

  describe.each`
    searchType    | docsLink
    ${'advanced'} | ${'/help/user/search/advanced_search'}
    ${'zoekt'}    | ${'/help/user/search/exact_code_search'}
  `('documentation link for $searchType', ({ searchType, docsLink }) => {
    beforeEach(() => {
      createComponent({
        query: { repository_ref: 'master' },
        searchType,
        searchLevel: 'project',
        defaultBranchName: 'master',
      });
    });
    it('has correct link', () => {
      expect(findDocsLink().attributes('href')).toBe(docsLink);
    });
  });

  describe.each`
    searchType    | syntaxdocsLink
    ${'advanced'} | ${'/help/user/search/advanced_search#use-the-advanced-search-syntax'}
    ${'zoekt'}    | ${'/help/user/search/exact_code_search#syntax'}
  `('Syntax documentation $searchType', ({ searchType, syntaxdocsLink }) => {
    beforeEach(() => {
      createComponent({
        query: { repository_ref: '000' },
        searchType,
        searchLevel: 'project',
        defaultBranchName: 'master',
      });
    });
    it('has correct link', () => {
      expect(findSyntaxDocsLink().attributes('href')).toBe(syntaxdocsLink);
    });
  });
});