<commit_before>import { mount, createLocalVue } from '@vue/test-utils'
import { DropdownPlugin } from 'bootstrap-vue'
import SearchDropdown from '~/components/SearchDropdown'

const localVue = createLocalVue()

localVue.use(DropdownPlugin)

const factory = (props = {}, route = {}) => {
  return mount(SearchDropdown, {
    localVue,
    propsData: props,
    stubs: {
      fa: true
    },
    mocks: {
      $route: route
    }
  })
}

const props = {
  label: 'Tags',
  query: 'tag',
  items: ['tag1', 'tag2', 'tag3']
}
const route = {
  query: { tag: '' }
}
let wrapper

test('label', () => {
  const text = (wrapper) => {
    return wrapper.find('button').text()
  }
  wrapper = factory(props, route)
  expect(text(wrapper)).toBe('Tags')

  route.query = { tag: 'tag1' }
  wrapper = factory(props, route)
  expect(text(wrapper)).toBe('tag1')
})

test('query: none', () => {
  wrapper = factory(props, route)
  const a = wrapper.findAll('a')
  expect(a.at(0).attributes('href')).toBe('/')
  expect(a.at(1).attributes('href')).toBe('?tag=tag1')
})

test('query: tag=tag1', () => {
  route.query = { tag: 'tag1' }
  wrapper = factory(props, route)
  const a = wrapper.findAll('a')
  expect(a.at(0).attributes('href')).toBe('/')
  expect(a.at(1).attributes('href')).toBe('?tag=tag1')
})

test('query: country=country1', () => {
  route.query = { country: 'country1' }
  wrapper = factory(props, route)
  const a = wrapper.findAll('a')
  expect(a.at(0).attributes('href')).toBe('?country=country1')
  expect(a.at(1).attributes('href')).toBe('?country=country1&tag=tag1')
})

test('query: country=country1&tag=tag2', () => {
  route.query = { country: 'country1', tag: 'tag2' }
  wrapper = factory(props, route)
  const a = wrapper.findAll('a')
  expect(a.at(0).attributes('href')).toBe('?country=country1')
  expect(a.at(1).attributes('href')).toBe('?country=country1&tag=tag1')
})

test('query: search=foo', () => {
  route.query = { search: 'foo' }
  wrapper = factory(props, route)
  const a = wrapper.findAll('a')
  expect(a.at(0).attributes('href')).toBe('?search=foo')
  expect(a.at(1).attributes('href')).toBe('?tag=tag1')
})

test('query: page=2', () => {
  route.query = { page: '2' }
  wrapper = factory(props, route)
  const a = wrapper.findAll('a')
  expect(a.at(0).attributes('href')).toBe('/')
  expect(a.at(1).attributes('href')).toBe('?tag=tag1')
})<commit_msg>Improve testing for SearchDropdown component<commit_after>import { shallowMount } from '@vue/test-utils'
import { BDropdown, BDropdownItem } from 'bootstrap-vue'
import SearchDropdown from '~/components/SearchDropdown'

const factory = ({ props, route }) => {
  return shallowMount(SearchDropdown, {
    propsData: props,
    stubs: {
      BDropdown,
      BDropdownDivider: true,
      BDropdownItem,
      fa: true
    },
    mocks: {
      $route: route
    }
  })
}

const props = {
  label: 'Tags',
  query: 'tag',
  items: ['tag1', 'tag2', 'tag3']
}
const route = {
  query: { tag: '' }
}
let wrapper

test('label', () => {
  const text = (wrapper) => {
    return wrapper.find('button').text()
  }
  wrapper = factory({ props, route })
  expect(text(wrapper)).toBe('Tags')

  route.query = { tag: 'tag1' }
  wrapper = factory({ props, route })
  expect(text(wrapper)).toBe('tag1')
})

test('query: none', () => {
  wrapper = factory({ props, route })
  const a = wrapper.findAll('a')
  expect(a.at(0).attributes('href')).toBe('/')
  expect(a.at(1).attributes('href')).toBe('?tag=tag1')
})

test('query: tag=tag1', () => {
  route.query = { tag: 'tag1' }
  wrapper = factory({ props, route })
  const a = wrapper.findAll('a')
  expect(a.at(0).attributes('href')).toBe('/')
  expect(a.at(1).attributes('href')).toBe('?tag=tag1')
})

test('query: country=country1', () => {
  route.query = { country: 'country1' }
  wrapper = factory({ props, route })
  const a = wrapper.findAll('a')
  expect(a.at(0).attributes('href')).toBe('?country=country1')
  expect(a.at(1).attributes('href')).toBe('?country=country1&tag=tag1')
})

test('query: country=country1&tag=tag2', () => {
  route.query = { country: 'country1', tag: 'tag2' }
  wrapper = factory({ props, route })
  const a = wrapper.findAll('a')
  expect(a.at(0).attributes('href')).toBe('?country=country1')
  expect(a.at(1).attributes('href')).toBe('?country=country1&tag=tag1')
})

test('query: search=foo', () => {
  route.query = { search: 'foo' }
  wrapper = factory({ props, route })
  const a = wrapper.findAll('a')
  expect(a.at(0).attributes('href')).toBe('?search=foo')
  expect(a.at(1).attributes('href')).toBe('?tag=tag1')
})

test('query: page=2', () => {
  route.query = { page: '2' }
  wrapper = factory({ props, route })
  const a = wrapper.findAll('a')
  expect(a.at(0).attributes('href')).toBe('/')
  expect(a.at(1).attributes('href')).toBe('?tag=tag1')
})
{'fraction_non_alphanumeric': 0.22316971713810316, 'fraction_numerical': 0.015391014975041598, 'mean_word_length': 4.41554054054054, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5428915', 'n_tokens_mistral': 1722, 'n_tokens_neox': 1741, 'n_words': 295}