-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix vue tests, add default scope lease extensions
- Loading branch information
1 parent
c56f1d4
commit 49dd7e6
Showing
9 changed files
with
746 additions
and
162 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { defineComponent, h, type Component } from "vue"; | ||
import type { AnyScopeTuple } from "../../vanilla/internal/internal-types"; | ||
import { provideScope } from "../provideScopes"; | ||
|
||
export const ScopeProvider = defineComponent({ | ||
props: { | ||
tuple: null, | ||
}, | ||
setup(props) { | ||
provideScope(props.tuple); | ||
}, | ||
template: `<div><slot/></div>`, | ||
}); | ||
|
||
export const createProvider = (tuple: AnyScopeTuple): Component => { | ||
return { | ||
props: {}, | ||
render() { | ||
// <ScopeProvider><slot /></ScopeProvider> | ||
return h(ScopeProvider, { tuple }, () => this.$slots.default()); | ||
}, | ||
}; | ||
}; | ||
|
||
export default ScopeProvider; |
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 |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import { resetDefaultInjector } from "../vanilla/getDefaultInjector"; | ||
import { CountMolecule, lifecycle, userScope } from "./testing/CountMolecule"; | ||
import { createProvider } from "./testing/ScopeProvider"; | ||
import { wrap } from "./testing/test-utils"; | ||
import { useMolecule } from "./useMolecule"; | ||
|
||
beforeEach(() => { | ||
/** | ||
* Prevents default scopes getting cached for too long | ||
*/ | ||
resetDefaultInjector(); | ||
}); | ||
|
||
describe.each([ | ||
{ userId: "[email protected]", case: "Regular email" }, | ||
{ userId: "[email protected]", case: "Different email" }, | ||
{ userId: "", case: "Empty string" }, | ||
{ userId: " ", case: "White space" }, | ||
{ userId: userScope.defaultValue, case: "Default value" }, | ||
])("Two branches, one molecule value. $case", ({ userId }) => { | ||
const Wrapper = createProvider([userScope, userId]); | ||
test("Same component", () => { | ||
const counter = wrap(() => useMolecule(CountMolecule), { Wrapper }); | ||
|
||
lifecycle.expectUncalled(); | ||
const [result1, rendered1] = counter.render(); | ||
|
||
expect(result1.value?.username).toBe(userId); | ||
lifecycle.expectActivelyMounted(); | ||
|
||
const [result2, rendered2] = counter.render(); | ||
expect(result2.value?.username).toBe(userId); | ||
|
||
rendered1.unmount(); | ||
|
||
lifecycle.expectActivelyMounted(); | ||
rendered2.unmount(); | ||
|
||
lifecycle.expectToMatchCalls([userId]); | ||
}); | ||
test("Different components", () => { | ||
const counter1 = wrap(() => useMolecule(CountMolecule), { | ||
Wrapper: createProvider([userScope, userId]), | ||
}); | ||
const counter2 = wrap(() => useMolecule(CountMolecule), { | ||
Wrapper: createProvider([userScope, userId]), | ||
}); | ||
|
||
lifecycle.expectUncalled(); | ||
const [result1, rendered1] = counter1.render(); | ||
|
||
expect(result1.value?.username).toBe(userId); | ||
lifecycle.expectActivelyMounted(); | ||
|
||
const [result2, rendered2] = counter2.render(); | ||
expect(result2.value?.username).toBe(userId); | ||
|
||
rendered1.unmount(); | ||
|
||
lifecycle.expectActivelyMounted(); | ||
rendered2.unmount(); | ||
|
||
lifecycle.expectToMatchCalls([userId]); | ||
}); | ||
}); | ||
|
||
test.each([ | ||
{ | ||
userId1: "[email protected]", | ||
userId2: "[email protected]", | ||
case: "Different emails", | ||
}, | ||
{ userId1: "a", userId2: "A", case: "Case sensitive" }, | ||
{ userId1: "a", userId2: "", case: "Empty strings" }, | ||
{ userId1: " ", userId2: " ", case: "White space" }, | ||
{ | ||
userId1: userScope.defaultValue, | ||
userId2: "two", | ||
case: "Default value is first", | ||
}, | ||
{ | ||
userId1: "one", | ||
userId2: userScope.defaultValue, | ||
case: "Default value is second", | ||
}, | ||
])( | ||
"Two molecule values for different scopes. $case", | ||
({ userId1, userId2 }) => { | ||
const counter1 = wrap( | ||
() => { | ||
return useMolecule(CountMolecule); | ||
}, | ||
{ | ||
Wrapper: createProvider([userScope, userId1]), | ||
}, | ||
); | ||
|
||
const counter2 = wrap( | ||
() => { | ||
return useMolecule(CountMolecule); | ||
}, | ||
{ | ||
Wrapper: createProvider([userScope, userId2]), | ||
}, | ||
); | ||
|
||
lifecycle.expectUncalled(); | ||
const [result1, rendered1] = counter1.render(); | ||
|
||
expect(result1.value?.username).toBe(userId1); | ||
lifecycle.expectActivelyMounted(); | ||
|
||
const [result2, rendered2] = counter2.render(); | ||
expect(result2.value?.username).toBe(userId2); | ||
|
||
expect(lifecycle.unmounts).not.toHaveBeenCalled(); | ||
rendered1.unmount(); | ||
rendered2.unmount(); | ||
|
||
lifecycle.expectToMatchCalls([userId1], [userId2]); | ||
}, | ||
); | ||
|
||
test("Default scope cleanup", () => { | ||
const counter1 = wrap(() => useMolecule(CountMolecule)); | ||
const counter2 = wrap(() => useMolecule(CountMolecule)); | ||
|
||
lifecycle.expectUncalled(); | ||
const [result1, rendered1] = counter1.render(); | ||
|
||
expect(result1.value?.username).toBe(userScope.defaultValue); | ||
lifecycle.expectActivelyMounted(); | ||
|
||
const [result2, rendered2] = counter2.render(); | ||
expect(result2.value?.username).toBe(userScope.defaultValue); | ||
|
||
expect(lifecycle.unmounts).not.toHaveBeenCalled(); | ||
rendered1.unmount(); | ||
rendered2.unmount(); | ||
|
||
lifecycle.expectToMatchCalls([userScope.defaultValue]); | ||
}); |
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