File size: 2,949 Bytes
3e05655
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { expect, test } from "bun:test"
import { classifySessionSwitch } from "../timeline/session-tab-switch-metrics"

test("counts source and blank samples before the destination is observed", () => {
  const result = classifySessionSwitch([
    { observedAtMs: 16, destination: [], source: ["source"], hasVisibleRows: true, last: false },
    { observedAtMs: 32, destination: [], source: [], hasVisibleRows: false, last: false },
    { observedAtMs: 48, destination: ["destination"], source: [], hasVisibleRows: true, last: true, bottomErrorPx: 0 },
    { observedAtMs: 64, destination: ["destination"], source: [], hasVisibleRows: true, last: true, bottomErrorPx: 0 },
    { observedAtMs: 80, destination: ["destination"], source: [], hasVisibleRows: true, last: true, bottomErrorPx: 0 },
  ])

  expect(result.blankSamples).toBe(1)
  expect(result.sourceSamples).toBe(1)
  expect(result.unknownSamples).toBe(0)
  expect(result.firstDestinationObservedMs).toBe(48)
  expect(result.stableObservedMs).toBe(80)
})

test("does not classify mixed source and destination content as correct", () => {
  const result = classifySessionSwitch([
    {
      observedAtMs: 16,
      destination: ["destination"],
      source: ["source"],
      hasVisibleRows: true,
      last: true,
      bottomErrorPx: 0,
    },
    { observedAtMs: 32, destination: ["destination"], source: [], hasVisibleRows: true, last: true, bottomErrorPx: 0 },
    { observedAtMs: 48, destination: ["destination"], source: [], hasVisibleRows: true, last: true, bottomErrorPx: 0 },
    { observedAtMs: 64, destination: ["destination"], source: [], hasVisibleRows: true, last: true, bottomErrorPx: 0 },
  ])

  expect(result.firstCorrectObservedMs).toBe(32)
  expect(result.stableObservedMs).toBe(64)
})

test("reports missing correctness without throwing", () => {
  const result = classifySessionSwitch([
    {
      observedAtMs: 16,
      destination: ["destination"],
      source: ["source"],
      hasVisibleRows: true,
      last: true,
      bottomErrorPx: 0,
    },
  ])

  expect(result.firstDestinationObservedMs).toBe(16)
  expect(result.firstCorrectObservedMs).toBeNull()
  expect(result.stableObservedMs).toBeNull()
})

test("requires an explicitly tracked part to be visible", () => {
  const result = classifySessionSwitch([
    {
      observedAtMs: 16,
      destination: ["destination"],
      source: [],
      hasVisibleRows: true,
      last: true,
      requiredPartVisible: false,
      bottomErrorPx: 0,
    },
  ])

  expect(result.firstCorrectObservedMs).toBeNull()
})

test("can measure content correctness without requiring a bottom anchor", () => {
  const result = classifySessionSwitch([
    {
      observedAtMs: 16,
      destination: ["destination"],
      source: [],
      hasVisibleRows: true,
      last: true,
      requiredPartVisible: true,
      bottomAnchorRequired: false,
    },
  ])

  expect(result.firstCorrectObservedMs).toBe(16)
})