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
37d20030
Commit
37d20030
authored
Aug 26, 2021
by
Enrique Alcantara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove waitForPromises in attachment_spec file
parent
509e4ffb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
45 deletions
+51
-45
spec/frontend/content_editor/extensions/attachment_spec.js
spec/frontend/content_editor/extensions/attachment_spec.js
+51
-45
No files found.
spec/frontend/content_editor/extensions/attachment_spec.js
View file @
37d20030
import
axios
from
'
axios
'
;
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
{
once
}
from
'
lodash
'
;
import
waitForPromises
from
'
helpers/wait_for_promises
'
;
import
Attachment
from
'
~/content_editor/extensions/attachment
'
;
import
Image
from
'
~/content_editor/extensions/image
'
;
import
Link
from
'
~/content_editor/extensions/link
'
;
...
...
@@ -12,7 +10,6 @@ import { createTestEditor, createDocBuilder } from '../test_utils';
describe
(
'
content_editor/extensions/attachment
'
,
()
=>
{
let
tiptapEditor
;
let
eq
;
let
doc
;
let
p
;
let
image
;
...
...
@@ -25,6 +22,24 @@ describe('content_editor/extensions/attachment', () => {
const
imageFile
=
new
File
([
'
foo
'
],
'
test-file.png
'
,
{
type
:
'
image/png
'
});
const
attachmentFile
=
new
File
([
'
foo
'
],
'
test-file.zip
'
,
{
type
:
'
application/zip
'
});
const
expectDocumentAfterTransaction
=
({
number
,
expectedDoc
,
action
})
=>
{
return
new
Promise
((
resolve
)
=>
{
let
counter
=
1
;
const
handleTransaction
=
()
=>
{
if
(
counter
===
number
)
{
expect
(
tiptapEditor
.
state
.
doc
.
toJSON
()).
toEqual
(
expectedDoc
.
toJSON
());
tiptapEditor
.
off
(
'
update
'
,
handleTransaction
);
resolve
();
}
counter
+=
1
;
};
tiptapEditor
.
on
(
'
update
'
,
handleTransaction
);
action
();
});
};
beforeEach
(()
=>
{
renderMarkdown
=
jest
.
fn
();
...
...
@@ -34,7 +49,6 @@ describe('content_editor/extensions/attachment', () => {
({
builders
:
{
doc
,
p
,
image
,
loading
,
link
},
eq
,
}
=
createDocBuilder
({
tiptapEditor
,
names
:
{
...
...
@@ -90,18 +104,14 @@ describe('content_editor/extensions/attachment', () => {
mock
.
onPost
().
reply
(
httpStatus
.
OK
,
successResponse
);
});
it
(
'
inserts an image with src set to the encoded image file and uploading true
'
,
(
done
)
=>
{
it
(
'
inserts an image with src set to the encoded image file and uploading true
'
,
async
(
)
=>
{
const
expectedDoc
=
doc
(
p
(
image
({
uploading
:
true
,
src
:
base64EncodedFile
})));
tiptapEditor
.
on
(
'
update
'
,
once
(()
=>
{
expect
(
eq
(
tiptapEditor
.
state
.
doc
,
expectedDoc
)).
toBe
(
true
);
done
();
}),
);
tiptapEditor
.
commands
.
uploadAttachment
({
file
:
imageFile
});
await
expectDocumentAfterTransaction
({
number
:
1
,
expectedDoc
,
action
:
()
=>
tiptapEditor
.
commands
.
uploadAttachment
({
file
:
imageFile
}),
});
});
it
(
'
updates the inserted image with canonicalSrc when upload is successful
'
,
async
()
=>
{
...
...
@@ -116,11 +126,11 @@ describe('content_editor/extensions/attachment', () => {
),
);
tiptapEditor
.
commands
.
uploadAttachment
({
file
:
imageFile
});
await
waitForPromises
();
expect
(
eq
(
tiptapEditor
.
state
.
doc
,
expectedDoc
)).
toBe
(
true
);
await
expectDocumentAfterTransaction
({
number
:
2
,
expectedDoc
,
action
:
()
=>
tiptapEditor
.
commands
.
uploadAttachment
({
file
:
imageFile
}),
}
);
});
});
...
...
@@ -129,14 +139,14 @@ describe('content_editor/extensions/attachment', () => {
mock
.
onPost
().
reply
(
httpStatus
.
INTERNAL_SERVER_ERROR
);
});
it
(
'
resets the doc to orginal state
'
,
async
()
=>
{
it
(
'
resets the doc to or
i
ginal state
'
,
async
()
=>
{
const
expectedDoc
=
doc
(
p
(
''
));
tiptapEditor
.
commands
.
uploadAttachment
({
file
:
imageFile
});
await
waitForPromises
();
expect
(
eq
(
tiptapEditor
.
state
.
doc
,
expectedDoc
)).
toBe
(
true
);
await
expectDocumentAfterTransaction
({
number
:
2
,
expectedDoc
,
action
:
()
=>
tiptapEditor
.
commands
.
uploadAttachment
({
file
:
imageFile
}),
}
);
});
it
(
'
emits an error event that includes an error message
'
,
(
done
)
=>
{
...
...
@@ -168,18 +178,14 @@ describe('content_editor/extensions/attachment', () => {
mock
.
onPost
().
reply
(
httpStatus
.
OK
,
successResponse
);
});
it
(
'
inserts a loading mark
'
,
(
done
)
=>
{
it
(
'
inserts a loading mark
'
,
async
(
)
=>
{
const
expectedDoc
=
doc
(
p
(
loading
({
label
:
'
test-file
'
})));
tiptapEditor
.
on
(
'
update
'
,
once
(()
=>
{
expect
(
eq
(
tiptapEditor
.
state
.
doc
,
expectedDoc
)).
toBe
(
true
);
done
();
}),
);
tiptapEditor
.
commands
.
uploadAttachment
({
file
:
attachmentFile
});
await
expectDocumentAfterTransaction
({
number
:
1
,
expectedDoc
,
action
:
()
=>
tiptapEditor
.
commands
.
uploadAttachment
({
file
:
attachmentFile
}),
});
});
it
(
'
updates the loading mark with a link with canonicalSrc and href attrs
'
,
async
()
=>
{
...
...
@@ -196,11 +202,11 @@ describe('content_editor/extensions/attachment', () => {
),
);
tiptapEditor
.
commands
.
uploadAttachment
({
file
:
attachmentFile
});
await
waitForPromises
();
expect
(
eq
(
tiptapEditor
.
state
.
doc
,
expectedDoc
)).
toBe
(
true
);
await
expectDocumentAfterTransaction
({
number
:
2
,
expectedDoc
,
action
:
()
=>
tiptapEditor
.
commands
.
uploadAttachment
({
file
:
attachmentFile
}),
}
);
});
});
...
...
@@ -212,11 +218,11 @@ describe('content_editor/extensions/attachment', () => {
it
(
'
resets the doc to orginal state
'
,
async
()
=>
{
const
expectedDoc
=
doc
(
p
(
''
));
tiptapEditor
.
commands
.
uploadAttachment
({
file
:
attachmentFile
});
await
waitForPromises
();
expect
(
eq
(
tiptapEditor
.
state
.
doc
,
expectedDoc
)).
toBe
(
true
);
await
expectDocumentAfterTransaction
({
number
:
2
,
expectedDoc
,
action
:
()
=>
tiptapEditor
.
commands
.
uploadAttachment
({
file
:
attachmentFile
}),
}
);
});
it
(
'
emits an error event that includes an error message
'
,
(
done
)
=>
{
...
...
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