Delete assets/js/dashboard/stats/metrics.test.ts with huggingface_hub
Browse files
assets/js/dashboard/stats/metrics.test.ts
DELETED
|
@@ -1,261 +0,0 @@
|
|
| 1 |
-
import {
|
| 2 |
-
isSortable,
|
| 3 |
-
getMetricLabel,
|
| 4 |
-
getBreakdownMetricLabel,
|
| 5 |
-
Metric
|
| 6 |
-
} from './metrics'
|
| 7 |
-
|
| 8 |
-
describe(`${isSortable.name}`, () => {
|
| 9 |
-
it('returns false for total_visitors', () => {
|
| 10 |
-
expect(isSortable('total_visitors')).toBe(false)
|
| 11 |
-
})
|
| 12 |
-
|
| 13 |
-
const sortableMetrics: Metric[] = [
|
| 14 |
-
'visitors',
|
| 15 |
-
'visits',
|
| 16 |
-
'pageviews',
|
| 17 |
-
'views_per_visit',
|
| 18 |
-
'bounce_rate',
|
| 19 |
-
'visit_duration',
|
| 20 |
-
'events',
|
| 21 |
-
'percentage',
|
| 22 |
-
'conversion_rate',
|
| 23 |
-
'group_conversion_rate',
|
| 24 |
-
'time_on_page',
|
| 25 |
-
'total_revenue',
|
| 26 |
-
'average_revenue',
|
| 27 |
-
'scroll_depth',
|
| 28 |
-
'exit_rate'
|
| 29 |
-
]
|
| 30 |
-
|
| 31 |
-
it.each(sortableMetrics)('returns true for %s', (metric) => {
|
| 32 |
-
expect(isSortable(metric)).toBe(true)
|
| 33 |
-
})
|
| 34 |
-
})
|
| 35 |
-
|
| 36 |
-
describe(`${getMetricLabel.name}`, () => {
|
| 37 |
-
it.each([
|
| 38 |
-
['visitors', false, 'Unique visitors'],
|
| 39 |
-
['visitors', true, 'Unique conversions'],
|
| 40 |
-
['events', false, 'Total events'],
|
| 41 |
-
['events', true, 'Total conversions'],
|
| 42 |
-
['visits', false, 'Total visits'],
|
| 43 |
-
['pageviews', false, 'Total pageviews'],
|
| 44 |
-
['views_per_visit', false, 'Views per visit'],
|
| 45 |
-
['bounce_rate', false, 'Bounce rate'],
|
| 46 |
-
['visit_duration', false, 'Visit duration'],
|
| 47 |
-
['time_on_page', false, 'Time on page'],
|
| 48 |
-
['scroll_depth', false, 'Scroll depth'],
|
| 49 |
-
['conversion_rate', false, 'Conversion rate'],
|
| 50 |
-
['total_revenue', false, 'Total revenue'],
|
| 51 |
-
['average_revenue', false, 'Average revenue'],
|
| 52 |
-
['percentage', false, 'Percentage'],
|
| 53 |
-
['group_conversion_rate', false, 'Conversion rate'],
|
| 54 |
-
['total_visitors', false, 'Total visitors'],
|
| 55 |
-
['exit_rate', false, 'Exit rate']
|
| 56 |
-
] as const)(
|
| 57 |
-
'%s (hasConversionGoalFilter=%s) -> %s',
|
| 58 |
-
(metric, hasConversionGoalFilter, expected) => {
|
| 59 |
-
expect(getMetricLabel(metric, { hasConversionGoalFilter })).toBe(expected)
|
| 60 |
-
}
|
| 61 |
-
)
|
| 62 |
-
})
|
| 63 |
-
|
| 64 |
-
describe(`${getBreakdownMetricLabel.name}`, () => {
|
| 65 |
-
const defaults = { hasConversionGoalFilter: false, isRealtime: false }
|
| 66 |
-
|
| 67 |
-
describe('entry page dimension', () => {
|
| 68 |
-
const dimension = 'visit:entry_page'
|
| 69 |
-
|
| 70 |
-
it('returns Unique entrances for visitors (no goal, not realtime)', () => {
|
| 71 |
-
expect(
|
| 72 |
-
getBreakdownMetricLabel('visitors', {
|
| 73 |
-
...defaults,
|
| 74 |
-
dimensions: [dimension]
|
| 75 |
-
})
|
| 76 |
-
).toBe('Unique entrances')
|
| 77 |
-
})
|
| 78 |
-
|
| 79 |
-
it('returns Total entrances for visits (no goal, not realtime)', () => {
|
| 80 |
-
expect(
|
| 81 |
-
getBreakdownMetricLabel('visits', {
|
| 82 |
-
...defaults,
|
| 83 |
-
dimensions: [dimension]
|
| 84 |
-
})
|
| 85 |
-
).toBe('Total entrances')
|
| 86 |
-
})
|
| 87 |
-
|
| 88 |
-
it('falls back to default label for visitors with conversion goal', () => {
|
| 89 |
-
expect(
|
| 90 |
-
getBreakdownMetricLabel('visitors', {
|
| 91 |
-
hasConversionGoalFilter: true,
|
| 92 |
-
isRealtime: false,
|
| 93 |
-
dimensions: [dimension]
|
| 94 |
-
})
|
| 95 |
-
).toBe('Conversions')
|
| 96 |
-
})
|
| 97 |
-
|
| 98 |
-
it('falls back to default label for visitors in realtime', () => {
|
| 99 |
-
expect(
|
| 100 |
-
getBreakdownMetricLabel('visitors', {
|
| 101 |
-
hasConversionGoalFilter: false,
|
| 102 |
-
isRealtime: true,
|
| 103 |
-
dimensions: [dimension]
|
| 104 |
-
})
|
| 105 |
-
).toBe('Current visitors')
|
| 106 |
-
})
|
| 107 |
-
|
| 108 |
-
it('falls back to default label for other metrics', () => {
|
| 109 |
-
expect(
|
| 110 |
-
getBreakdownMetricLabel('bounce_rate', {
|
| 111 |
-
...defaults,
|
| 112 |
-
dimensions: [dimension]
|
| 113 |
-
})
|
| 114 |
-
).toBe('Bounce rate')
|
| 115 |
-
})
|
| 116 |
-
})
|
| 117 |
-
|
| 118 |
-
describe('exit page dimension', () => {
|
| 119 |
-
const dimension = 'visit:exit_page'
|
| 120 |
-
|
| 121 |
-
it('returns Unique exits for visitors (no goal, not realtime)', () => {
|
| 122 |
-
expect(
|
| 123 |
-
getBreakdownMetricLabel('visitors', {
|
| 124 |
-
...defaults,
|
| 125 |
-
dimensions: [dimension]
|
| 126 |
-
})
|
| 127 |
-
).toBe('Unique exits')
|
| 128 |
-
})
|
| 129 |
-
|
| 130 |
-
it('returns Total exits for visits (no goal, not realtime)', () => {
|
| 131 |
-
expect(
|
| 132 |
-
getBreakdownMetricLabel('visits', {
|
| 133 |
-
...defaults,
|
| 134 |
-
dimensions: [dimension]
|
| 135 |
-
})
|
| 136 |
-
).toBe('Total exits')
|
| 137 |
-
})
|
| 138 |
-
|
| 139 |
-
it('falls back to default label for visitors with conversion goal', () => {
|
| 140 |
-
expect(
|
| 141 |
-
getBreakdownMetricLabel('visitors', {
|
| 142 |
-
hasConversionGoalFilter: true,
|
| 143 |
-
isRealtime: false,
|
| 144 |
-
dimensions: [dimension]
|
| 145 |
-
})
|
| 146 |
-
).toBe('Conversions')
|
| 147 |
-
})
|
| 148 |
-
|
| 149 |
-
it('falls back to default label for visitors in realtime', () => {
|
| 150 |
-
expect(
|
| 151 |
-
getBreakdownMetricLabel('visitors', {
|
| 152 |
-
hasConversionGoalFilter: false,
|
| 153 |
-
isRealtime: true,
|
| 154 |
-
dimensions: [dimension]
|
| 155 |
-
})
|
| 156 |
-
).toBe('Current visitors')
|
| 157 |
-
})
|
| 158 |
-
|
| 159 |
-
it('falls back to default label for other metrics', () => {
|
| 160 |
-
expect(
|
| 161 |
-
getBreakdownMetricLabel('exit_rate', {
|
| 162 |
-
...defaults,
|
| 163 |
-
dimensions: [dimension]
|
| 164 |
-
})
|
| 165 |
-
).toBe('Exit rate')
|
| 166 |
-
})
|
| 167 |
-
})
|
| 168 |
-
|
| 169 |
-
describe('goal dimension', () => {
|
| 170 |
-
const dimension = 'event:goal'
|
| 171 |
-
|
| 172 |
-
it('returns Uniques for visitors', () => {
|
| 173 |
-
expect(
|
| 174 |
-
getBreakdownMetricLabel('visitors', {
|
| 175 |
-
...defaults,
|
| 176 |
-
dimensions: [dimension]
|
| 177 |
-
})
|
| 178 |
-
).toBe('Uniques')
|
| 179 |
-
})
|
| 180 |
-
|
| 181 |
-
it('returns Total for events', () => {
|
| 182 |
-
expect(
|
| 183 |
-
getBreakdownMetricLabel('events', {
|
| 184 |
-
...defaults,
|
| 185 |
-
dimensions: [dimension]
|
| 186 |
-
})
|
| 187 |
-
).toBe('Total')
|
| 188 |
-
})
|
| 189 |
-
|
| 190 |
-
it('returns CR for conversion_rate', () => {
|
| 191 |
-
expect(
|
| 192 |
-
getBreakdownMetricLabel('conversion_rate', {
|
| 193 |
-
...defaults,
|
| 194 |
-
dimensions: [dimension]
|
| 195 |
-
})
|
| 196 |
-
).toBe('CR')
|
| 197 |
-
})
|
| 198 |
-
|
| 199 |
-
it('falls back to default label for other metrics', () => {
|
| 200 |
-
expect(
|
| 201 |
-
getBreakdownMetricLabel('bounce_rate', {
|
| 202 |
-
...defaults,
|
| 203 |
-
dimensions: [dimension]
|
| 204 |
-
})
|
| 205 |
-
).toBe('Bounce rate')
|
| 206 |
-
})
|
| 207 |
-
})
|
| 208 |
-
|
| 209 |
-
describe('any other session dimension', () => {
|
| 210 |
-
const dimensions = ['visit:source']
|
| 211 |
-
|
| 212 |
-
it('returns Visitors for visitors (no goal, not realtime)', () => {
|
| 213 |
-
expect(
|
| 214 |
-
getBreakdownMetricLabel('visitors', { ...defaults, dimensions })
|
| 215 |
-
).toBe('Visitors')
|
| 216 |
-
})
|
| 217 |
-
|
| 218 |
-
it('returns Conversions for visitors with conversion goal', () => {
|
| 219 |
-
expect(
|
| 220 |
-
getBreakdownMetricLabel('visitors', {
|
| 221 |
-
hasConversionGoalFilter: true,
|
| 222 |
-
isRealtime: false,
|
| 223 |
-
dimensions
|
| 224 |
-
})
|
| 225 |
-
).toBe('Conversions')
|
| 226 |
-
})
|
| 227 |
-
|
| 228 |
-
it('returns Current visitors for visitors in realtime', () => {
|
| 229 |
-
expect(
|
| 230 |
-
getBreakdownMetricLabel('visitors', {
|
| 231 |
-
hasConversionGoalFilter: false,
|
| 232 |
-
isRealtime: true,
|
| 233 |
-
dimensions
|
| 234 |
-
})
|
| 235 |
-
).toBe('Current visitors')
|
| 236 |
-
})
|
| 237 |
-
|
| 238 |
-
it.each([
|
| 239 |
-
['group_conversion_rate', 'CR'],
|
| 240 |
-
['conversion_rate', 'CR'],
|
| 241 |
-
['pageviews', 'Pageviews'],
|
| 242 |
-
['average_revenue', 'Average'],
|
| 243 |
-
['total_revenue', 'Revenue']
|
| 244 |
-
] as const)('%s -> %s', (metric, expected) => {
|
| 245 |
-
expect(getBreakdownMetricLabel(metric, { ...defaults, dimensions })).toBe(
|
| 246 |
-
expected
|
| 247 |
-
)
|
| 248 |
-
})
|
| 249 |
-
|
| 250 |
-
it.each([
|
| 251 |
-
'visits',
|
| 252 |
-
'views_per_visit',
|
| 253 |
-
'bounce_rate',
|
| 254 |
-
'visit_duration'
|
| 255 |
-
] as const)('delegates to getMetricLabel for %s', (metric) => {
|
| 256 |
-
expect(getBreakdownMetricLabel(metric, { ...defaults, dimensions })).toBe(
|
| 257 |
-
getMetricLabel(metric, defaults)
|
| 258 |
-
)
|
| 259 |
-
})
|
| 260 |
-
})
|
| 261 |
-
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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