refactor: make transcoding support more deterministic

This commit is contained in:
Phan An 2024-09-05 12:33:20 +02:00
parent d73028fb0c
commit a64353aedc
3 changed files with 10 additions and 16 deletions

View file

@ -1,27 +1,20 @@
import { expect, it } from 'vitest'
import { screen } from '@testing-library/vue'
import isMobile from 'ismobilejs'
import { commonStore } from '@/stores'
import UnitTestCase from '@/__tests__/UnitTestCase'
import PreferencesForm from './PreferencesForm.vue'
new class extends UnitTestCase {
protected test () {
it('has "Transcode on mobile" option for mobile users', () => {
isMobile.phone = true
it('has "Transcode on mobile" option if supported', () => {
commonStore.state.supports_transcoding = true
this.render(PreferencesForm)
screen.getByTestId('transcode_on_mobile')
})
it('does not have "Transcode on mobile" option for non-mobile users', async () => {
isMobile.phone = false
this.render(PreferencesForm)
expect(screen.queryByTestId('transcode_on_mobile')).toBeNull()
})
it('does not have "Transcode on mobile" option if transcoding is not supported', async () => {
isMobile.phone = true
it('does not have "Transcode on mobile" option if not supported', async () => {
commonStore.state.supports_transcoding = false
this.render(PreferencesForm)
expect(screen.queryByTestId('transcode_on_mobile')).toBeNull()
})
}

View file

@ -12,13 +12,13 @@
Playing a song or episode triggers continuous playback of the entire playlist, album, artist, genre, or podcast
</div>
</FormRow>
<FormRow v-if="isPhone">
<FormRow v-if="onMobile">
<div>
<CheckBox v-model="preferences.show_now_playing_notification" name="notify" />
Show Now Playing notification
</div>
</FormRow>
<FormRow v-if="!isPhone">
<FormRow v-if="!onMobile">
<div>
<CheckBox v-model="preferences.confirm_before_closing" name="confirm_closing" />
Confirm before closing Koel
@ -53,17 +53,17 @@
<script lang="ts" setup>
import isMobile from 'ismobilejs'
import { computed } from 'vue'
import { toRef } from 'vue'
import { commonStore, preferenceStore as preferences } from '@/stores'
import { useKoelPlus } from '@/composables'
import CheckBox from '@/components/ui/form/CheckBox.vue'
import FormRow from '@/components/ui/form/FormRow.vue'
const isPhone = isMobile.phone
const onMobile = isMobile.any
const { isPlus } = useKoelPlus()
const showTranscodingOption = computed(() => isPhone && commonStore.state.supports_transcoding)
const showTranscodingOption = toRef(commonStore.state, 'supports_transcoding')
</script>
<style lang="postcss" scoped>

View file

@ -14,6 +14,7 @@ export const defaultPreferences: UserPreferences = {
artists_view_mode: null,
albums_view_mode: null,
transcode_on_mobile: false,
transcode_quality: 128,
support_bar_no_bugging: false,
show_album_art_overlay: true,
lyrics_zoom_level: 1,