]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fix: some random frontend fixes and coverage
authorshamoon <4887959+shamoon@users.noreply.github.com>
Thu, 5 Dec 2024 00:31:16 +0000 (16:31 -0800)
committershamoon <4887959+shamoon@users.noreply.github.com>
Thu, 5 Dec 2024 05:15:45 +0000 (21:15 -0800)
src-ui/src/app/components/common/input/switch/switch.component.spec.ts
src-ui/src/app/components/document-list/document-card-large/document-card-large.component.spec.ts
src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts
src-ui/src/app/components/document-list/document-card-small/document-card-small.component.spec.ts
src-ui/src/app/components/document-list/document-card-small/document-card-small.component.ts
src-ui/src/app/utils/color.spec.ts
src-ui/src/app/utils/color.ts

index 372bfd8abf847a54027a2839cd241beaaf236364..790330955dfc6eb3ec73f9edfc74516ec06f9edf 100644 (file)
@@ -38,8 +38,10 @@ describe('SwitchComponent', () => {
     expect(component.value).toBeFalsy()
   })
 
-  it('should show note if unset', () => {
+  it('should correctly report unset', () => {
     component.value = null
     expect(component.isUnset).toBeTruthy()
+    component.value = undefined
+    expect(component.isUnset).toBeTruthy()
   })
 })
index 95b12d7ec4f1c51a157e5219e4f835b15c0be7d7..8905d3ff233cfdf2c67432a8a7c1e305f9aec176 100644 (file)
@@ -120,4 +120,12 @@ describe('DocumentCardLargeComponent', () => {
     expect(fixture.nativeElement.textContent).toContain('bananas')
     expect(component.searchNoteHighlights).toContain('<span>bananas</span>')
   })
+
+  it('should try to close the preview on mouse leave', () => {
+    component.popupPreview = {
+      close: jest.fn(),
+    } as any
+    component.mouseLeaveCard()
+    expect(component.popupPreview.close).toHaveBeenCalled()
+  })
 })
index 99597ca5aa83fc4b5c96ee1f5e58d305e981a53d..d33cef9f372b53b759521cd0af54e4740e0a5daa 100644 (file)
@@ -108,12 +108,8 @@ export class DocumentCardLargeComponent extends ComponentWithPermissions {
     return this.documentService.getDownloadUrl(this.document.id)
   }
 
-  get previewUrl() {
-    return this.documentService.getPreviewUrl(this.document.id)
-  }
-
   mouseLeaveCard() {
-    this.popupPreview.close()
+    this.popupPreview?.close()
   }
 
   get contentTrimmed() {
index 0c0c821036e4bcde038f80d43385e5bfb6b13406..7bdb0c3f804579164d977b23d0d2cb48eb2a59d6 100644 (file)
@@ -111,4 +111,12 @@ describe('DocumentCardSmallComponent', () => {
       fixture.debugElement.queryAll(By.directive(TagComponent))
     ).toHaveLength(6)
   })
+
+  it('should try to close the preview on mouse leave', () => {
+    component.popupPreview = {
+      close: jest.fn(),
+    } as any
+    component.mouseLeaveCard()
+    expect(component.popupPreview.close).toHaveBeenCalled()
+  })
 })
index 7397159af34e0a84e1e044130947dfe360c16e4a..f8705fa8e64ed0b4139e75a2d3c839ccd60feed6 100644 (file)
@@ -94,7 +94,7 @@ export class DocumentCardSmallComponent extends ComponentWithPermissions {
   }
 
   mouseLeaveCard() {
-    this.popupPreview.close()
+    this.popupPreview?.close()
   }
 
   get notesEnabled(): boolean {
index 4dddb59a191eb7f7fef60f692458b957e51d8627..d31ad1b26b32d75dc8ff9a3a4e3e6f4108fd1451 100644 (file)
@@ -1,8 +1,10 @@
 import {
   BRIGHTNESS,
+  componentToHex,
   computeLuminance,
   estimateBrightnessForColor,
   hexToHsl,
+  hslToRgb,
   randomColor,
   rgbToHsl,
 } from './color'
@@ -44,7 +46,21 @@ describe('Color Utils', () => {
     expect(hsl).toEqual([0, 0, 0.5019607843137255])
   })
 
+  it('should convert hsl to rgb', () => {
+    let rgb = hslToRgb(0, 0, 0.5)
+    expect(rgb).toEqual([127.5, 127.5, 127.5])
+    expect(hslToRgb(0, 0, 0)).toEqual([0, 0, 0])
+    expect(hslToRgb(0, 0, 1)).toEqual([255, 255, 255])
+  })
+
   it('should return a random color', () => {
     expect(randomColor()).not.toBeNull()
   })
+
+  it('should convert component to hex', () => {
+    expect(componentToHex(0)).toEqual('00')
+    expect(componentToHex(255)).toEqual('ff')
+    expect(componentToHex(128)).toEqual('80')
+    expect(componentToHex(15)).toEqual('0f')
+  })
 })
index e23a91c5f1e2131b2815e99ba856f9842c93cf1b..b2899571e57d6b8f832ca21d66edc5ae971a319f 100644 (file)
@@ -5,7 +5,7 @@ export const BRIGHTNESS = {
   DARK: 'dark',
 }
 
-function componentToHex(c) {
+export function componentToHex(c) {
   var hex = Math.floor(c).toString(16)
   return hex.length == 1 ? '0' + hex : hex
 }
@@ -23,21 +23,22 @@ function componentToHex(c) {
  * @param   Number  l       The lightness
  * @return  Array           The RGB representation
  */
-function hslToRgb(h, s, l) {
+
+function hue2rgb(p, q, t) {
+  if (t < 0) t += 1
+  if (t > 1) t -= 1
+  if (t < 1 / 6) return p + (q - p) * 6 * t
+  if (t < 1 / 2) return q
+  if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6
+  return p
+}
+
+export function hslToRgb(h, s, l) {
   var r, g, b
 
   if (s == 0) {
     r = g = b = l // achromatic
   } else {
-    function hue2rgb(p, q, t) {
-      if (t < 0) t += 1
-      if (t > 1) t -= 1
-      if (t < 1 / 6) return p + (q - p) * 6 * t
-      if (t < 1 / 2) return q
-      if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6
-      return p
-    }
-
     var q = l < 0.5 ? l * (1 + s) : l + s - l * s
     var p = 2 * l - q
     r = hue2rgb(p, q, h + 1 / 3)