-
Notifications
You must be signed in to change notification settings - Fork 458
/
Copy pathSfSelect.cy.tsx
140 lines (122 loc) · 3.48 KB
/
SfSelect.cy.tsx
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
import React from 'react';
import { SfSelectSize } from '@storefront-ui/vue';
import { h } from 'vue';
import { mount, useComponent } from '../../utils/mount';
import SfSelectBaseObject from './SfSelect.PageObject';
const { vue: SfSelectVue, react: SfSelectReact } = useComponent('SfSelect');
describe('SfSelect', () => {
const options = [
{ label: 'red', value: 'red' },
{ label: 'blue', value: 'blue' },
{ label: 'yellow', value: 'yellow' },
{ label: 'green', value: 'green' },
{ label: 'gray', value: 'gray' },
{ label: 'black', value: 'black' },
{ label: 'brown', value: 'brown' },
];
let disabled: boolean;
let size: SfSelectSize;
let required: boolean;
let placeholder: string;
let invalid: boolean;
let onChangeSpy: Cypress.Agent<sinon.SinonSpy>;
let value = '';
const page = () => new SfSelectBaseObject('select');
const initializeComponent = () => {
return mount({
vue: {
component: SfSelectVue,
props: {
options: Object.values(options),
disabled,
size,
required,
placeholder,
invalid,
modelValue: value,
'onUpdate:modelValue': onChangeSpy,
},
slots: {
default: () => options.map((option) => h('option', { value: option.value }, option.label)),
},
},
react: (
<SfSelectReact
options={Object.values(options)}
disabled={disabled}
placeholder={placeholder}
required={required}
invalid={invalid}
size={size}
onChange={onChangeSpy}
>
{options.map((option) => (
<option value={option.value} key={option.value}>
{option.label}
</option>
))}
</SfSelectReact>
),
});
};
beforeEach(() => {
onChangeSpy = cy.spy();
});
afterEach(() => {
size = SfSelectSize.base;
placeholder = '--Select--';
});
it('initial state', () => {
initializeComponent();
page().makeSnapshot();
});
describe('when prop size is set to ', () => {
Object.values(SfSelectSize).forEach((componentSize) => {
describe(`${componentSize}`, () => {
it(`should render correct ${componentSize} size`, () => {
size = componentSize;
initializeComponent();
page().makeSnapshot();
});
});
});
});
describe('when an option is selected', () => {
after(() => {
value = '';
});
it('should change value/modelValue', () => {
initializeComponent();
page().isNotDisabled().hasSelectedOption('red');
cy.then(() => {
expect(onChangeSpy).calledOnceWith();
page().makeSnapshot();
});
});
});
describe('when prop disabled=true', () => {
before(() => (disabled = true));
after(() => (disabled = false));
it(`should render as disabled`, () => {
initializeComponent();
page().isDisabled().makeSnapshot();
});
});
describe('when prop required=true', () => {
before(() => (required = true));
after(() => (required = false));
it(`should render as required`, () => {
initializeComponent();
page().isRequired().makeSnapshot();
});
});
describe('when prop placeholder is filled in', () => {
before(() => {
placeholder = 'Select value';
});
it('should render with no placeholder', () => {
initializeComponent();
page().hasPlaceholder('Select value').makeSnapshot();
});
});
});