<commit_before>// flow
/* global describe, it, expect */

import Vue from 'vue'
import vSelect from 'src/components/Select.vue'
import pointerScroll from 'src/mixins/pointerScroll.js'

//  http://vue-loader.vuejs.org/en/workflow/testing-with-mocks.html
const Mock = require('!!vue?inject!src/components/Select.vue')

Vue.component('v-select', vSelect)

/**
 * Simulate a DOM event.
 * @param target
 * @param event
 * @param process
 * @returns {Event}
 */
function trigger(target, event, process) {
	var e = document.createEvent('HTMLEvents')
	e.initEvent(event, true, true)
	if (process) process(e)
	target.dispatchEvent(e)
	return e
}

/**
 * Simulate a Mouse event.
 * @param target
 * @param event
 * @param process
 * @returns {Event}
 */
function triggerMouse(target, event, process) {
	var e = document.createEvent('MouseEvent')
	e.initEvent('event', true, true)
	if (process) process(e)
	target.dispatchEvent(e)
	return e
}

/**
 * Simulate a Focus event.
 * @param target
 * @param event
 * @param process
 * @returns {Event}
 */
function triggerFocusEvent(target, event, process) {
	var e = document.createEvent('FocusEvent')
	e.initEvent('event', true, true)
	if (process) process(e)
	target.dispatchEvent(e)
	return e
}

/**
 * Optionally set the search term, then simulate a return keypress.
 * @param vm
 * @param search
 */
function searchSubmit(vm, search = false) {
	if (search) {
		vm.$children[0].search = search
	}

	trigger(vm.$children[0].$refs.search, 'keyup', function (e) {
		e.keyCode = 13
	})
}

describe('Select.vue', () => {

	describe('Selecting values', () => {
		it('can accept an array with pre-selected values', () => {
			const vm = new Vue({
				template: '<div><v-select :options="options" :value="value"></v-select></div>',
				components: {vSelect},
				data: {
					value: 'one',
					options: ['one', 'two', 'three']
				}
			}).$mount()
			expect(vm.$children[0].mutableValue).toEqual(vm.value)
		})

		it('can accept an array of objects and pre-selected value (single)', () => {
			const vm = new Vue({
				template: '<div><v-select :options="options" :value="value"></v-select></div>',
				components: {vSelect},
				data: {
					value: {label: 'This is Foo', value: 'foo'},
					options: [{label: 'This is Foo', value: 'foo'}, {label: 'This is Bar', value: 'bar'}]<commit_msg>fixes tests from #249<commit_after>// flow
/* global describe, it, expect */

import Vue from 'vue'
import vSelect from 'src/components/Select.vue'
import pointerScroll from 'src/mixins/pointerScroll.js'

//  http://vue-loader.vuejs.org/en/workflow/testing-with-mocks.html
const Mock = require('!!vue?inject!src/components/Select.vue')

Vue.component('v-select', vSelect)

/**
 * Simulate a DOM event.
 * @param target
 * @param event
 * @param process
 * @returns {Event}
 */
function trigger(target, event, process) {
	var e = document.createEvent('HTMLEvents')
	e.initEvent(event, true, true)
	if (process) process(e)
	target.dispatchEvent(e)
	return e
}

/**
 * Simulate a Mouse event.
 * @param target
 * @param event
 * @param process
 * @returns {Event}
 */
function triggerMouse(target, event, process) {
	var e = document.createEvent('MouseEvent')
	e.initEvent('event', true, true)
	if (process) process(e)
	target.dispatchEvent(e)
	return e
}

/**
 * Simulate a Focus event.
 * @param target
 * @param event
 * @param process
 * @returns {Event}
 */
function triggerFocusEvent(target, event, process) {
	var e = document.createEvent('FocusEvent')
	e.initEvent('event', true, true)
	if (process) process(e)
	target.dispatchEvent(e)
	return e
}

/**
 * Optionally set the search term, then simulate a return keypress.
 * @param vm
 * @param search
 */
function searchSubmit(vm, search = false) {
	if (search) {
		vm.$children[0].search = search
	}

	trigger(vm.$children[0].$refs.search, 'keydown', function (e) {
		e.keyCode = 13
	})
}

describe('Select.vue', () => {

	describe('Selecting values', () => {
		it('can accept an array with pre-selected values', () => {
			const vm = new Vue({
				template: '<div><v-select :options="options" :value="value"></v-select></div>',
				components: {vSelect},
				data: {
					value: 'one',
					options: ['one', 'two', 'three']
				}
			}).$mount()
			expect(vm.$children[0].mutableValue).toEqual(vm.value)
		})

		it('can accept an array of objects and pre-selected value (single)', () => {
			const vm = new Vue({
				template: '<div><v-select :options="options" :value="value"></v-select></div>',
				components: {vSelect},
				data: {
					value: {label: 'This is Foo', value: 'foo'},
					options: [{label: 'This is Foo', value: 'foo'}, {label: 'This is Bar', value: 'bar'}]
{'fraction_non_alphanumeric': 0.1742587021916631, 'fraction_numerical': 0.002793296089385475, 'mean_word_length': 3.9732905982905984, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 27, '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': '1858057', 'n_tokens_mistral': 1672, 'n_tokens_neox': 1555, 'n_words': 414}