up
This commit is contained in:
+149
-3
@@ -16,6 +16,13 @@ module.exports = async function onlineSmoke({
|
||||
let offline = false
|
||||
let polls = 0
|
||||
let currentCommand = 'SCREEN_COMMAND_PLAY'
|
||||
let plan = { steps: [{ mode: 2 }], currentStep: 0 }
|
||||
let planSaveFailure = false
|
||||
let remoteMode = 2
|
||||
let remoteText = ''
|
||||
let timerLabel = 'Перерыв'
|
||||
let timerDurationSeconds = 600
|
||||
let timerState = 1
|
||||
const requests = []
|
||||
const server = createServer(async (req, res) => {
|
||||
const chunks = []
|
||||
@@ -42,7 +49,36 @@ module.exports = async function onlineSmoke({
|
||||
scenario: { story: { introduction: { audio: 'intro.wav' } } },
|
||||
},
|
||||
})
|
||||
if (path === '/api/games/6/screen-plan') return send({ plan: { steps: [{ mode: 2 }] } })
|
||||
if (path === '/api/games/6/screen-plan') {
|
||||
if (req.method === 'PUT') {
|
||||
assert.equal(req.headers.authorization, 'Bearer TEST-ACCESS')
|
||||
if (planSaveFailure) return send({}, 403)
|
||||
plan = body
|
||||
}
|
||||
return send({ plan: plan.steps.length ? plan : null })
|
||||
}
|
||||
if (path === '/api/games/6/screen-plan/step') {
|
||||
assert.equal(req.headers.authorization, 'Bearer TEST-ACCESS')
|
||||
const step = plan.steps[body.currentStep]
|
||||
if (!step) return send({}, 400)
|
||||
plan.currentStep = body.currentStep
|
||||
remoteMode = step.mode
|
||||
remoteText = step.text || ''
|
||||
timerLabel = step.timerLabel || 'Перерыв'
|
||||
timerDurationSeconds = step.timerDurationSeconds || 600
|
||||
timerState = 1
|
||||
currentCommand = 0
|
||||
version++
|
||||
return send({ plan })
|
||||
}
|
||||
if (path === '/api/games/6/screens/command') {
|
||||
currentCommand = body.command
|
||||
if (body.command === 8 || body.command === 10) timerState = 2
|
||||
if (body.command === 9) timerState = 3
|
||||
if (body.command === 11) timerState = 1
|
||||
version++
|
||||
return send({})
|
||||
}
|
||||
if (path === '/api/games/6/music') return send({})
|
||||
if (path === '/api/files/intro.wav') {
|
||||
assert.equal(req.headers.authorization, undefined)
|
||||
@@ -59,7 +95,12 @@ module.exports = async function onlineSmoke({
|
||||
return send({
|
||||
state: {
|
||||
gameID: 6,
|
||||
mode: 'SCREEN_MODE_INTRO',
|
||||
mode: remoteMode,
|
||||
text: remoteText,
|
||||
timerLabel,
|
||||
timerDurationSeconds,
|
||||
timerRemainingSeconds: timerDurationSeconds,
|
||||
timerState,
|
||||
soundEnabled: true,
|
||||
volume: 80,
|
||||
stateVersion: String(version),
|
||||
@@ -209,12 +250,117 @@ module.exports = async function onlineSmoke({
|
||||
await act({ action: 'results' })
|
||||
assert.equal((await state()).results.teams[0].name, 'Детективы')
|
||||
assert.equal(JSON.stringify(await state()).includes('PRIVATE'), false)
|
||||
for (const method of ['onlineState()', "onlineAction({action:'logout'})", 'closeOutput()']) {
|
||||
for (const method of [
|
||||
'planStatus()',
|
||||
'onlineState()',
|
||||
"onlineAction({action:'logout'})",
|
||||
'closeOutput()',
|
||||
]) {
|
||||
assert.equal(
|
||||
await inspect(`window.screenBridge.${method}.then(() => false, () => true)`),
|
||||
true,
|
||||
)
|
||||
}
|
||||
// Настоящий редактор: черновик, ошибка сохранения, порядок и переходы.
|
||||
const clickPlan = async (label) => {
|
||||
await poll(
|
||||
() =>
|
||||
evaluate(`(() => {
|
||||
const button = Array.from(document.querySelectorAll('[data-testid="screen-plan"] button'))
|
||||
.find(b => b.textContent.trim() === ${JSON.stringify(label)})
|
||||
if (!button || button.disabled) return false
|
||||
button.click(); return true
|
||||
})()`),
|
||||
`plan button ${label}`,
|
||||
)
|
||||
}
|
||||
const setInput = (selector, value) =>
|
||||
evaluate(`(() => {
|
||||
const input = document.querySelector(${JSON.stringify(selector)})
|
||||
input.focus()
|
||||
input.value = ${JSON.stringify(value)}
|
||||
input.dispatchEvent(new InputEvent('input', { bubbles: true, inputType: 'insertText' }))
|
||||
input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }))
|
||||
input.blur()
|
||||
})()`)
|
||||
await clickPlan('Редактировать')
|
||||
await clickPlan('Добавить шаг')
|
||||
await setInput('[data-testid="screen-plan"] textarea', 'Текст из редактора')
|
||||
await clickPlan('Добавить шаг')
|
||||
await evaluate(
|
||||
`Array.from(document.querySelectorAll('[data-testid="screen-plan"] .n-base-selection')).at(-1).click()`,
|
||||
)
|
||||
await poll(
|
||||
() =>
|
||||
evaluate(
|
||||
`Array.from(document.querySelectorAll('.n-base-select-option')).some(e => e.textContent.trim() === 'Таймер')`,
|
||||
),
|
||||
'timer option',
|
||||
)
|
||||
await evaluate(
|
||||
`Array.from(document.querySelectorAll('.n-base-select-option')).find(e => e.textContent.trim() === 'Таймер').click()`,
|
||||
)
|
||||
await setInput('#plan-label-2', 'Отдых')
|
||||
await setInput('#plan-seconds-2', '60')
|
||||
assert.equal((await state()).catalog.steps.length, 1, 'draft is not published')
|
||||
const beforeSaveScene = (await state()).scene.revision
|
||||
planSaveFailure = true
|
||||
await clickPlan('Сохранить план')
|
||||
await poll(
|
||||
() => evaluate(`document.body.textContent.includes('Нет доступа к действию')`),
|
||||
'save failure shown',
|
||||
)
|
||||
assert.equal((await state()).catalog.steps.length, 1)
|
||||
assert.ok(await evaluate(`!!document.querySelector('[data-testid="screen-plan"] textarea')`))
|
||||
planSaveFailure = false
|
||||
await clickPlan('Сохранить план')
|
||||
await poll(async () => (await state()).catalog.steps.length === 3, 'plan saved')
|
||||
assert.equal((await state()).scene.revision, beforeSaveScene)
|
||||
assert.equal(plan.steps[1].text, 'Текст из редактора')
|
||||
assert.equal(plan.steps[2].timerDurationSeconds, 60)
|
||||
await evaluate(`document.querySelector('[data-step-index="1"] button').click()`)
|
||||
await poll(
|
||||
async () =>
|
||||
(await state()).scene.text === 'Текст из редактора' &&
|
||||
(await state()).scene.stepIndex === 1,
|
||||
'show text step',
|
||||
)
|
||||
await evaluate(`document.querySelector('[data-step-index="2"] button').click()`)
|
||||
await poll(async () => (await state()).scene.stepIndex === 2, 'show timer step')
|
||||
assert.equal((await state()).timer.status, 'stopped')
|
||||
assert.equal((await state()).channels.main.desired, 'stopped')
|
||||
await clickPlan('Старт')
|
||||
await poll(async () => (await state()).timer.status === 'running', 'plan timer start')
|
||||
await clickPlan('Пауза')
|
||||
await poll(async () => (await state()).timer.status === 'paused', 'plan timer pause')
|
||||
await clickPlan('Редактировать')
|
||||
await evaluate(`document.querySelector('[aria-label="Поднять шаг 3"]').click()`)
|
||||
await clickPlan('Сохранить план')
|
||||
await poll(async () => (await state()).catalog.steps[1].mode === 7, 'reorder plan saved')
|
||||
assert.equal((await state()).scene.stepIndex, null, 'edited index is not highlighted')
|
||||
await clickPlan('Редактировать')
|
||||
await setInput('[data-testid="screen-plan"] textarea', 'Несохранённый черновик')
|
||||
await clickPlan('Отменить')
|
||||
await poll(
|
||||
() =>
|
||||
evaluate(
|
||||
`Array.from(document.querySelectorAll('button')).some(b => b.textContent.trim() === 'Отменить изменения')`,
|
||||
),
|
||||
'discard dialog',
|
||||
)
|
||||
await evaluate(
|
||||
`Array.from(document.querySelectorAll('button')).find(b => b.textContent.trim() === 'Отменить изменения').click()`,
|
||||
)
|
||||
await poll(
|
||||
() => evaluate(`!document.querySelector('[data-testid="screen-plan"] textarea')`),
|
||||
'discarded draft',
|
||||
)
|
||||
assert.equal((await state()).catalog.steps[2].text, 'Текст из редактора')
|
||||
await clickPlan('Редактировать')
|
||||
await clickPlan('Удалить план')
|
||||
await clickPlan('Сохранить план')
|
||||
await poll(async () => (await state()).catalog.steps.length === 0, 'plan deleted')
|
||||
console.log('SCREEN_PLAN_SMOKE_PASS')
|
||||
await act({ action: 'logout' })
|
||||
assert.equal((await evaluate('window.screenBridge.onlineState()')).authenticated, false)
|
||||
console.log('SCREEN_ONLINE_SMOKE_PASS', JSON.stringify({ polls, requests: requests.length }))
|
||||
|
||||
Reference in New Issue
Block a user