Refactoring diagnostic tests in multiple files.

This commit is contained in:
John Livingston
2021-04-12 17:53:12 +02:00
parent 6bc1f66cf1
commit d1ede8d3ee
9 changed files with 240 additions and 157 deletions

View File

@ -0,0 +1,54 @@
import { newResult, TestResult } from './utils'
export async function diagVideo (test: string, settingsManager: PluginSettingsManager): Promise<TestResult> {
const result = newResult(test)
result.label = 'Webchat activated on videos'
const videoSettings = await settingsManager.getSettings([
'chat-auto-display',
'chat-open-blank',
'chat-only-locals',
'chat-all-lives',
'chat-all-non-lives',
'chat-videos-list'
])
if (videoSettings['chat-auto-display']) {
result.messages.push('Chat will open automatically')
} else {
result.messages.push('Chat will not open automatically')
}
if (videoSettings['chat-open-blank']) {
result.messages.push('Displaying «open in new window» button')
}
if (videoSettings['chat-only-locals']) {
result.messages.push('Chat will only be available for local videos')
}
let atLeastOne: boolean = false
if (videoSettings['chat-all-lives']) {
result.messages.push('Chat is enabled for all lives.')
atLeastOne = true
}
if (videoSettings['chat-all-non-lives']) {
result.messages.push('Chat is enabled for all non-lives.')
atLeastOne = true
}
if ((videoSettings['chat-videos-list'] ?? '') !== '') {
const lines = ((videoSettings['chat-videos-list'] ?? '') as string).split('\n')
for (let i = 0; i < lines.length; i++) {
if (/^\s*(-|\w)+\s*($|#)/.test(lines[i])) {
result.messages.push('Chat is activated for a specific videos.')
atLeastOne = true
}
}
}
if (atLeastOne) {
result.ok = true
result.next = 'webchat-type'
} else {
result.ok = false
result.messages.push('Chat is activate for no video.')
}
return result
}