Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F3010205
file.test.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
file.test.ts
View Options
import
Router
from
"@koa/router"
;
import
{
Context
}
from
"koa"
;
import
{
FileManager
,
FilePointer
}
from
"@sealcode/file-manager"
;
import
getPort
from
"get-port"
;
import
Koa
from
"koa"
;
import
fs
from
"node:fs/promises"
;
import
{
KoaResponsiveImageRouter
}
from
"koa-responsive-image-router"
;
import
{
mount
}
from
"../../mount.js"
;
import
{
Photo
}
from
"../controls/photo.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
.
log
(
`Using port http://localhost:
${
port
}
form file field test`
);
const
app
=
new
Koa
();
const
router
=
new
Router
();
const
fields
=
{
file
:
new
FileField
(
true
,
new
FileManager
(
"/tmp"
,
"/uploaded_files"
)),
};
let
received_values
:
any
;
mount
(
router
,
"/"
,
new
(
class
extends
Form
<
typeof
fields
,
unknown
>
{
fields
=
fields
;
controls
=
[
new
Photo
(
fields
.
file
,
new
KoaResponsiveImageRouter
({
staticPath
:
"/tmp"
,
thumbnailSize
:
10
,
cacheManagerResolutionThreshold
:
10
,
imageStoragePath
:
"/tmp"
,
smartCropStoragePath
:
"/tmp"
,
})
),
];
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
text/x-java
Expires
Wed, May 7, 19:38 (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
624949
Default Alt Text
file.test.ts (2 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment