-
Notifications
You must be signed in to change notification settings - Fork 66.9k
Expand file tree
/
Copy pathrendering.ts
More file actions
100 lines (86 loc) · 4.21 KB
/
rendering.ts
File metadata and controls
100 lines (86 loc) · 4.21 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
import { describe, expect, test, vi } from 'vitest'
import { getDOM } from '@/tests/helpers/e2etest.js'
import { allVersions } from '@/versions/lib/all-versions'
import { getCategorizedAuditLogEvents } from '../lib'
describe('audit log events docs', () => {
vi.setConfig({ testTimeout: 60 * 1000 })
const auditLogEventPages = [
{
path: '/organizations/keeping-your-organization-secure/managing-security-settings-for-your-organization/audit-log-events-for-your-organization',
type: 'organization',
},
{
path: '/admin/monitoring-activity-in-your-enterprise/reviewing-audit-logs-for-your-enterprise/audit-log-events-for-your-enterprise',
type: 'enterprise',
},
{
path: '/authentication/keeping-your-account-and-data-secure/security-log-events',
type: 'user',
},
] as const
// This test ensures that the audit log event page components and Markdown
// file are in sync. Additionally, it checks all event categories are
// rendered and spot checks the events of one category are all rendered.
test.each(auditLogEventPages)(
'loads audit log event data for all versions on page %o',
async (page) => {
for (const version of Object.keys(allVersions)) {
// the enterprise events page has no FPT versioned audit log data
if (page.type === 'enterprise' && version === 'free-pro-team@latest') continue
const auditLogEvents = getCategorizedAuditLogEvents(page.type, version)
if (Object.keys(auditLogEvents).length === 0) {
console.warn(`There are no audit log events for ${page.path} with version '${version}'.`)
continue
}
// check that we get and render all the audit log event categories
// from the schema files
const auditLogCategories = Object.keys(auditLogEvents).map((category) => category)
const versionedAuditLogEventsPage = `/${version}${page.path}`
const $ = await getDOM(versionedAuditLogEventsPage)
const categoryH2Ids = $('h2')
.map((_, h2) => $(h2).attr('id'))
.get()
const categoryNames = categoryH2Ids.map((category) => category)
const everyAuditLogCategoryPresent = auditLogCategories.every((category) =>
categoryNames.includes(category),
)
expect(categoryH2Ids.length).toBeGreaterThan(0)
expect(everyAuditLogCategoryPresent).toBe(true)
// Spot check audit log event data by checking all the event actions under
// the workflows category which is available across all audit log event
// pages.
const workflowsEventActions = auditLogEvents.workflows.map((e) => e.action)
// each row corresponds to an audit log event, the format is:
//
// event action | event description
//
// we grab all the rendered workflow event action names and for our
// comparison we check that all the action names from the audit log
// schema data are included in the rendered action names.
const workflowsEventTRs = $('#workflows + table > tbody > tr').get()
const renderedWorkflowsEventActions = workflowsEventTRs.map((tr) => {
return $(tr.children[0]).text()
})
const everyWorkflowsEventActionPresent = workflowsEventActions.every((action) =>
renderedWorkflowsEventActions.includes(action),
)
expect(renderedWorkflowsEventActions.length).toBeGreaterThan(0)
expect(everyWorkflowsEventActionPresent).toBe(true)
}
},
)
test('audit log event pages have DOM markers needed for extracting search content', async () => {
// We just need to test one of the 3 audit log event pages because they all use the same component
// so we'll use the organization events page
const $ = await getDOM(
'/organizations/keeping-your-organization-secure/managing-security-settings-for-your-organization/audit-log-events-for-your-organization',
)
const rootSelector = '[data-search=article-body]'
const $root = $(rootSelector)
expect($root.length).toBe(1)
// on the audit log event pages the lead is separate from the article body
const leadSelector = '[data-search=lead] p'
const $lead = $(leadSelector)
expect($lead.length).toBe(1)
})
})