-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from FusionAuth/67-vue-add-sdkcontext-and-sdkc…
…onfig Bring Vue SDK to parity with React
- Loading branch information
Showing
29 changed files
with
502 additions
and
185 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './mockLoggedIn'; | ||
export * from './mockWindowLocation'; |
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...testing-tools/mocks/mockWindowLocation.ts → .../core/src/testUtils/mockWindowLocation.ts
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
36 changes: 36 additions & 0 deletions
36
packages/sdk-vue/src/components/FusionAuthLogoutButton/FusionAuthLogoutButton.test.ts
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,36 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { shallowMount } from '@vue/test-utils'; | ||
|
||
import FusionAuthLogoutButton from './FusionAuthLogoutButton.vue'; | ||
import { getMockFusionAuth } from '../../utilsForTests'; | ||
|
||
const label = 'logout button label'; | ||
const setup = () => { | ||
const { key, mockedValues } = getMockFusionAuth({}); | ||
return [ | ||
shallowMount(FusionAuthLogoutButton, { | ||
global: { | ||
provide: { | ||
[key]: mockedValues, | ||
}, | ||
}, | ||
slots: { | ||
default: label, | ||
}, | ||
}), | ||
mockedValues, | ||
] as const; | ||
}; | ||
|
||
describe('FusionAuthLogoutButton', () => { | ||
it('renders with label', () => { | ||
const [Button] = setup(); | ||
expect(Button.text()).toBe(label); | ||
}); | ||
|
||
it('can be clicked to run logout()', () => { | ||
const [Button, { logout }] = setup(); | ||
Button.trigger('click'); | ||
expect(logout).toHaveBeenCalledOnce(); | ||
}); | ||
}); |
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 was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
packages/sdk-vue/src/components/RequireAnonymous/RequireAnonymous.test.ts
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,39 @@ | ||
import { ref } from 'vue'; | ||
import { describe, expect, it } from 'vitest'; | ||
import { mount } from '@vue/test-utils'; | ||
|
||
import RequireAnonymous from './RequireAnonymous.vue'; | ||
import { getMockFusionAuth } from '../../utilsForTests'; | ||
import { FusionAuth } from '../../types'; | ||
|
||
function setup(params: { | ||
fusionAuthMock: Partial<FusionAuth>; | ||
content: string; | ||
}) { | ||
const { key, mockedValues } = getMockFusionAuth(params.fusionAuthMock); | ||
return mount(RequireAnonymous, { | ||
global: { provide: { [key]: mockedValues } }, | ||
slots: { default: params.content }, | ||
}); | ||
} | ||
|
||
describe('RequireAnonymous', () => { | ||
it('Renders the slot if not logged in', () => { | ||
const content = 'There is content here'; | ||
const wrapper = setup({ | ||
fusionAuthMock: { isLoggedIn: ref(false) }, | ||
content, | ||
}); | ||
|
||
expect(wrapper.text()).toBe(content); | ||
}); | ||
|
||
it('Does not render the slot if logged in', () => { | ||
const wrapper = setup({ | ||
fusionAuthMock: { isLoggedIn: ref(true) }, | ||
content: 'For admins only', | ||
}); | ||
|
||
expect(wrapper.text()).toBe(''); | ||
}); | ||
}); |
11 changes: 11 additions & 0 deletions
11
packages/sdk-vue/src/components/RequireAnonymous/RequireAnonymous.vue
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,11 @@ | ||
<template> | ||
<template v-if="!isLoggedIn"> | ||
<slot></slot> | ||
</template> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { useFusionAuth } from '#/composables/useFusionAuth.ts'; | ||
const { isLoggedIn } = useFusionAuth(); | ||
</script> |
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
packages/sdk-vue/src/components/RequireAuth/RequireAuth.test.ts
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,52 @@ | ||
import { ref } from 'vue'; | ||
import { describe, expect, it } from 'vitest'; | ||
import { mount } from '@vue/test-utils'; | ||
|
||
import RequireAuth from './RequireAuth.vue'; | ||
import { getMockFusionAuth } from '../../utilsForTests'; | ||
import { FusionAuth } from '../../types'; | ||
|
||
function setup(params: { | ||
fusionAuthMock: Partial<FusionAuth>; | ||
content: string; | ||
withRole: string[]; | ||
}) { | ||
const { key, mockedValues } = getMockFusionAuth(params.fusionAuthMock); | ||
|
||
return mount(RequireAuth, { | ||
global: { provide: { [key]: mockedValues } }, | ||
slots: { default: params.content }, | ||
props: { | ||
withRole: params.withRole, | ||
}, | ||
}); | ||
} | ||
|
||
describe('RequireAuth', () => { | ||
it('Renders the slot if the user is logged in with the specified role', () => { | ||
const content = 'Protected Content'; | ||
const wrapper = setup({ | ||
fusionAuthMock: { | ||
isLoggedIn: ref(true), | ||
userInfo: ref({ roles: ['ADMIN'] }), | ||
}, | ||
content, | ||
withRole: ['USER', 'ADMIN'], | ||
}); | ||
|
||
expect(wrapper.text()).toBe(content); | ||
}); | ||
|
||
it('Does not render the slot if the user is not authorized', () => { | ||
const wrapper = setup({ | ||
fusionAuthMock: { | ||
isLoggedIn: ref(true), | ||
userInfo: ref({ roles: ['USER'] }), | ||
}, | ||
content: 'For admins only', | ||
withRole: ['ADMIN', 'SUPER-ADMIN'], | ||
}); | ||
|
||
expect(wrapper.text()).toBe(''); | ||
}); | ||
}); |
Oops, something went wrong.