|
1 | | -import { fn } from '@storybook/test' |
| 1 | +import { expect, fn, within } from '@storybook/test' |
2 | 2 |
|
3 | 3 | import DsfrToggleSwitch from './DsfrToggleSwitch.vue' |
4 | 4 |
|
@@ -43,6 +43,18 @@ export default { |
43 | 43 | description: |
44 | 44 | 'Appelé à chaque changement de la valeur `checked`.\n\n*N.B. : Ne fait pas partie du composant.*', |
45 | 45 | }, |
| 46 | + activeText: { |
| 47 | + control: 'text', |
| 48 | + description: 'Texte à afficher sous l\'interrupteur lorsqu\'il est activé', |
| 49 | + }, |
| 50 | + inactiveText: { |
| 51 | + control: 'text', |
| 52 | + description: 'Texte à afficher sous l\'interrupteur lorsqu\'il est désactivé', |
| 53 | + }, |
| 54 | + noText: { |
| 55 | + control: 'boolean', |
| 56 | + description: 'Désactive l\'affichage de activeText et inactiveText', |
| 57 | + }, |
46 | 58 | 'update:modelValue': { |
47 | 59 | description: |
48 | 60 | 'Evènement de mise à jour de la valeur contenue dans modelValue', |
@@ -137,3 +149,79 @@ InterrupteurAvecBordure.args = { |
137 | 149 | modelValue: true, |
138 | 150 | borderBottom: true, |
139 | 151 | } |
| 152 | + |
| 153 | +export const InterrupteurAvecTextePersonnalisé = (args) => ({ |
| 154 | + components: { DsfrToggleSwitch }, |
| 155 | + data () { |
| 156 | + return args |
| 157 | + }, |
| 158 | + template: ` |
| 159 | + <DsfrToggleSwitch |
| 160 | + v-model="modelValue" |
| 161 | + :label="label" |
| 162 | + :hint="hint" |
| 163 | + :input-id="inputId" |
| 164 | + :active-text="activeText" |
| 165 | + :inactive-text="inactiveText" |
| 166 | + /> |
| 167 | + `, |
| 168 | + watch: { |
| 169 | + modelValue (newVal) { |
| 170 | + this.onChange(newVal) |
| 171 | + }, |
| 172 | + }, |
| 173 | +}) |
| 174 | +InterrupteurAvecTextePersonnalisé.args = { |
| 175 | + label: 'Interrupteur 1', |
| 176 | + hint: 'Indice', |
| 177 | + inputId: 'toggle-4', |
| 178 | + modelValue: true, |
| 179 | + activeText: 'Autorisé', |
| 180 | + inactiveText: 'Interdit', |
| 181 | +} |
| 182 | + |
| 183 | +export const InterrupteurSansTexte = (args) => ({ |
| 184 | + components: { DsfrToggleSwitch }, |
| 185 | + data () { |
| 186 | + return args |
| 187 | + }, |
| 188 | + template: ` |
| 189 | + <DsfrToggleSwitch |
| 190 | + v-model="modelValue" |
| 191 | + :label="label" |
| 192 | + :hint="hint" |
| 193 | + :input-id="inputId" |
| 194 | + :no-text="noText" |
| 195 | + /> |
| 196 | + `, |
| 197 | + watch: { |
| 198 | + modelValue (newVal) { |
| 199 | + this.onChange(newVal) |
| 200 | + }, |
| 201 | + }, |
| 202 | +}) |
| 203 | +InterrupteurSansTexte.args = { |
| 204 | + label: 'Interrupteur 1', |
| 205 | + hint: 'Indice', |
| 206 | + inputId: 'toggle-5', |
| 207 | + modelValue: true, |
| 208 | + noText: true, |
| 209 | +} |
| 210 | + |
| 211 | +InterrupteurAvecTextePersonnalisé.play = async ({ canvasElement }) => { |
| 212 | + const canvas = within(canvasElement) |
| 213 | + const toggleSwitch = canvas.getByLabelText('Interrupteur 1') as HTMLInputElement |
| 214 | + expect(toggleSwitch.checked).toBe(true) |
| 215 | + toggleSwitch.click() |
| 216 | + expect(toggleSwitch.checked).toBe(false) |
| 217 | + toggleSwitch.click() |
| 218 | + |
| 219 | + const toggleSwitchLabel = canvas.getByText('Interrupteur 1') as HTMLLabelElement |
| 220 | + toggleSwitchLabel.click() |
| 221 | + expect(toggleSwitch.checked).toBe(false) |
| 222 | + toggleSwitchLabel.click() |
| 223 | + expect(toggleSwitch.checked).toBe(true) |
| 224 | + |
| 225 | + const hint = canvas.getByText('Indice') as HTMLParagraphElement |
| 226 | + expect(hint).toBeVisible() |
| 227 | +} |
0 commit comments