@eturnity/eturnity_reusable_components 7.45.5 → 7.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,40 +1,67 @@
|
|
|
1
|
+
import { useArgs } from '@storybook/preview-api'
|
|
2
|
+
import { action } from '@storybook/addon-actions'
|
|
3
|
+
import defaultSearchInputProps from './defaultProps'
|
|
1
4
|
import SearchInput from './index.vue'
|
|
2
5
|
|
|
3
6
|
export default {
|
|
4
7
|
title: 'SearchInput',
|
|
5
8
|
component: SearchInput,
|
|
6
|
-
|
|
9
|
+
tags: ['autodocs'],
|
|
7
10
|
}
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
12
|
+
// To use:
|
|
13
|
+
|
|
14
|
+
const defaultProps = defaultSearchInputProps
|
|
15
|
+
|
|
16
|
+
const Template = (args) => {
|
|
17
|
+
const [currentArgs, updateArgs] = useArgs()
|
|
18
|
+
|
|
19
|
+
const handleInputChange = ($event) => {
|
|
20
|
+
action('on-change')($event)
|
|
21
|
+
updateArgs({ value: $event })
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
components: { SearchInput },
|
|
26
|
+
setup() {
|
|
27
|
+
return { args: currentArgs, handleInputChange }
|
|
28
|
+
},
|
|
29
|
+
template: `
|
|
30
|
+
<SearchInput
|
|
31
|
+
v-bind="args"
|
|
32
|
+
@on-change="handleInputChange"
|
|
33
|
+
/>
|
|
34
|
+
`,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
25
37
|
|
|
26
38
|
export const Default = Template.bind({})
|
|
27
39
|
Default.args = {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
40
|
+
...defaultProps,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const Placeholder = Template.bind({})
|
|
44
|
+
Placeholder.args = {
|
|
45
|
+
...defaultProps,
|
|
46
|
+
placeholder: 'Search... ',
|
|
32
47
|
}
|
|
33
48
|
|
|
34
49
|
export const Disabled = Template.bind({})
|
|
35
50
|
Disabled.args = {
|
|
36
|
-
|
|
51
|
+
...defaultProps,
|
|
37
52
|
disabled: true,
|
|
38
|
-
value: '',
|
|
39
|
-
inputWidth: '250px',
|
|
40
53
|
}
|
|
54
|
+
|
|
55
|
+
export const StyledIcon = Template.bind({})
|
|
56
|
+
StyledIcon.args = {
|
|
57
|
+
...defaultProps,
|
|
58
|
+
'icon-color': 'red',
|
|
59
|
+
'icon-position': 'left',
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const Sizes = Template.bind({})
|
|
63
|
+
Sizes.args = {
|
|
64
|
+
...defaultProps,
|
|
65
|
+
'input-width': '250px',
|
|
66
|
+
'is-filter': true,
|
|
67
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const defaultSearchInputProps = {
|
|
2
|
+
dataId: 'search_input_id',
|
|
3
|
+
disabled: false, //
|
|
4
|
+
hasFocus: false, //
|
|
5
|
+
iconColor: 'black',
|
|
6
|
+
iconPosition: 'right',
|
|
7
|
+
inputWidth: null, //
|
|
8
|
+
isFilter: false,
|
|
9
|
+
placeholder: '',
|
|
10
|
+
value: '',
|
|
11
|
+
}
|
|
12
|
+
export default defaultSearchInputProps
|
|
@@ -22,15 +22,16 @@
|
|
|
22
22
|
// import SearchInput from "@eturnity/eturnity_reusable_components/src/components/inputs/searchInput"
|
|
23
23
|
// To use:
|
|
24
24
|
// <search-input
|
|
25
|
-
//
|
|
26
|
-
// :value="companyName"
|
|
25
|
+
// data-id='search_input_id'
|
|
27
26
|
// :disabled="true"
|
|
28
|
-
//
|
|
27
|
+
// :has-focus="true"
|
|
28
|
+
// icon-color="grey2" // colors only from theme
|
|
29
|
+
// icon-position="left"
|
|
30
|
+
// input-width="250px"
|
|
31
|
+
// :is-filter="true" // to set the height at 30px
|
|
32
|
+
// placeholder="Search by company name"
|
|
33
|
+
// :value="companyName"
|
|
29
34
|
// @on-change="function($event)"
|
|
30
|
-
// :isFilter="true" // to set the height at 30px
|
|
31
|
-
// data-id="test-data-id"
|
|
32
|
-
// iconPosition="left"
|
|
33
|
-
// iconColor="grey2"
|
|
34
35
|
// />
|
|
35
36
|
import styled from 'vue3-styled-components'
|
|
36
37
|
import SearchIconSvg from '../../../assets/icons/search_icon_black.svg'
|
|
@@ -94,31 +95,38 @@
|
|
|
94
95
|
},
|
|
95
96
|
props: {
|
|
96
97
|
value: {
|
|
98
|
+
type: [String, Number],
|
|
97
99
|
required: true,
|
|
98
100
|
},
|
|
99
101
|
disabled: {
|
|
100
102
|
required: false,
|
|
101
103
|
default: false,
|
|
104
|
+
type: Boolean,
|
|
102
105
|
},
|
|
103
106
|
placeholder: {
|
|
104
107
|
required: false,
|
|
105
108
|
default: '',
|
|
109
|
+
type: String,
|
|
106
110
|
},
|
|
107
111
|
inputWidth: {
|
|
108
112
|
required: false,
|
|
109
113
|
default: null,
|
|
114
|
+
type: String,
|
|
110
115
|
},
|
|
111
116
|
isFilter: {
|
|
112
117
|
required: false,
|
|
113
118
|
default: false,
|
|
119
|
+
type: Boolean,
|
|
114
120
|
},
|
|
115
121
|
hasFocus: {
|
|
116
122
|
required: false,
|
|
117
123
|
default: false,
|
|
124
|
+
type: Boolean,
|
|
118
125
|
},
|
|
119
126
|
dataId: {
|
|
120
127
|
required: false,
|
|
121
128
|
default: '',
|
|
129
|
+
type: [String, Number],
|
|
122
130
|
},
|
|
123
131
|
iconPosition: {
|
|
124
132
|
type: String,
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { mount } from '@vue/test-utils'
|
|
2
|
+
import SearchInput from '@/components/inputs/searchInput'
|
|
3
|
+
import defaultSearchInputProps from './defaultProps'
|
|
4
|
+
import theme from '@/assets/theme'
|
|
5
|
+
|
|
6
|
+
describe('SearchInput.vue', () => {
|
|
7
|
+
let searchInput
|
|
8
|
+
let searchInputWrapper
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
searchInput = mount(SearchInput, {
|
|
12
|
+
props: defaultSearchInputProps,
|
|
13
|
+
global: {
|
|
14
|
+
provide: {
|
|
15
|
+
theme,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const defaultDataId = searchInput.props('dataId')
|
|
21
|
+
searchInputWrapper = searchInput.find(`[data-id="${defaultDataId}"]`)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('Search input is rendered and displays the correct placeholder', async () => {
|
|
25
|
+
// Check that Search input has been rendered
|
|
26
|
+
expect(searchInputWrapper.exists()).toBe(true)
|
|
27
|
+
|
|
28
|
+
// Set the placeholder
|
|
29
|
+
const placeholderText = 'Search by company name'
|
|
30
|
+
await searchInput.setProps({ placeholder: placeholderText })
|
|
31
|
+
await searchInput.vm.$nextTick()
|
|
32
|
+
|
|
33
|
+
// Check that the input displays the correct placeholder
|
|
34
|
+
expect(searchInputWrapper.attributes('placeholder')).toBe(placeholderText)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('Search input emits correct payload on change', async () => {
|
|
38
|
+
// Simulate user input
|
|
39
|
+
const inputValue = 'test input'
|
|
40
|
+
await searchInputWrapper.setValue(inputValue)
|
|
41
|
+
|
|
42
|
+
// Check that the component emitted the 'on-change' event with correct payload
|
|
43
|
+
expect(searchInput.emitted('on-change')).toBeTruthy()
|
|
44
|
+
expect(searchInput.emitted('on-change')[0]).toEqual([inputValue])
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('test disabled prop', async () => {
|
|
48
|
+
await searchInput.setProps({ disabled: true })
|
|
49
|
+
await searchInput.vm.$nextTick()
|
|
50
|
+
|
|
51
|
+
expect(searchInputWrapper.attributes()).toHaveProperty('disabled')
|
|
52
|
+
expect(searchInputWrapper.element.disabled).toBe(true)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('test hasFocus prop', async () => {
|
|
56
|
+
// Spy on the focus method
|
|
57
|
+
const focusSpy = jest.spyOn(searchInputWrapper.element, 'focus')
|
|
58
|
+
|
|
59
|
+
await searchInput.setProps({ hasFocus: true })
|
|
60
|
+
await searchInput.vm.$nextTick()
|
|
61
|
+
|
|
62
|
+
// Check that the focus method was called
|
|
63
|
+
expect(focusSpy).toHaveBeenCalled()
|
|
64
|
+
})
|
|
65
|
+
})
|