|
|
@@ -1,27 +1,15 @@
|
|
|
-import { vi, expect } from 'vitest'
|
|
|
-import sinon from 'sinon'
|
|
|
+import { expect } from 'vitest'
|
|
|
const modulePath = '../../../../app/src/Features/Project/UserSettingsHelper.mjs'
|
|
|
|
|
|
describe('UserSettingsHelper', function () {
|
|
|
beforeEach(async function (ctx) {
|
|
|
- ctx.SplitTestHandler = {
|
|
|
- promises: { getAssignment: sinon.stub() },
|
|
|
- }
|
|
|
-
|
|
|
- vi.doMock(
|
|
|
- '../../../../app/src/Features/SplitTests/SplitTestHandler.mjs',
|
|
|
- () => ({
|
|
|
- default: ctx.SplitTestHandler,
|
|
|
- })
|
|
|
- )
|
|
|
-
|
|
|
ctx.req = { query: {} }
|
|
|
ctx.res = {}
|
|
|
ctx.UserSettingsHelper = (await import(modulePath)).default
|
|
|
})
|
|
|
|
|
|
- describe('for user with overall theme set to value', function () {
|
|
|
- beforeEach(async function (ctx) {
|
|
|
+ describe('overall theme', function () {
|
|
|
+ it('should return the overall theme if set', async function (ctx) {
|
|
|
const user = {
|
|
|
ace: {
|
|
|
overallTheme: 'light',
|
|
|
@@ -29,137 +17,43 @@ describe('UserSettingsHelper', function () {
|
|
|
signUpDate: new Date('2022-01-01'),
|
|
|
}
|
|
|
|
|
|
- ctx.settings = await ctx.UserSettingsHelper.buildUserSettings(
|
|
|
+ const settings = await ctx.UserSettingsHelper.buildUserSettings(
|
|
|
ctx.req,
|
|
|
ctx.res,
|
|
|
user
|
|
|
)
|
|
|
- })
|
|
|
-
|
|
|
- it('should return the user settings with the correct overall theme', function (ctx) {
|
|
|
- expect(ctx.settings.overallTheme).toBe('light')
|
|
|
- })
|
|
|
-
|
|
|
- it('should not check split test', function (ctx) {
|
|
|
- expect(ctx.SplitTestHandler.promises.getAssignment).not.toHaveBeenCalled
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- describe('for user with no overall theme set', function () {
|
|
|
- describe('for new users in treatment group', function () {
|
|
|
- beforeEach(async function (ctx) {
|
|
|
- const user = {
|
|
|
- ace: {},
|
|
|
- signUpDate: new Date('2027-02-16T00:00:00Z'),
|
|
|
- }
|
|
|
-
|
|
|
- ctx.SplitTestHandler.promises.getAssignment
|
|
|
- .withArgs(ctx.req, ctx.res, 'new-user-system-overall-theme')
|
|
|
- .resolves({
|
|
|
- variant: 'system',
|
|
|
- })
|
|
|
-
|
|
|
- ctx.settings = await ctx.UserSettingsHelper.buildUserSettings(
|
|
|
- ctx.req,
|
|
|
- ctx.res,
|
|
|
- user
|
|
|
- )
|
|
|
- })
|
|
|
-
|
|
|
- it('should default to system theme', function (ctx) {
|
|
|
- expect(ctx.settings.overallTheme).toBe('system')
|
|
|
- })
|
|
|
-
|
|
|
- it('should check split test', function (ctx) {
|
|
|
- expect(ctx.SplitTestHandler.promises.getAssignment).toHaveBeenCalled
|
|
|
- })
|
|
|
- })
|
|
|
-
|
|
|
- describe('for new users in control group', function () {
|
|
|
- beforeEach(async function (ctx) {
|
|
|
- const user = {
|
|
|
- ace: {},
|
|
|
- signUpDate: new Date('2027-02-16T00:00:00Z'),
|
|
|
- }
|
|
|
-
|
|
|
- ctx.SplitTestHandler.promises.getAssignment
|
|
|
- .withArgs(ctx.req, ctx.res, 'new-user-system-overall-theme')
|
|
|
- .resolves({
|
|
|
- variant: 'default',
|
|
|
- })
|
|
|
-
|
|
|
- ctx.settings = await ctx.UserSettingsHelper.buildUserSettings(
|
|
|
- ctx.req,
|
|
|
- ctx.res,
|
|
|
- user
|
|
|
- )
|
|
|
- })
|
|
|
|
|
|
- it('should default to dark theme', function (ctx) {
|
|
|
- expect(ctx.settings.overallTheme).toBe('')
|
|
|
- })
|
|
|
-
|
|
|
- it('should check split test', function (ctx) {
|
|
|
- expect(ctx.SplitTestHandler.promises.getAssignment).toHaveBeenCalled
|
|
|
- })
|
|
|
+ expect(settings.overallTheme).toBe('light')
|
|
|
})
|
|
|
|
|
|
- describe('for old users in control group', function () {
|
|
|
- beforeEach(async function (ctx) {
|
|
|
- const user = {
|
|
|
- ace: {},
|
|
|
- signUpDate: new Date('2025-02-15T00:00:00Z'),
|
|
|
- }
|
|
|
-
|
|
|
- ctx.SplitTestHandler.promises.getAssignment
|
|
|
- .withArgs(ctx.req, ctx.res, 'new-user-system-overall-theme')
|
|
|
- .resolves({
|
|
|
- variant: 'default',
|
|
|
- })
|
|
|
-
|
|
|
- ctx.settings = await ctx.UserSettingsHelper.buildUserSettings(
|
|
|
- ctx.req,
|
|
|
- ctx.res,
|
|
|
- user
|
|
|
- )
|
|
|
- })
|
|
|
+ it('should return system for new users with no overall theme set', async function (ctx) {
|
|
|
+ const user = {
|
|
|
+ ace: {},
|
|
|
+ signUpDate: new Date('2026-03-16T00:00:00Z'),
|
|
|
+ }
|
|
|
|
|
|
- it('should default to dark theme', function (ctx) {
|
|
|
- expect(ctx.settings.overallTheme).toBe('')
|
|
|
- })
|
|
|
+ const settings = await ctx.UserSettingsHelper.buildUserSettings(
|
|
|
+ ctx.req,
|
|
|
+ ctx.res,
|
|
|
+ user
|
|
|
+ )
|
|
|
|
|
|
- it('should not check split test', function (ctx) {
|
|
|
- expect(ctx.SplitTestHandler.promises.getAssignment).not.toHaveBeenCalled
|
|
|
- })
|
|
|
+ expect(settings.overallTheme).toBe('system')
|
|
|
})
|
|
|
|
|
|
- describe('for old users in treatment group', function () {
|
|
|
- beforeEach(async function (ctx) {
|
|
|
- const user = {
|
|
|
- ace: {},
|
|
|
- signUpDate: new Date('2025-02-15T00:00:00Z'),
|
|
|
- }
|
|
|
-
|
|
|
- ctx.SplitTestHandler.promises.getAssignment
|
|
|
- .withArgs(ctx.req, ctx.res, 'new-user-system-overall-theme')
|
|
|
- .resolves({
|
|
|
- variant: 'system',
|
|
|
- })
|
|
|
-
|
|
|
- ctx.settings = await ctx.UserSettingsHelper.buildUserSettings(
|
|
|
- ctx.req,
|
|
|
- ctx.res,
|
|
|
- user
|
|
|
- )
|
|
|
- })
|
|
|
+ it('should return dark for old users with no overall theme set', async function (ctx) {
|
|
|
+ const user = {
|
|
|
+ ace: {},
|
|
|
+ signUpDate: new Date('2025-02-15T00:00:00Z'),
|
|
|
+ }
|
|
|
|
|
|
- it('should default to dark theme', function (ctx) {
|
|
|
- expect(ctx.settings.overallTheme).toBe('')
|
|
|
- })
|
|
|
+ const settings = await ctx.UserSettingsHelper.buildUserSettings(
|
|
|
+ ctx.req,
|
|
|
+ ctx.res,
|
|
|
+ user
|
|
|
+ )
|
|
|
|
|
|
- it('should not check split test', function (ctx) {
|
|
|
- expect(ctx.SplitTestHandler.promises.getAssignment).not.toHaveBeenCalled
|
|
|
- })
|
|
|
+ expect(settings.overallTheme).toBe('')
|
|
|
})
|
|
|
})
|
|
|
})
|