mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-31 12:51:35 +02:00
Merge pull request #28544 from overleaf/ac-some-web-esm-migration-4
[web] Convert some Features files to ES modules (part 4) GitOrigin-RevId: cf11a7584e39c4d4de08e2f924240e488a4066c4
This commit is contained in:
@@ -1,19 +1,20 @@
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const { expect } = require('chai')
|
||||
const sinon = require('sinon')
|
||||
const { ObjectId } = require('mongodb-legacy')
|
||||
import { vi, expect } from 'vitest'
|
||||
import sinon from 'sinon'
|
||||
import mongodb from 'mongodb-legacy'
|
||||
|
||||
const { ObjectId } = mongodb
|
||||
|
||||
const MODULE_PATH = '../../../../app/src/Features/Tutorial/TutorialHandler'
|
||||
|
||||
describe('TutorialHandler', function () {
|
||||
beforeEach(function () {
|
||||
this.clock = sinon.useFakeTimers()
|
||||
beforeEach(async function (ctx) {
|
||||
ctx.clock = sinon.useFakeTimers()
|
||||
|
||||
const THIRTY_DAYS_AGO = Date.now() - 30 * 24 * 60 * 60 * 1000
|
||||
const TOMORROW = Date.now() + 24 * 60 * 60 * 1000
|
||||
const YESTERDAY = Date.now() - 24 * 60 * 60 * 1000
|
||||
|
||||
this.user = {
|
||||
ctx.user = {
|
||||
_id: new ObjectId(),
|
||||
completedTutorials: {
|
||||
'legacy-format': new Date(Date.now() - 1000),
|
||||
@@ -42,28 +43,26 @@ describe('TutorialHandler', function () {
|
||||
},
|
||||
}
|
||||
|
||||
this.UserUpdater = {
|
||||
ctx.UserUpdater = {
|
||||
promises: {
|
||||
updateUser: sinon.stub().resolves(),
|
||||
},
|
||||
}
|
||||
|
||||
this.TutorialHandler = SandboxedModule.require(MODULE_PATH, {
|
||||
requires: {
|
||||
'../User/UserUpdater': this.UserUpdater,
|
||||
},
|
||||
})
|
||||
vi.doMock('../../../../app/src/Features/User/UserUpdater', () => ({
|
||||
default: ctx.UserUpdater,
|
||||
}))
|
||||
|
||||
ctx.TutorialHandler = (await import(MODULE_PATH)).default
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
this.clock.restore()
|
||||
afterEach(function (ctx) {
|
||||
ctx.clock.restore()
|
||||
})
|
||||
|
||||
describe('getInactiveTutorials', function () {
|
||||
it('returns all recorded tutorials except when they were posponed long ago', function () {
|
||||
const hiddenTutorials = this.TutorialHandler.getInactiveTutorials(
|
||||
this.user
|
||||
)
|
||||
it('returns all recorded tutorials except when they were posponed long ago', function (ctx) {
|
||||
const hiddenTutorials = ctx.TutorialHandler.getInactiveTutorials(ctx.user)
|
||||
expect(hiddenTutorials).to.have.members([
|
||||
'legacy-format',
|
||||
'completed',
|
||||
@@ -73,7 +72,7 @@ describe('TutorialHandler', function () {
|
||||
|
||||
expect(hiddenTutorials).to.have.lengthOf(4)
|
||||
|
||||
const shownTutorials = Object.keys(this.user.completedTutorials).filter(
|
||||
const shownTutorials = Object.keys(ctx.user.completedTutorials).filter(
|
||||
key => !hiddenTutorials.includes(key)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user