Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F3010255
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
getPort
from
"get-port"
;
import
{
Browser
,
Page
}
from
"playwright"
;
import
type
{
Context
}
from
"koa"
;
import
Koa
from
"koa"
;
import
{
mount
}
from
"../../mount.js"
;
import
{
Form
}
from
"../form.js"
;
import
{
getBrowser
}
from
"../../utils/browser-creator.js"
;
import
{
Controls
,
Fields
,
sleep
}
from
"../../index.js"
;
import
_locreq
from
"locreq"
;
import
{
module_dirname
}
from
"../../utils/module-dirname.js"
;
import
{
FileManager
,
PathFilePointer
}
from
"@sealcode/file-manager"
;
import
assert
from
"node:assert"
;
const
locreq
=
_locreq
(
module_dirname
(
import
.
meta
.
url
));
describe
(
"file-control"
,
()
=>
{
describe
(
"basic tests"
,
async
()
=>
{
let
server
:
ReturnType
<
Koa
[
"listen"
]
>
;
let
browser
:
Browser
;
let
page
:
Page
;
after
(()
=>
{
server
.
close
();
});
it
(
"doesn't require image input if it already has old-value"
,
async
()
=>
{
const
port
=
await
getPort
();
console
.
log
(
`Using port
${
port
}
for photo.test.ts`
);
const
app
=
new
Koa
();
const
router
=
new
Router
();
const
fields
=
{
file
:
new
Fields
.
File
(
true
,
new
FileManager
(
"/tmp"
,
"/uploaded_files"
)),
};
let
submit_called
=
false
;
mount
(
router
,
"/"
,
new
(
class
extends
Form
<
typeof
fields
,
unknown
>
{
fields
=
fields
;
controls
=
[
new
Controls
.
File
(
fields
.
file
)];
async
onSubmit
(
_ctx
:
Context
)
{
submit_called
=
true
;
}
async
getInitialValues
(
_ctx
:
Context
)
{
const
file
=
new
PathFilePointer
(
new
FileManager
(
"/tmp"
,
"/uploaded_files"
),
locreq
.
resolve
(
"assets/important.png"
)
);
return
{
file
:
await
file
.
save
(
false
),
// to get the token
};
}
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
();
let
screenshot
=
true
;
(
async
function
()
{
while
(
screenshot
)
{
await
page
.
screenshot
({
path
:
"/home/kuba/Downloads/"
+
Date
.
now
()
+
".png"
});
await
sleep
(
100
);
}
})();
await
page
.
goto
(
`http://localhost:
${
port
}
`
);
await
page
.
getByRole
(
"button"
,
{
name
:
"Wyślij"
}).
click
();
await
sleep
(
100
);
assert
(
submit_called
,
"Submit not called - something prevented submit on click?"
);
screenshot
=
false
;
});
}).
timeout
(
10000
);
});
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Wed, May 7, 19:38 (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
624929
Default Alt Text
file.test.ts (2 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment