mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-29 20:11:32 +02:00
* Update selectors to improve test stability * Update selectors to improve test stability * Use plain string matchers * Fix test * [monorepo] use plain string matchers everywhere * [web] remove Kb/ prefix from title of learn wiki links --------- Co-authored-by: Jakob Ackermann <jakob.ackermann@overleaf.com> GitOrigin-RevId: 12e13c39822795338a3bee20236454f9948e6221
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
/**
|
|
* Helper function for throttling clicks on the recompile button to avoid hitting server side rate limits.
|
|
* The naive approach is waiting a fixed a mount of time (3s) just before clicking the button.
|
|
* This helper takes into account that other UI interactions take time. We can deduce that latency from the fixed delay (3s minus other latency). This can bring down the effective waiting time to 0s.
|
|
*/
|
|
export function throttledRecompile() {
|
|
const { queueReset, recompile } = prepareWaitForNextCompileSlot()
|
|
queueReset()
|
|
return recompile
|
|
}
|
|
|
|
export function stopCompile(options: { delay?: number } = {}) {
|
|
const { delay = 0 } = options
|
|
cy.wait(delay)
|
|
cy.log('Stop compile')
|
|
cy.findByRole('button', { name: 'Toggle compile options menu' }).click()
|
|
cy.findByRole('menuitem', { name: 'Stop compilation' }).click()
|
|
}
|
|
|
|
export function prepareWaitForNextCompileSlot() {
|
|
let lastCompile = 0
|
|
function queueReset() {
|
|
cy.then(() => {
|
|
lastCompile = Date.now()
|
|
})
|
|
}
|
|
function waitForCompileRateLimitCoolOff(triggerCompile: () => void) {
|
|
cy.then(() => {
|
|
cy.log('Wait for recompile rate-limit to cool off')
|
|
const msSinceLastCompile = Date.now() - lastCompile
|
|
cy.wait(Math.max(0, 1_000 - msSinceLastCompile))
|
|
queueReset()
|
|
triggerCompile()
|
|
cy.log('Wait for compile to finish')
|
|
cy.findByRole('button', { name: 'Recompile' }).should('be.visible')
|
|
})
|
|
}
|
|
function recompile() {
|
|
waitForCompileRateLimitCoolOff(() => {
|
|
cy.findByText('Recompile').click()
|
|
})
|
|
}
|
|
return {
|
|
queueReset,
|
|
waitForCompileRateLimitCoolOff,
|
|
recompile,
|
|
}
|
|
}
|