Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ef8e0ab7
Commit
ef8e0ab7
authored
Mar 24, 2022
by
Paul Gascou-Vaillancourt
Committed by
Paul Gascou-Vaillancourt
Mar 25, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve initArkoseLabsScript spec
parent
73847e4e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
6 deletions
+15
-6
ee/spec/frontend/arkose_labs/init_arkose_labs_script_spec.js
ee/spec/frontend/arkose_labs/init_arkose_labs_script_spec.js
+15
-6
No files found.
ee/spec/frontend/arkose_labs/init_arkose_labs_script_spec.js
View file @
ef8e0ab7
import
{
initArkoseLabsScript
}
from
'
ee/arkose_labs/init_arkose_labs_script
'
;
import
{
initArkoseLabsScript
}
from
'
ee/arkose_labs/init_arkose_labs_script
'
;
jest
.
mock
(
'
lodash/uniqueId
'
,
()
=>
()
=>
'
initArkoseLabsScript_callback
'
);
jest
.
mock
(
'
lodash/uniqueId
'
,
()
=>
(
x
)
=>
`
${
x
}
7`
);
const
EXPECTED_CALLBACK_NAME
=
'
_initArkoseLabsScript_callback_7
'
;
const
TEST_PUBLIC_KEY
=
'
arkose-labs-public-api-key
'
;
describe
(
'
initArkoseLabsScript
'
,
()
=>
{
describe
(
'
initArkoseLabsScript
'
,
()
=>
{
let
subject
;
let
subject
;
const
initSubject
=
()
=>
{
const
initSubject
=
()
=>
{
subject
=
initArkoseLabsScript
({
publicKey
:
'
arkose-labs-public-api-key
'
});
subject
=
initArkoseLabsScript
({
publicKey
:
TEST_PUBLIC_KEY
});
};
};
const
findScriptTags
=
()
=>
document
.
querySelectorAll
(
'
script
'
);
const
findScriptTags
=
()
=>
document
.
querySelectorAll
(
'
script
'
);
...
@@ -19,7 +22,7 @@ describe('initArkoseLabsScript', () => {
...
@@ -19,7 +22,7 @@ describe('initArkoseLabsScript', () => {
it
(
'
sets a global enforcement callback
'
,
()
=>
{
it
(
'
sets a global enforcement callback
'
,
()
=>
{
initSubject
();
initSubject
();
expect
(
window
.
initArkoseLabsScript_callback
).
not
.
toBe
(
undefined
);
expect
(
window
[
EXPECTED_CALLBACK_NAME
]
).
not
.
toBe
(
undefined
);
});
});
it
(
'
adds ArkoseLabs scripts to the HTML head
'
,
()
=>
{
it
(
'
adds ArkoseLabs scripts to the HTML head
'
,
()
=>
{
...
@@ -27,15 +30,21 @@ describe('initArkoseLabsScript', () => {
...
@@ -27,15 +30,21 @@ describe('initArkoseLabsScript', () => {
initSubject
();
initSubject
();
expect
(
findScriptTags
()).
toHaveLength
(
1
);
const
scriptTag
=
findScriptTags
().
item
(
0
);
expect
(
scriptTag
.
getAttribute
(
'
type
'
)).
toBe
(
'
text/javascript
'
);
expect
(
scriptTag
.
getAttribute
(
'
src
'
)).
toBe
(
`https://client-api.arkoselabs.com/v2/
${
TEST_PUBLIC_KEY
}
/api.js`
,
);
expect
(
scriptTag
.
getAttribute
(
'
data-callback
'
)).
toBe
(
EXPECTED_CALLBACK_NAME
);
});
});
it
(
'
when callback is called, cleans up the global object and resolves the Promise
'
,
()
=>
{
it
(
'
when callback is called, cleans up the global object and resolves the Promise
'
,
()
=>
{
initSubject
();
initSubject
();
const
enforcement
=
'
ArkoseLabsEnforcement
'
;
const
enforcement
=
'
ArkoseLabsEnforcement
'
;
window
.
initArkoseLabsScript_callback
(
enforcement
);
window
[
EXPECTED_CALLBACK_NAME
]
(
enforcement
);
expect
(
window
.
initArkoseLabsScript_callback
).
toBe
(
undefined
);
expect
(
window
[
EXPECTED_CALLBACK_NAME
]
).
toBe
(
undefined
);
return
expect
(
subject
).
resolves
.
toBe
(
enforcement
);
return
expect
(
subject
).
resolves
.
toBe
(
enforcement
);
});
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment