Skip to content

Commit 0f5bc7b

Browse files
fix global settings and injection
1 parent a9fb919 commit 0f5bc7b

File tree

9 files changed

+30
-12
lines changed

9 files changed

+30
-12
lines changed

cypress.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ export default defineConfig({
2323
viewportHeight: 800,
2424
viewportWidth: 1920,
2525
},
26+
27+
numTestsKeptInMemory: 0,
2628
});

cypress/support/component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import VStepperForm from '../../src/plugin/VStepperForm.vue';
77
import * as DATA from '../templates/testData';
88
import type { Component } from 'vue';
99
import "cypress-real-events";
10+
import { pluginOptionsInjectionKey } from '../../src/plugin/utils/globals';
1011

1112

1213
// declare global {
@@ -95,7 +96,7 @@ Cypress.Commands.add('mountComponent', (options: MountComponentOptions = {}) =>
9596
validationSchema: stepperProps.validationSchema ?? undefined,
9697
...stepperProps,
9798
},
98-
global: { provide: { globalOptions: { ...globalOptions, ...globalProps }, }, },
99+
global: { provide: { [pluginOptionsInjectionKey]: { ...globalOptions, ...globalProps }, }, },
99100
}).as('wrapper');
100101
});
101102
});

cypress/templates/testData.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
object as yupObject,
66
} from 'yup';
77
import { useDeepMerge } from '../../src/plugin/composables/helpers';
8+
import { pluginOptionsInjectionKey } from '../../src/plugin/utils/globals';
89

910

1011
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Shared //
@@ -592,7 +593,7 @@ const navigationTest = {
592593
},
593594
global: {
594595
provide: {
595-
globalOptions: {
596+
[pluginOptionsInjectionKey]: {
596597
color: 'primary',
597598
validateOn: 'blur',
598599
variant: 'outlined',

src/playground/configs/playground.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ import PlaygroundApp from './PlaygroundApp.vue';
1010

1111
const app = createApp(PlaygroundApp);
1212

13+
app.use(createVStepperForm({
14+
variant: 'outlined',
15+
},
16+
));
1317
app.use(createVCodeBlock());
14-
app.use(createVStepperForm());
1518
app.use(createPinia());
1619
app.component('font-awesome-icon', FontAwesomeIcon);
1720

src/plugin/VStepperForm.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ import type {
170170
ComputedClasses,
171171
Field,
172172
Page,
173+
PluginOptions,
173174
Props,
174175
} from '@/plugin/types';
175176
import type { PrivateFormContext } from 'vee-validate';
@@ -191,14 +192,16 @@ import {
191192
useHandleNonJumpAhead,
192193
} from './composables/navigation';
193194
import componentEmits from './utils/emits';
195+
import { pluginOptionsInjectionKey } from './utils/globals';
194196
import { AllProps } from './utils/props';
195197
196198
197199
const attrs = useAttrs();
198200
const componentId = useId();
199201
const slots = useSlots();
200202
const emit = defineEmits([...componentEmits]);
201-
const injectedOptions = inject<Ref<Settings>>('globalOptions')!;
203+
const injectedOptions = inject<PluginOptions>(pluginOptionsInjectionKey)!;
204+
202205
203206
// -------------------------------------------------- Props //
204207
const props = withDefaults(defineProps<Props>(), AllProps);

src/plugin/__tests__/VStepperForm.cy.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Field, Page } from '../../plugin/types';
22
import * as DATA from '@cypress/templates/testData';
33
import VStepperForm from '../VStepperForm.vue';
4+
import { pluginOptionsInjectionKey } from '../../plugin/utils/globals';
45

56

67
const finalAnswer = DATA.finalAnswer;
@@ -65,7 +66,7 @@ const pages = [
6566

6667
const global = {
6768
provide: {
68-
globalOptions: {
69+
[pluginOptionsInjectionKey]: {
6970
color: 'primary',
7071
validateOn: 'blur',
7172
fieldColumns: {
@@ -771,7 +772,7 @@ describe('Stepper Form', () => {
771772
},
772773
global: {
773774
provide: {
774-
globalOptions: {
775+
[pluginOptionsInjectionKey]: {
775776
fieldColumns: stepperFieldColumns,
776777
summaryColumns,
777778
},

src/plugin/__tests__/slots/FieldSlots.cy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Field } from '../../../plugin/types';
22
import * as DATA from '@cypress/templates/testData';
33
import VStepperForm from '../../VStepperForm.vue';
44
import { VTextField } from 'vuetify/components';
5+
import { pluginOptionsInjectionKey } from '../../../plugin/utils/globals';
56
import {
67
string as yupString,
78
object as yupObject,
@@ -50,7 +51,7 @@ const pages = [
5051

5152
const global = {
5253
provide: {
53-
globalOptions: {
54+
[pluginOptionsInjectionKey]: {
5455
color: 'primary',
5556
validateOn: 'blur',
5657
fieldColumns: {

src/plugin/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ import type { PluginOptions } from './types';
22
import type { App, Plugin } from 'vue';
33
import './styles/main.scss';
44
import FieldLabel from './components/shared/FieldLabel.vue';
5+
import { useDeepMerge } from './composables/helpers';
6+
import { pluginOptionsInjectionKey } from './utils/globals';
57
import { AllProps } from './utils/props';
68
import VStepperForm from './VStepperForm.vue';
79

810

9-
const defaultOptions = AllProps;
10-
export const globalOptions = Symbol();
11-
12-
export function createVStepperForm(options: PluginOptions = defaultOptions): Plugin {
11+
export function createVStepperForm(options: PluginOptions = {}): Plugin {
1312
const install = (app: App) => {
14-
app.provide(globalOptions, options);
13+
const pluginOptions: PluginOptions = useDeepMerge(options, AllProps);
14+
15+
app.provide(pluginOptionsInjectionKey, pluginOptions);
1516

1617
// eslint-disable-next-line no-param-reassign
1718
app.config.idPrefix = 'vsf';

src/plugin/utils/globals.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1+
import type { InjectionKey } from 'vue';
2+
import { PluginOptions } from '../types';
3+
14
export const componentName = 'v-stepper-form';
5+
6+
export const pluginOptionsInjectionKey: InjectionKey<PluginOptions> = Symbol();

0 commit comments

Comments
 (0)