-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2dba197
commit 937f9c7
Showing
6 changed files
with
152 additions
and
105 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
38 changes: 38 additions & 0 deletions
38
src/resources/js/features/anime/rating/AnimeRating.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,38 @@ | ||
import { beforeEach, describe, expect, it } from 'vitest'; | ||
import { mount } from '@vue/test-utils'; | ||
import AnimeRating from './AnimeRating.vue'; | ||
import Rating from 'primevue/rating'; | ||
import PrimeVue from 'primevue/config'; | ||
|
||
describe('AnimeRating test (AnimeRating.vue)', () => { | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
wrapper = mount(AnimeRating, { | ||
props: { modelValue: 5 }, | ||
global: { | ||
plugins: [PrimeVue], | ||
}, | ||
}); | ||
}); | ||
|
||
it('Will display initial rating', () => { | ||
expect(wrapper.text()).toContain('5 / 10'); | ||
const ratingComponent = wrapper.findComponent(Rating); | ||
|
||
expect(ratingComponent.props('modelValue')).toBe(5); | ||
}); | ||
|
||
it('Will update rating when the modelValue prop changes', async () => { | ||
await wrapper.setProps({ modelValue: 8 }); | ||
expect(wrapper.text()).toContain('8 / 10'); | ||
}); | ||
|
||
it('Has appropriate ARIA attributes for accessibility', () => { | ||
expect(wrapper.attributes('role')).toBe('status'); | ||
expect(wrapper.attributes('aria-live')).toBe('polite'); | ||
|
||
const ratingComponent = wrapper.findComponent(Rating); | ||
expect(ratingComponent.exists()).toBeTruthy(); | ||
}); | ||
}); |
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,31 @@ | ||
<script setup lang="ts"> | ||
import Rating from 'primevue/rating'; | ||
import { computed } from 'vue'; | ||
type Props = { | ||
modelValue: number; | ||
}; | ||
const props = defineProps<Props>(); | ||
const emit = defineEmits<{ 'update:modelValue': [value: number] }>(); | ||
const rating = computed({ | ||
get: () => props.modelValue, | ||
set: (value: number) => emit('update:modelValue', value), | ||
}); | ||
</script> | ||
|
||
<template> | ||
<div class="flex gap-2" role="status" aria-live="polite"> | ||
<span id="ratingValue">{{ rating }} / 10</span> | ||
<Rating | ||
v-model="rating" | ||
readonly | ||
:stars="10" | ||
:cancel="false" | ||
aria-labelledby="ratingValue" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<style scoped></style> |
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 @@ | ||
export { default as AnimeRating } from './AnimeRating.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
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