Skip to content

Commit

Permalink
Convert QualityChooser test to async test
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkykh committed Jul 5, 2019
1 parent bedb7b0 commit b0f732b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion themes-default/slim/test/specs/quality-chooser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ describe('QualityChooser.test.js', () => {
store.replaceState(state);
});

it('renders', () => {
it('renders', async () => {
const { state } = fixtures;
const wrapper = shallowMount(QualityChooser, {
localVue,
store,
sync: false,
propsData: {
overallQuality: undefined,
keep: 'show'
Expand All @@ -45,18 +46,21 @@ describe('QualityChooser.test.js', () => {

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

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

// Choose custom
wrapper.setData({ selectedQualityPreset: 0 });
await wrapper.vm.$nextTick();
// Custom quality elements should now be visible
expect(wrapper.find('#customQualityWrapper').isVisible()).toBe(true);
expect(wrapper.vm.allowedQualities).toEqual([2, 4]);
Expand All @@ -67,18 +71,21 @@ describe('QualityChooser.test.js', () => {
selectedQualityPreset: 0,
allowedQualities: []
});
await wrapper.vm.$nextTick();
expect(wrapper.find('#customQualityWrapper').isVisible()).toBe(true);
expect(wrapper.findAll('#customQualityWrapper select').at(1).is(':disabled')).toBe(true);

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

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

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

0 comments on commit b0f732b

Please sign in to comment.