feat: add max_ratio_act handling (#523) @giacomocerquone

This commit is contained in:
Giacomo Cerquone 2022-10-20 11:44:26 +02:00 committed by GitHub
parent 058766f617
commit b05dcd0569
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 274 additions and 91 deletions

View file

@ -170,6 +170,26 @@
</v-col> </v-col>
</v-row> </v-row>
</v-list-item> </v-list-item>
<v-list-item>
<v-row dense>
<v-col>
<v-subheader>
{{ $t('then') }}
</v-subheader>
</v-col>
<v-col>
<v-select
v-model="settings.max_ratio_act"
class="mb-2"
outlined
:disabled="!settings.max_ratio_enabled && !settings.max_seeding_time_enabled"
dense
small-chips
:items="thenTypes"
/>
</v-col>
</v-row>
</v-list-item>
</v-card> </v-card>
</template> </template>
@ -178,6 +198,29 @@ import { SettingsTab, FullScreenModal } from '@/mixins'
export default { export default {
name: 'BitTorrent', name: 'BitTorrent',
mixins: [SettingsTab, FullScreenModal] mixins: [SettingsTab, FullScreenModal],
data() {
return {
thenTypes: [
{
value: 0,
text: this.$i18n.t('modals.settings.pageBittorrent.maxRatioPauseTorrent')
},
{
value: 1,
text: this.$i18n.t('modals.settings.pageBittorrent.maxRatioRemoveTorrent')
},
{
value: 3,
text: this.$i18n.t('modals.settings.pageBittorrent.maxRatioRemoveTorrentAndFiles')
},
{
value: 2,
text: this.$i18n.t('modals.settings.pageBittorrent.maxRatioTorrentSuperseeding')
}
]
}
}
} }
</script> </script>

View file

@ -42,6 +42,7 @@ const locale = {
magnet: 'Magnet', magnet: 'Magnet',
feed: 'feed', feed: 'feed',
rule: 'rule', rule: 'rule',
then: 'Then',
/** Torrent */ /** Torrent */
torrent: { torrent: {
@ -207,7 +208,11 @@ const locale = {
torrentInactivityTimer: 'Torrent inactivity timer', torrentInactivityTimer: 'Torrent inactivity timer',
subHeaderSeedLimits: 'Seed Limits', subHeaderSeedLimits: 'Seed Limits',
whenRatioReaches: 'When ratio reaches', whenRatioReaches: 'When ratio reaches',
whenSeedingTimeReaches: 'When seeding time reaches' whenSeedingTimeReaches: 'When seeding time reaches',
maxRatioPauseTorrent: 'Pause torrent',
maxRatioRemoveTorrent: 'Remove torrent',
maxRatioRemoveTorrentAndFiles: 'Remove torrent and files',
maxRatioTorrentSuperseeding: 'Enable torrent super seeding'
}, },
pageRss: { pageRss: {
tabName: { tabName: {

View file

@ -4,118 +4,133 @@ import BitTorrent from '../../src/components/Settings/Tabs/BitTorrent.vue'
let wrapper let wrapper
const getSettingsMockRes = { const getSettingsMockRes = {
dht:true, dht: true,
pex:true, pex: true,
lsd:true, lsd: true,
anonymous_mode:true, anonymous_mode: true,
queueing_enabled:true, queueing_enabled: true,
max_active_downloads:1, max_active_downloads: 1,
max_active_uploads:'max_active_uploads', max_active_uploads: 'max_active_uploads',
max_active_torrents:6, max_active_torrents: 6,
dont_count_slow_torrents:true, dont_count_slow_torrents: true,
slow_torrent_dl_rate_threshold:1, slow_torrent_dl_rate_threshold: 1,
slow_torrent_ul_rate_threshold:1, slow_torrent_ul_rate_threshold: 1,
slow_torrent_inactive_timer:1, slow_torrent_inactive_timer: 1,
max_ratio_enabled:true, max_ratio_enabled: true,
max_ratio:1, max_ratio: 1,
max_seeding_time_enabled:true, max_seeding_time_enabled: true,
max_seeding_time:1 max_seeding_time: 1
} }
const getCustomWrapper = (getSettingsRes)=> { const getCustomWrapper = getSettingsRes => {
return shallowMount(BitTorrent,{ mocks: { $t: (x) => x , $store: { return shallowMount(BitTorrent, {
getters:{getSettings:()=>{ mocks: {
return getSettingsRes $i18n: {
}}, t: x => x
state: { } },
} $t: x => x,
} }) $store: {
getters: { getSettings: () => {
return getSettingsRes
} },
state: { }
}
}
})
} }
describe('BitTorrent', () => { describe('BitTorrent', () => {
beforeEach(() => { beforeEach(() => {
wrapper = shallowMount(BitTorrent,{ mocks: { $t: (x) => x , $store: { wrapper = shallowMount(BitTorrent, {
getters:{getSettings:()=>{ mocks: {
return getSettingsMockRes $i18n: {
}}, t: x => x
state: { } },
} $t: x => x,
} }) $store: {
getters: { getSettings: () => {
return getSettingsMockRes
} },
state: { }
}
}
}) })
})
it('render correctly', () => { it('render correctly', () => {
expect(wrapper.html()).toMatchSnapshot() expect(wrapper.html()).toMatchSnapshot()
}) })
it('render correctly when anonymous_mode is false', () => { it('render correctly when anonymous_mode is false', () => {
const customerWarpper = getCustomWrapper({ const customWrapper = getCustomWrapper({
...getSettingsMockRes, ...getSettingsMockRes,
anonymous_mode:false anonymous_mode: false
})
expect(customerWarpper.html()).toMatchSnapshot()
}) })
expect(customWrapper.html()).toMatchSnapshot()
})
it('render correctly when queueing_enabled is false', () => { it('render correctly when queueing_enabled is false', () => {
const customerWarpper = getCustomWrapper({ const customWrapper = getCustomWrapper({
...getSettingsMockRes, ...getSettingsMockRes,
queueing_enabled:false queueing_enabled: false
})
expect(customerWarpper.html()).toMatchSnapshot()
}) })
expect(customWrapper.html()).toMatchSnapshot()
})
it('render correctly when dont_count_slow_torrents is false', () => { it('render correctly when dont_count_slow_torrents is false', () => {
const customerWarpper = getCustomWrapper({ const customWrapper = getCustomWrapper({
...getSettingsMockRes, ...getSettingsMockRes,
dont_count_slow_torrents:false dont_count_slow_torrents: false
})
expect(customerWarpper.html()).toMatchSnapshot()
}) })
expect(customWrapper.html()).toMatchSnapshot()
})
it('render correctly when max_ratio_enabled is false', () => { it('render correctly when max_ratio_enabled is false', () => {
const customerWarpper = getCustomWrapper({ const customWrapper = getCustomWrapper({
...getSettingsMockRes, ...getSettingsMockRes,
max_ratio_enabled:false max_ratio_enabled: false
})
expect(customerWarpper.html()).toMatchSnapshot()
}) })
expect(customWrapper.html()).toMatchSnapshot()
})
it('render correctly when max_seeding_time_enabled is false', () => { it('render correctly when max_seeding_time_enabled is false', () => {
const customerWarpper = getCustomWrapper({ const customWrapper = getCustomWrapper({
...getSettingsMockRes, ...getSettingsMockRes,
max_seeding_time_enabled:false max_seeding_time_enabled: false
})
expect(customerWarpper.html()).toMatchSnapshot()
}) })
expect(customWrapper.html()).toMatchSnapshot()
})
it('render correctly when max_active_downloads is 2', () => { it('render correctly when max_active_downloads is 2', () => {
const customerWarpper = getCustomWrapper({ const customWrapper = getCustomWrapper({
...getSettingsMockRes, ...getSettingsMockRes,
max_active_downloads:2 max_active_downloads: 2
})
expect(customerWarpper.html()).toMatchSnapshot()
}) })
expect(customWrapper.html()).toMatchSnapshot()
})
it('render correctly when max_active_torrents is 3', () => { it('render correctly when max_active_torrents is 3', () => {
const customerWarpper = getCustomWrapper({ const customWrapper = getCustomWrapper({
...getSettingsMockRes, ...getSettingsMockRes,
max_active_torrents:3 max_active_torrents: 3
})
expect(customerWarpper.html()).toMatchSnapshot()
}) })
expect(customWrapper.html()).toMatchSnapshot()
})
it('render correctly when slow_torrent_dl_rate_threshold is 25', () => { it('render correctly when slow_torrent_dl_rate_threshold is 25', () => {
const customerWarpper = getCustomWrapper({ const customWrapper = getCustomWrapper({
...getSettingsMockRes, ...getSettingsMockRes,
slow_torrent_dl_rate_threshold:25 slow_torrent_dl_rate_threshold: 25
})
expect(customerWarpper.html()).toMatchSnapshot()
}) })
expect(customWrapper.html()).toMatchSnapshot()
})
it('render correctly when slow_torrent_ul_rate_threshold is 24', () => { it('render correctly when slow_torrent_ul_rate_threshold is 24', () => {
const customerWarpper = getCustomWrapper({ const customWrapper = getCustomWrapper({
...getSettingsMockRes, ...getSettingsMockRes,
slow_torrent_ul_rate_threshold:24 slow_torrent_ul_rate_threshold: 24
})
expect(customerWarpper.html()).toMatchSnapshot()
}) })
expect(customWrapper.html()).toMatchSnapshot()
})
}) })

View file

@ -62,6 +62,18 @@ exports[`BitTorrent render correctly 1`] = `
</v-col-stub> </v-col-stub>
</v-row-stub> </v-row-stub>
</v-list-item-stub> </v-list-item-stub>
<v-list-item-stub activeclass="" tag="div">
<v-row-stub tag="div" dense="true">
<v-col-stub tag="div">
<v-subheader-stub>
then
</v-subheader-stub>
</v-col-stub>
<v-col-stub tag="div">
<v-select-stub errorcount="1" errormessages="" messages="" rules="" successmessages="" appendicon="$dropdown" backgroundcolor="" dense="true" loaderheight="2" clearicon="$clear" outlined="true" type="text" valuecomparator="[Function]" nodatatext="$vuetify.noDataText" items="[object Object],[object Object],[object Object],[object Object]" itemcolor="primary" itemdisabled="disabled" itemtext="text" itemvalue="value" menuprops="[object Object]" smallchips="true" class="mb-2"></v-select-stub>
</v-col-stub>
</v-row-stub>
</v-list-item-stub>
</v-card-stub> </v-card-stub>
`; `;
@ -127,6 +139,18 @@ exports[`BitTorrent render correctly when anonymous_mode is false 1`] = `
</v-col-stub> </v-col-stub>
</v-row-stub> </v-row-stub>
</v-list-item-stub> </v-list-item-stub>
<v-list-item-stub activeclass="" tag="div">
<v-row-stub tag="div" dense="true">
<v-col-stub tag="div">
<v-subheader-stub>
then
</v-subheader-stub>
</v-col-stub>
<v-col-stub tag="div">
<v-select-stub errorcount="1" errormessages="" messages="" rules="" successmessages="" appendicon="$dropdown" backgroundcolor="" dense="true" loaderheight="2" clearicon="$clear" outlined="true" type="text" valuecomparator="[Function]" nodatatext="$vuetify.noDataText" items="[object Object],[object Object],[object Object],[object Object]" itemcolor="primary" itemdisabled="disabled" itemtext="text" itemvalue="value" menuprops="[object Object]" smallchips="true" class="mb-2"></v-select-stub>
</v-col-stub>
</v-row-stub>
</v-list-item-stub>
</v-card-stub> </v-card-stub>
`; `;
@ -192,6 +216,18 @@ exports[`BitTorrent render correctly when dont_count_slow_torrents is false 1`]
</v-col-stub> </v-col-stub>
</v-row-stub> </v-row-stub>
</v-list-item-stub> </v-list-item-stub>
<v-list-item-stub activeclass="" tag="div">
<v-row-stub tag="div" dense="true">
<v-col-stub tag="div">
<v-subheader-stub>
then
</v-subheader-stub>
</v-col-stub>
<v-col-stub tag="div">
<v-select-stub errorcount="1" errormessages="" messages="" rules="" successmessages="" appendicon="$dropdown" backgroundcolor="" dense="true" loaderheight="2" clearicon="$clear" outlined="true" type="text" valuecomparator="[Function]" nodatatext="$vuetify.noDataText" items="[object Object],[object Object],[object Object],[object Object]" itemcolor="primary" itemdisabled="disabled" itemtext="text" itemvalue="value" menuprops="[object Object]" smallchips="true" class="mb-2"></v-select-stub>
</v-col-stub>
</v-row-stub>
</v-list-item-stub>
</v-card-stub> </v-card-stub>
`; `;
@ -257,6 +293,18 @@ exports[`BitTorrent render correctly when max_active_downloads is 2 1`] = `
</v-col-stub> </v-col-stub>
</v-row-stub> </v-row-stub>
</v-list-item-stub> </v-list-item-stub>
<v-list-item-stub activeclass="" tag="div">
<v-row-stub tag="div" dense="true">
<v-col-stub tag="div">
<v-subheader-stub>
then
</v-subheader-stub>
</v-col-stub>
<v-col-stub tag="div">
<v-select-stub errorcount="1" errormessages="" messages="" rules="" successmessages="" appendicon="$dropdown" backgroundcolor="" dense="true" loaderheight="2" clearicon="$clear" outlined="true" type="text" valuecomparator="[Function]" nodatatext="$vuetify.noDataText" items="[object Object],[object Object],[object Object],[object Object]" itemcolor="primary" itemdisabled="disabled" itemtext="text" itemvalue="value" menuprops="[object Object]" smallchips="true" class="mb-2"></v-select-stub>
</v-col-stub>
</v-row-stub>
</v-list-item-stub>
</v-card-stub> </v-card-stub>
`; `;
@ -322,6 +370,18 @@ exports[`BitTorrent render correctly when max_active_torrents is 3 1`] = `
</v-col-stub> </v-col-stub>
</v-row-stub> </v-row-stub>
</v-list-item-stub> </v-list-item-stub>
<v-list-item-stub activeclass="" tag="div">
<v-row-stub tag="div" dense="true">
<v-col-stub tag="div">
<v-subheader-stub>
then
</v-subheader-stub>
</v-col-stub>
<v-col-stub tag="div">
<v-select-stub errorcount="1" errormessages="" messages="" rules="" successmessages="" appendicon="$dropdown" backgroundcolor="" dense="true" loaderheight="2" clearicon="$clear" outlined="true" type="text" valuecomparator="[Function]" nodatatext="$vuetify.noDataText" items="[object Object],[object Object],[object Object],[object Object]" itemcolor="primary" itemdisabled="disabled" itemtext="text" itemvalue="value" menuprops="[object Object]" smallchips="true" class="mb-2"></v-select-stub>
</v-col-stub>
</v-row-stub>
</v-list-item-stub>
</v-card-stub> </v-card-stub>
`; `;
@ -387,6 +447,18 @@ exports[`BitTorrent render correctly when max_ratio_enabled is false 1`] = `
</v-col-stub> </v-col-stub>
</v-row-stub> </v-row-stub>
</v-list-item-stub> </v-list-item-stub>
<v-list-item-stub activeclass="" tag="div">
<v-row-stub tag="div" dense="true">
<v-col-stub tag="div">
<v-subheader-stub>
then
</v-subheader-stub>
</v-col-stub>
<v-col-stub tag="div">
<v-select-stub errorcount="1" errormessages="" messages="" rules="" successmessages="" appendicon="$dropdown" backgroundcolor="" dense="true" loaderheight="2" clearicon="$clear" outlined="true" type="text" valuecomparator="[Function]" nodatatext="$vuetify.noDataText" items="[object Object],[object Object],[object Object],[object Object]" itemcolor="primary" itemdisabled="disabled" itemtext="text" itemvalue="value" menuprops="[object Object]" smallchips="true" class="mb-2"></v-select-stub>
</v-col-stub>
</v-row-stub>
</v-list-item-stub>
</v-card-stub> </v-card-stub>
`; `;
@ -452,6 +524,18 @@ exports[`BitTorrent render correctly when max_seeding_time_enabled is false 1`]
</v-col-stub> </v-col-stub>
</v-row-stub> </v-row-stub>
</v-list-item-stub> </v-list-item-stub>
<v-list-item-stub activeclass="" tag="div">
<v-row-stub tag="div" dense="true">
<v-col-stub tag="div">
<v-subheader-stub>
then
</v-subheader-stub>
</v-col-stub>
<v-col-stub tag="div">
<v-select-stub errorcount="1" errormessages="" messages="" rules="" successmessages="" appendicon="$dropdown" backgroundcolor="" dense="true" loaderheight="2" clearicon="$clear" outlined="true" type="text" valuecomparator="[Function]" nodatatext="$vuetify.noDataText" items="[object Object],[object Object],[object Object],[object Object]" itemcolor="primary" itemdisabled="disabled" itemtext="text" itemvalue="value" menuprops="[object Object]" smallchips="true" class="mb-2"></v-select-stub>
</v-col-stub>
</v-row-stub>
</v-list-item-stub>
</v-card-stub> </v-card-stub>
`; `;
@ -517,6 +601,18 @@ exports[`BitTorrent render correctly when queueing_enabled is false 1`] = `
</v-col-stub> </v-col-stub>
</v-row-stub> </v-row-stub>
</v-list-item-stub> </v-list-item-stub>
<v-list-item-stub activeclass="" tag="div">
<v-row-stub tag="div" dense="true">
<v-col-stub tag="div">
<v-subheader-stub>
then
</v-subheader-stub>
</v-col-stub>
<v-col-stub tag="div">
<v-select-stub errorcount="1" errormessages="" messages="" rules="" successmessages="" appendicon="$dropdown" backgroundcolor="" dense="true" loaderheight="2" clearicon="$clear" outlined="true" type="text" valuecomparator="[Function]" nodatatext="$vuetify.noDataText" items="[object Object],[object Object],[object Object],[object Object]" itemcolor="primary" itemdisabled="disabled" itemtext="text" itemvalue="value" menuprops="[object Object]" smallchips="true" class="mb-2"></v-select-stub>
</v-col-stub>
</v-row-stub>
</v-list-item-stub>
</v-card-stub> </v-card-stub>
`; `;
@ -582,6 +678,18 @@ exports[`BitTorrent render correctly when slow_torrent_dl_rate_threshold is 25 1
</v-col-stub> </v-col-stub>
</v-row-stub> </v-row-stub>
</v-list-item-stub> </v-list-item-stub>
<v-list-item-stub activeclass="" tag="div">
<v-row-stub tag="div" dense="true">
<v-col-stub tag="div">
<v-subheader-stub>
then
</v-subheader-stub>
</v-col-stub>
<v-col-stub tag="div">
<v-select-stub errorcount="1" errormessages="" messages="" rules="" successmessages="" appendicon="$dropdown" backgroundcolor="" dense="true" loaderheight="2" clearicon="$clear" outlined="true" type="text" valuecomparator="[Function]" nodatatext="$vuetify.noDataText" items="[object Object],[object Object],[object Object],[object Object]" itemcolor="primary" itemdisabled="disabled" itemtext="text" itemvalue="value" menuprops="[object Object]" smallchips="true" class="mb-2"></v-select-stub>
</v-col-stub>
</v-row-stub>
</v-list-item-stub>
</v-card-stub> </v-card-stub>
`; `;
@ -647,5 +755,17 @@ exports[`BitTorrent render correctly when slow_torrent_ul_rate_threshold is 24 1
</v-col-stub> </v-col-stub>
</v-row-stub> </v-row-stub>
</v-list-item-stub> </v-list-item-stub>
<v-list-item-stub activeclass="" tag="div">
<v-row-stub tag="div" dense="true">
<v-col-stub tag="div">
<v-subheader-stub>
then
</v-subheader-stub>
</v-col-stub>
<v-col-stub tag="div">
<v-select-stub errorcount="1" errormessages="" messages="" rules="" successmessages="" appendicon="$dropdown" backgroundcolor="" dense="true" loaderheight="2" clearicon="$clear" outlined="true" type="text" valuecomparator="[Function]" nodatatext="$vuetify.noDataText" items="[object Object],[object Object],[object Object],[object Object]" itemcolor="primary" itemdisabled="disabled" itemtext="text" itemvalue="value" menuprops="[object Object]" smallchips="true" class="mb-2"></v-select-stub>
</v-col-stub>
</v-row-stub>
</v-list-item-stub>
</v-card-stub> </v-card-stub>
`; `;