fix: Fixes issue where lock screen would not use previously active theme (#2372)

This commit is contained in:
Mo
2023-07-26 15:50:08 -05:00
committed by GitHub
parent 86fc4c684d
commit d268c02ab3
88 changed files with 1118 additions and 716 deletions

View File

@@ -22,7 +22,7 @@
"prebuild": "yarn clean",
"build": "tsc -p tsconfig.json",
"lint": "eslint src --ext .ts",
"test": "jest spec"
"test": "jest"
},
"dependencies": {
"@standardnotes/common": "^1.50.0",

View File

@@ -1,11 +1,46 @@
import * as DOMPurifyLib from 'dompurify'
import { JSDOM } from 'jsdom'
import { sortByKey, withoutLastElement } from './Utils'
import { sortByKey, withoutLastElement, compareArrayReferences } from './Utils'
const window = new JSDOM('').window
const DOMPurify = DOMPurifyLib(window as never)
describe('Utils', () => {
describe('compareArrayReferences', () => {
it('should return true when both arrays are empty', () => {
expect(compareArrayReferences([], [])).toBe(true)
})
it('should return true when both arrays have the same reference', () => {
const obj = {}
expect(compareArrayReferences([obj], [obj])).toBe(true)
})
it('should return false when arrays have different lengths', () => {
const obj1 = {}
const obj2 = {}
expect(compareArrayReferences([obj1], [obj1, obj2])).toBe(false)
})
it('should return false when arrays have the same length but different references', () => {
const obj1 = {}
const obj2 = {}
expect(compareArrayReferences([obj1], [obj2])).toBe(false)
})
it('should return true when arrays have multiple identical references', () => {
const obj1 = {}
const obj2 = {}
expect(compareArrayReferences([obj1, obj2], [obj1, obj2])).toBe(true)
})
it('should return false when arrays have the same references in different order', () => {
const obj1 = {}
const obj2 = {}
expect(compareArrayReferences([obj1, obj2], [obj2, obj1])).toBe(false)
})
})
it('sanitizeHtmlString', () => {
const dirty = '<svg><animate onbegin=alert(1) attributeName=x dur=1s>'
const cleaned = DOMPurify.sanitize(dirty)

View File

@@ -223,6 +223,10 @@ export function arrayByDifference<T>(array: T[], subtract: T[]): T[] {
return array.filter((x) => !subtract.includes(x)).concat(subtract.filter((x) => !array.includes(x)))
}
export function compareArrayReferences<T>(arr1: T[], arr2: T[]) {
return arr1.length === arr2.length && arr1.every((val, index) => val === arr2[index])
}
export function compareValues<T>(left: T, right: T) {
if ((left && !right) || (!left && right)) {
return false