Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
29bd7b79
Commit
29bd7b79
authored
Jun 11, 2021
by
Lyza Danger Gardner
Committed by
Lyza Gardner
Jun 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace modal component in `prompts` with shared `ConfirmModal`
parent
be29e99a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
45 deletions
+23
-45
prompts.js
src/shared/prompts.js
+3
-3
prompts-test.js
src/shared/test/prompts-test.js
+20
-42
No files found.
src/shared/prompts.js
View file @
29bd7b79
import
{
render
}
from
'preact'
;
import
{
render
}
from
'preact'
;
import
ConfirmDialog
from
'./components/ConfirmDialog
'
;
import
{
ConfirmModal
}
from
'@hypothesis/frontend-shared
'
;
/**
/**
* Show the user a prompt asking them to confirm an action.
* Show the user a prompt asking them to confirm an action.
...
@@ -11,7 +11,7 @@ import ConfirmDialog from './components/ConfirmDialog';
...
@@ -11,7 +11,7 @@ import ConfirmDialog from './components/ConfirmDialog';
* for the native `window.confirm` dialog)
* for the native `window.confirm` dialog)
* - The visual style of the dialog matches the Hypothesis design system
* - The visual style of the dialog matches the Hypothesis design system
*
*
* @param {object} options - Options for the `Confirm
Dialog
`
* @param {object} options - Options for the `Confirm
Modal
`
* @prop {string} [title]
* @prop {string} [title]
* @prop {string} message
* @prop {string} message
* @prop {string} [confirmAction]
* @prop {string} [confirmAction]
...
@@ -52,7 +52,7 @@ export async function confirm({
...
@@ -52,7 +52,7 @@ export async function confirm({
};
};
render
(
render
(
<
Confirm
Dialog
<
Confirm
Modal
title
=
{
title
}
title
=
{
title
}
message
=
{
message
}
message
=
{
message
}
confirmAction
=
{
confirmAction
}
confirmAction
=
{
confirmAction
}
...
...
src/shared/test/prompts-test.js
View file @
29bd7b79
import
{
confirm
,
$imports
}
from
'../prompts'
;
import
{
confirm
}
from
'../prompts'
;
function
FakeConfirmDialog
({
confirmAction
,
message
,
onCancel
,
onConfirm
,
title
,
})
{
return
(
<
div
>
<
h1
>
{
title
}
<
/h1
>
<
p
>
{
message
}
<
/p
>
<
button
data
-
testid
=
"confirm"
onClick
=
{
onConfirm
}
>
{
confirmAction
}
<
/button
>
<
button
data
-
testid
=
"cancel"
onClick
=
{
onCancel
}
>
Cancel
<
/button
>
<
/div
>
);
}
describe
(
'shared/prompts'
,
()
=>
{
describe
(
'shared/prompts'
,
()
=>
{
describe
(
'confirm'
,
()
=>
{
describe
(
'confirm'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
// This will cause the custom ConfirmModal to be used instead of
// window.confirm
sinon
.
stub
(
window
,
'confirm'
).
returns
(
false
);
sinon
.
stub
(
window
,
'confirm'
).
returns
(
false
);
$imports
.
$mock
({
'./components/ConfirmDialog'
:
FakeConfirmDialog
,
});
});
});
afterEach
(()
=>
{
afterEach
(()
=>
{
window
.
confirm
.
restore
();
window
.
confirm
.
restore
();
});
});
function
getCustomDialog
()
{
function
clickClose
()
{
return
document
.
querySelector
(
'[data-testid="confirm-container"]'
);
const
closeButton
=
getCustomDialog
().
querySelector
(
'[aria-label="Close"]'
);
closeButton
.
click
();
}
function
clickCancel
()
{
const
cancelButton
=
getCustomDialog
().
querySelector
(
'[data-testid="cancel-button"]'
);
cancelButton
.
click
();
}
}
function
clickConfirm
()
{
function
clickConfirm
()
{
const
confirmButton
=
getCustomDialog
().
querySelector
(
const
confirmButton
=
getCustomDialog
().
querySelector
(
'[data-testid="confirm"]'
'[data-testid="confirm
-button
"]'
);
);
confirmButton
.
click
();
confirmButton
.
click
();
}
}
function
clickCancel
()
{
function
getCustomDialog
()
{
const
cancelButton
=
getCustomDialog
().
querySelector
(
return
document
.
querySelector
(
'[data-testid="confirm-container"]'
);
'[data-testid="cancel"]'
);
cancelButton
.
click
();
}
}
it
(
'uses `window.confirm` if available'
,
async
()
=>
{
it
(
'uses `window.confirm` if available'
,
async
()
=>
{
...
@@ -68,17 +52,11 @@ describe('shared/prompts', () => {
...
@@ -68,17 +52,11 @@ describe('shared/prompts', () => {
const
dialog
=
getCustomDialog
();
const
dialog
=
getCustomDialog
();
assert
.
ok
(
dialog
);
assert
.
ok
(
dialog
);
assert
.
equal
(
dialog
.
querySelector
(
'h1'
).
textContent
,
'Confirm action?'
);
assert
.
equal
(
dialog
.
querySelector
(
'p'
).
textContent
,
'Do the thing?'
);
assert
.
equal
(
dialog
.
querySelector
(
'[data-testid=confirm]'
).
textContent
,
'Yeah!'
);
clickConfirm
();
clickClose
();
await
result
;
assert
.
notOk
(
getCustomDialog
());
assert
.
notOk
(
getCustomDialog
());
assert
.
isFalse
(
await
result
);
});
});
it
(
'returns true if "Confirm" button is clicked'
,
async
()
=>
{
it
(
'returns true if "Confirm" button is clicked'
,
async
()
=>
{
...
...
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