Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22396646
file.test.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
file.test.ts
View Options
import
Router
from
"@koa/router"
;
import
{
Context
}
from
"koa"
;
import
{
FilePointer
}
from
"@sealcode/file-manager"
;
import
getPort
from
"get-port"
;
import
Koa
from
"koa"
;
import
fs
from
"node:fs/promises"
;
import
{
mount
}
from
"../../mount.js"
;
import
{
Image
}
from
"../controls/image.js"
;
import
{
Form
}
from
"../form.js"
;
import
{
File
as
FileField
}
from
"./file.js"
;
import
{
getBrowser
}
from
"../../utils/browser-creator.js"
;
import
assert
from
"node:assert"
;
import
{
Browser
,
Page
}
from
"playwright"
;
import
{
module_dirname
}
from
"../../utils/module-dirname.js"
;
import
_locreq
from
"locreq"
;
const
locreq
=
_locreq
(
module_dirname
(
import
.
meta
.
url
));
describe
(
"file field"
,
()
=>
{
let
server
:
ReturnType
<
Koa
[
"listen"
]
>
;
let
browser
:
Browser
;
let
page
:
Page
;
afterEach
(()
=>
{
server
.
close
();
});
it
(
"should handle as imple upload scenario"
,
async
()
=>
{
const
port
=
await
getPort
();
console
.
info
(
`Using port http://localhost:
${
port
}
form file field test`
);
const
app
=
new
Koa
();
const
router
=
new
Router
();
const
fields
=
{
file
:
new
FileField
(
true
),
};
let
received_values
:
any
;
mount
(
router
,
"/"
,
new
(
class
extends
Form
<
typeof
fields
,
unknown
>
{
getFields
=
()
=>
fields
;
getControls
=
()
=>
[
new
Image
(
fields
.
file
)];
async
onSubmit
(
ctx
:
Context
)
{
received_values
=
await
this
.
getParsedValues
(
ctx
);
}
async
canAccess
(
_
:
Context
)
{
return
{
canAccess
:
true
,
message
:
""
};
}
})(),
true
);
app
.
use
(
router
.
routes
()).
use
(
router
.
allowedMethods
());
server
=
app
.
listen
(
port
);
browser
=
await
getBrowser
();
const
context
=
await
browser
.
newContext
();
page
=
await
context
.
newPage
();
// await sleep(999999999);
await
page
.
goto
(
`http://localhost:
${
port
}
`
);
// await page.getByPlaceholder("file").click();
await
page
.
getByPlaceholder
(
"file"
).
setInputFiles
({
name
:
"important.png"
,
mimeType
:
"image/png"
,
buffer
:
await
fs
.
readFile
(
locreq
.
resolve
(
"assets/important.png"
)),
});
await
page
.
getByRole
(
"button"
,
{
name
:
"Wyślij"
}).
click
();
assert
.
ok
(
received_values
.
file
.
old
==
null
);
assert
.
ok
(
received_values
.
file
.
new
instanceof
FilePointer
);
}).
timeout
(
999999
);
});
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Fri, Nov 27, 16:54 (1 d, 22 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1200134
Default Alt Text
file.test.ts (2 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline