-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add reactivity to useDefaults & AConfig (#184)
Co-authored-by: jd-solanki <[email protected]>
- Loading branch information
1 parent
a92f222
commit 7ae732f
Showing
7 changed files
with
143 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import type { InjectionKey } from "vue" | ||
import type { InjectionKey, MaybeRef } from "vue" | ||
import type { PluginOptions } from '@/plugin' | ||
|
||
export const ANU_CONFIG = Symbol('ANU_CONFIG') as InjectionKey<PluginOptions> | ||
export const ANU_DEFAULTS = Symbol("ANU_DEFAULTS") as InjectionKey<PluginOptions["propsDefaults"]> | ||
export const ANU_PROPS_DEFAULTS = Symbol("ANU_PROPS_DEFAULTS") as InjectionKey<MaybeRef<PluginOptions["propsDefaults"]>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { mount } from '@vue/test-utils' | ||
import { afterEach, describe, expect, it } from 'vitest' | ||
import { nextTick, ref } from 'vue' | ||
import { AAlert, ABtn, ACard, AConfig } from '../src' | ||
|
||
describe('AConfig', () => { | ||
let wrapper: ReturnType<typeof mount<AConfig>> | ||
|
||
function getSelectorStyle(selector: string) { | ||
return wrapper.find(selector).attributes('style') | ||
} | ||
|
||
afterEach(() => { | ||
wrapper.unmount() | ||
}) | ||
|
||
it('should provide config to matched component', () => { | ||
const props = ref({ | ||
ABtn: { color: 'success' }, | ||
AAlert: { color: 'info' }, | ||
}) | ||
wrapper = mount(() => | ||
<AConfig props={props.value}> | ||
<AAlert>Alert</AAlert> | ||
<ABtn>Btn</ABtn> | ||
</AConfig>, | ||
) | ||
expect(getSelectorStyle('.a-btn')).toContain('--a-success') | ||
expect(getSelectorStyle('.a-alert')).toContain('--a-info') | ||
}) | ||
|
||
it('config can be reactive', async () => { | ||
const props = ref({ | ||
ABtn: { color: 'success' }, | ||
}) | ||
wrapper = mount(() => | ||
<AConfig props={props.value}> | ||
<ABtn>Btn</ABtn> | ||
</AConfig>, | ||
) | ||
expect(getSelectorStyle('.a-btn')).toContain('--a-success') | ||
props.value.ABtn.color = 'info' | ||
await nextTick() | ||
expect(getSelectorStyle('.a-btn')).toContain('--a-info') | ||
}) | ||
|
||
it('should apply nested config correctly', () => { | ||
const props = ref({ | ||
ABtn: { color: 'success' }, | ||
}) | ||
const nestedProps = ref({ | ||
ABtn: { color: 'info' }, | ||
}) | ||
wrapper = mount(() => | ||
<AConfig props={props.value}> | ||
<ACard> | ||
<AConfig props={nestedProps.value}> | ||
<ABtn>Btn</ABtn> | ||
</AConfig> | ||
</ACard> | ||
</AConfig>, | ||
) | ||
expect(getSelectorStyle('.a-btn')).toContain('--a-info') | ||
}) | ||
}) |