@@ -7,9 +7,13 @@ import {
7
7
MockAuditLogUnsuccessfulLoginUnknownUser ,
8
8
} from "testHelpers/entities"
9
9
import { AuditLogDescription } from "./AuditLogDescription"
10
- import { AuditLogRow } from "./AuditLogRow"
11
- import { render } from "../../ testHelpers/renderHelpers"
10
+ import { AuditLogRow } from ".. /AuditLogRow"
11
+ import { render } from "testHelpers/renderHelpers"
12
12
import { screen } from "@testing-library/react"
13
+ import { i18n } from "i18n"
14
+
15
+ const t = ( str : string , variables ?: Record < string , unknown > ) =>
16
+ i18n . t < string > ( str , variables )
13
17
14
18
const getByTextContent = ( text : string ) => {
15
19
return screen . getByText ( ( _ , element ) => {
@@ -25,17 +29,14 @@ describe("AuditLogDescription", () => {
25
29
it ( "renders the correct string for a workspace create audit log" , async ( ) => {
26
30
render ( < AuditLogDescription auditLog = { MockAuditLog } /> )
27
31
28
- expect (
29
- getByTextContent ( "TestUser created workspace bruno-dev" ) ,
30
- ) . toBeDefined ( )
32
+ expect ( screen . getByText ( "TestUser created workspace" ) ) . toBeDefined ( )
33
+ expect ( screen . getByText ( "bruno-dev" ) ) . toBeDefined ( )
31
34
} )
32
35
33
36
it ( "renders the correct string for a workspace_build stop audit log" , async ( ) => {
34
37
render ( < AuditLogDescription auditLog = { MockAuditLogWithWorkspaceBuild } /> )
35
38
36
- expect (
37
- getByTextContent ( "TestUser stopped build for workspace test2" ) ,
38
- ) . toBeDefined ( )
39
+ expect ( getByTextContent ( "TestUser stopped workspace test2" ) ) . toBeDefined ( )
39
40
} )
40
41
41
42
it ( "renders the correct string for a workspace_build audit log with a duplicate word" , async ( ) => {
@@ -48,7 +49,7 @@ describe("AuditLogDescription", () => {
48
49
render ( < AuditLogDescription auditLog = { AuditLogWithRepeat } /> )
49
50
50
51
expect (
51
- getByTextContent ( "TestUser stopped build for workspace workspace" ) ,
52
+ getByTextContent ( "TestUser stopped workspace workspace" ) ,
52
53
) . toBeDefined ( )
53
54
} )
54
55
it ( "renders the correct string for a workspace created for a different owner" , async ( ) => {
@@ -57,27 +58,68 @@ describe("AuditLogDescription", () => {
57
58
auditLog = { MockWorkspaceCreateAuditLogForDifferentOwner }
58
59
/> ,
59
60
)
61
+
60
62
expect (
61
- getByTextContent (
62
- `TestUser created workspace bruno-dev on behalf of ${ MockWorkspaceCreateAuditLogForDifferentOwner . additional_fields . workspace_owner } ` ,
63
+ screen . getByText (
64
+ `on behalf of ${ MockWorkspaceCreateAuditLogForDifferentOwner . additional_fields . workspace_owner } ` ,
65
+ { exact : false } ,
63
66
) ,
64
67
) . toBeDefined ( )
65
68
} )
66
69
it ( "renders the correct string for successful login" , async ( ) => {
67
70
render ( < AuditLogRow auditLog = { MockAuditLogSuccessfulLogin } /> )
68
- expect ( getByTextContent ( `TestUser logged in` ) ) . toBeDefined ( )
71
+
72
+ expect (
73
+ screen . getByText (
74
+ t ( "auditLog:table.logRow.description.unlinkedAuditDescription" , {
75
+ truncatedDescription : `${ MockAuditLogSuccessfulLogin . user ?. username } logged in` ,
76
+ target : "" ,
77
+ onBehalfOf : undefined ,
78
+ } )
79
+ . replace ( / < [ ^ > ] * > / g, " " )
80
+ . replace ( / \s { 2 , } / g, " " )
81
+ . trim ( ) ,
82
+ ) ,
83
+ ) . toBeInTheDocument ( )
84
+
69
85
const statusPill = screen . getByRole ( "status" )
70
86
expect ( statusPill ) . toHaveTextContent ( "201" )
71
87
} )
72
88
it ( "renders the correct string for unsuccessful login for a known user" , async ( ) => {
73
89
render ( < AuditLogRow auditLog = { MockAuditLogUnsuccessfulLoginKnownUser } /> )
74
- expect ( getByTextContent ( `TestUser logged in` ) ) . toBeDefined ( )
90
+
91
+ expect (
92
+ screen . getByText (
93
+ t ( "auditLog:table.logRow.description.unlinkedAuditDescription" , {
94
+ truncatedDescription : `${ MockAuditLogUnsuccessfulLoginKnownUser . user ?. username } logged in` ,
95
+ target : "" ,
96
+ onBehalfOf : undefined ,
97
+ } )
98
+ . replace ( / < [ ^ > ] * > / g, " " )
99
+ . replace ( / \s { 2 , } / g, " " )
100
+ . trim ( ) ,
101
+ ) ,
102
+ ) . toBeInTheDocument ( )
103
+
75
104
const statusPill = screen . getByRole ( "status" )
76
105
expect ( statusPill ) . toHaveTextContent ( "401" )
77
106
} )
78
107
it ( "renders the correct string for unsuccessful login for an unknown user" , async ( ) => {
79
108
render ( < AuditLogRow auditLog = { MockAuditLogUnsuccessfulLoginUnknownUser } /> )
80
- expect ( getByTextContent ( `an unknown user logged in` ) ) . toBeDefined ( )
109
+
110
+ expect (
111
+ screen . getByText (
112
+ t ( "auditLog:table.logRow.description.unlinkedAuditDescription" , {
113
+ truncatedDescription : "an unknown user logged in" ,
114
+ target : "" ,
115
+ onBehalfOf : undefined ,
116
+ } )
117
+ . replace ( / < [ ^ > ] * > / g, " " )
118
+ . replace ( / \s { 2 , } / g, " " )
119
+ . trim ( ) ,
120
+ ) ,
121
+ ) . toBeInTheDocument ( )
122
+
81
123
const statusPill = screen . getByRole ( "status" )
82
124
expect ( statusPill ) . toHaveTextContent ( "401" )
83
125
} )
0 commit comments