Skip to content

Commit c77a19a

Browse files
sharkykhp0psicles
authored andcommitted
Fix QualityChooser (#6918)
* Remove waitFor from QualityChooser Use `v-if`s instead * [bundle] * Convert QualityChooser test to async test vuejs/vue-test-utils#1137
1 parent 8d6ed43 commit c77a19a

19 files changed

+126
-31
lines changed

Diff for: themes-default/slim/src/components/helpers/quality-chooser.vue

+5-9
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
<div v-else>Please select at least one allowed quality.</div>
8181
</div>
8282

83-
<div v-if="showSlug && (allowedQualities.length + preferredQualities.length) >= 1">
83+
<div v-if="backloggedEpisodes">
8484
<h5 class="{ 'red-text': !backloggedEpisodes.status }" v-html="backloggedEpisodes.html" />
8585
</div>
8686

@@ -106,7 +106,6 @@
106106
import { mapGetters, mapState } from 'vuex';
107107
108108
import { api } from '../../api';
109-
import { waitFor } from '../../utils/core';
110109
import AppLink from './app-link';
111110
112111
export default {
@@ -194,12 +193,12 @@ export default {
194193
195194
// Skip if no showSlug, as that means we're on a addShow page
196195
if (!showSlug) {
197-
return {};
196+
return null;
198197
}
199198
200199
// Skip if no qualities are selected
201-
if (allowedQualities.length === 0 && preferredQualities.length === 0) {
202-
return {};
200+
if ((allowedQualities.length + preferredQualities.length) === 0) {
201+
return null;
203202
}
204203
205204
const url = `series/${showSlug}/legacy/backlogged`;
@@ -254,10 +253,7 @@ export default {
254253
isQualityPreset(quality) {
255254
return this.getQualityPreset({ value: quality }) !== undefined;
256255
},
257-
async setInitialPreset(preset) {
258-
// Wait for the store to get populated.
259-
await waitFor(() => this.qualityValues.length > 0, 100, 3000);
260-
256+
setInitialPreset(preset) {
261257
const { isQualityPreset, keep } = this;
262258
const newPreset = keep === 'keep' ? 'keep' : (isQualityPreset(preset) ? preset : 0);
263259
this.selectedQualityPreset = [newPreset, preset];

Diff for: themes-default/slim/test/specs/quality-chooser.spec.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ describe('QualityChooser.test.js', () => {
2323
store.replaceState(state);
2424
});
2525

26-
it('renders', () => {
26+
it('renders', async () => {
2727
const { state } = fixtures;
2828
const wrapper = shallowMount(QualityChooser, {
2929
localVue,
3030
store,
31+
sync: false,
3132
propsData: {
3233
overallQuality: undefined,
3334
keep: 'show'
@@ -45,18 +46,21 @@ describe('QualityChooser.test.js', () => {
4546

4647
// If `overallQuality` is provided, `initialQuality` should be that value
4748
wrapper.setProps({ overallQuality: 1000 }); // HD preset
49+
await wrapper.vm.$nextTick();
4850
expect(wrapper.vm.initialQuality).toBe(1000);
4951
expect(wrapper.find('#customQualityWrapper').isVisible()).toBe(false);
5052

5153
// Choose a preset
5254
wrapper.setData({ selectedQualityPreset: 6 }); // SD preset
55+
await wrapper.vm.$nextTick();
5356
// Custom quality elements should be hidden
5457
expect(wrapper.find('#customQualityWrapper').isVisible()).toBe(false);
5558
expect(wrapper.vm.allowedQualities).toEqual([2, 4]);
5659
expect(wrapper.vm.preferredQualities).toEqual([]);
5760

5861
// Choose custom
5962
wrapper.setData({ selectedQualityPreset: 0 });
63+
await wrapper.vm.$nextTick();
6064
// Custom quality elements should now be visible
6165
expect(wrapper.find('#customQualityWrapper').isVisible()).toBe(true);
6266
expect(wrapper.vm.allowedQualities).toEqual([2, 4]);
@@ -67,18 +71,21 @@ describe('QualityChooser.test.js', () => {
6771
selectedQualityPreset: 0,
6872
allowedQualities: []
6973
});
74+
await wrapper.vm.$nextTick();
7075
expect(wrapper.find('#customQualityWrapper').isVisible()).toBe(true);
7176
expect(wrapper.findAll('#customQualityWrapper select').at(1).is(':disabled')).toBe(true);
7277

7378
// Choose keep
7479
wrapper.setData({ selectedQualityPreset: 'keep' });
80+
await wrapper.vm.$nextTick();
7581
expect(wrapper.find('#customQualityWrapper').isVisible()).toBe(false);
7682
// Underlying value should be equal to `initialQuality`
7783
expect(wrapper.vm.allowedQualities).toEqual([8, 32, 64, 128, 256, 512]); // HD preset
7884
expect(wrapper.vm.preferredQualities).toEqual([]);
7985

8086
// And to custom again
8187
wrapper.setData({ selectedQualityPreset: 0 });
88+
await wrapper.vm.$nextTick();
8289
expect(wrapper.find('#customQualityWrapper').isVisible()).toBe(true);
8390
// Underlying value should be equal to `initialQuality`
8491
expect(wrapper.vm.allowedQualities).toEqual([8, 32, 64, 128, 256, 512]); // HD preset
@@ -88,6 +95,7 @@ describe('QualityChooser.test.js', () => {
8895
wrapper.setData({
8996
allowedQualities: [2, 4] // SD preset
9097
});
98+
await wrapper.vm.$nextTick();
9199
expect(wrapper.find('#customQualityWrapper').isVisible()).toBe(true);
92100
expect(wrapper.vm.selectedQualityPreset).toEqual(0);
93101

@@ -97,6 +105,7 @@ describe('QualityChooser.test.js', () => {
97105
preferredQualities: [32]
98106
});
99107
wrapper.setData({ allowedQualities: [] });
108+
await wrapper.vm.$nextTick();
100109
expect(wrapper.findAll('#customQualityWrapper select').at(1).is(':disabled')).toBe(true);
101110
expect(wrapper.vm.allowedQualities).toEqual([]);
102111
expect(wrapper.vm.preferredQualities).toEqual([]);

Diff for: themes-default/slim/views/addShows_addExistingShow.mako

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
<%block name="scripts">
1212
<script type="text/javascript" src="js/add-show-options.js?${sbPID}"></script>
1313
<script>
14+
const { mapState } = window.Vuex;
15+
1416
window.app = {};
1517
window.app = new Vue({
1618
store,
@@ -38,7 +40,10 @@ window.app = new Vue({
3840
$.updateBlackWhiteList(undefined);
3941
}, 500);
4042
},
41-
computed: {
43+
// TODO: Replace with Object spread (`...mapState`)
44+
computed: Object.assign(mapState([
45+
'config' // Used by `inc_addShowOptions.mako`
46+
]), {
4247
selectedRootDirs() {
4348
return this.rootDirs.filter(rd => rd.selected);
4449
},
@@ -81,7 +86,7 @@ window.app = new Vue({
8186
});
8287
}
8388
}
84-
},
89+
}),
8590
methods: {
8691
/**
8792
* Transform root dirs paths array, and select all the paths.

Diff for: themes-default/slim/views/addShows_recommended.mako

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<script type="text/javascript" src="js/blackwhite.js?${sbPID}"></script>
55
% endif
66
<script>
7+
const { mapState } = window.Vuex;
8+
79
window.app = {};
810
window.app = new Vue({
911
store,
@@ -13,7 +15,13 @@ window.app = new Vue({
1315
return {
1416
rootDirs: []
1517
};
16-
}
18+
},
19+
// TODO: Replace with Object spread (`...mapState`)
20+
computed: Object.assign(mapState([
21+
'config' // Used by `inc_addShowOptions.mako`
22+
]), {
23+
24+
})
1725
});
1826
</script>
1927
</%block>

Diff for: themes-default/slim/views/addShows_trendingShows.mako

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<script type="text/javascript" src="js/blackwhite.js?${sbPID}"></script>
88
% endif
99
<script>
10+
const { mapState } = window.Vuex;
11+
1012
window.app = {};
1113
window.app = new Vue({
1214
store,
@@ -16,7 +18,13 @@ window.app = new Vue({
1618
return {
1719
rootDirs: []
1820
};
19-
}
21+
},
22+
// TODO: Replace with Object spread (`...mapState`)
23+
computed: Object.assign(mapState([
24+
'config' // Used by `inc_addShowOptions.mako`
25+
]), {
26+
27+
})
2028
});
2129
</script>
2230
</%block>

Diff for: themes-default/slim/views/inc_addShowOptions.mako

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<label for="customQuality" class="clearfix">
99
<span class="component-title">Quality</span>
1010
<span class="component-desc">
11-
<quality-chooser></quality-chooser>
11+
<quality-chooser v-if="config.showDefaults.quality !== null"></quality-chooser>
1212
</span>
1313
</label>
1414
</div>

Diff for: themes-default/slim/views/manage_massEdit.mako

+9
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,19 @@
88
%>
99
<%block name="scripts">
1010
<script>
11+
const { mapState } = window.Vuex;
12+
1113
window.app = {};
1214
window.app = new Vue({
1315
store,
1416
router,
1517
el: '#vue-wrap',
18+
// TODO: Replace with Object spread (`...mapState`)
19+
computed: Object.assign(mapState([
20+
'config'
21+
]), {
22+
23+
}),
1624
beforeMount() {
1725
$('#config-components').tabs();
1826
},
@@ -131,6 +139,7 @@ window.app = new Vue({
131139
qc_overall_quality = int(quality_value)
132140
%>
133141
<quality-chooser
142+
v-if="config.showDefaults.quality !== null"
134143
keep="${qc_keep}"
135144
:overall-quality="${qc_overall_quality}"
136145
></quality-chooser>

Diff for: themes/dark/assets/js/medusa-runtime.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: themes/dark/templates/addShows_addExistingShow.mako

+7-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: themes/dark/templates/addShows_recommended.mako

+9-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: themes/dark/templates/addShows_trendingShows.mako

+9-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: themes/dark/templates/inc_addShowOptions.mako

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: themes/dark/templates/manage_massEdit.mako

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)