Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F996356
photo.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
photo.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
{
Fields
}
from
"../../index.js"
;
import
{
Photo
}
from
"./photo.js"
;
import
{
KoaResponsiveImageRouter
}
from
"koa-responsive-image-router"
;
import
_locreq
from
"locreq"
;
import
{
module_dirname
}
from
"../../utils/module-dirname.js"
;
import
{
FileManager
,
PathFilePointer
}
from
"sealious"
;
const
locreq
=
_locreq
(
module_dirname
(
import
.
meta
.
url
));
describe
(
"photo-controll"
,
()
=>
{
describe
(
"basic tests"
,
async
()
=>
{
let
server
:
ReturnType
<
Koa
[
"listen"
]
>
;
let
browser
:
Browser
;
let
page
:
Page
;
afterAll
(()
=>
{
server
.
close
();
});
it
(
"sends the old photo if it wasn't changed and it has an initial 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
=
{
photo
:
new
Fields
.
File
(
false
,
new
FileManager
(
"/tmp"
)),
};
let
received_photo
:
unknown
;
const
imageRouter
=
new
KoaResponsiveImageRouter
({
staticPath
:
"/images"
,
thumbnailSize
:
20
,
cacheManagerResolutionThreshold
:
50
,
imageStoragePath
:
`/tmp/image-cache-
${
port
}
`
,
smartCropStoragePath
:
`/tmp/smartcrop-storage-
${
port
}
`
,
});
mount
(
router
,
"/"
,
new
(
class
extends
Form
<
typeof
fields
,
unknown
>
{
fields
=
fields
;
controls
=
[
new
Photo
(
fields
.
photo
,
imageRouter
)];
async
onSubmit
(
ctx
:
Context
)
{
console
.
log
(
"OnSubmit!"
);
const
data
=
await
this
.
getParsedValues
(
ctx
);
console
.
log
({
data
});
received_photo
=
data
.
photo
;
}
async
getInitialValues
(
ctx
:
Context
)
{
const
file
=
new
PathFilePointer
(
new
FileManager
(
"/tmp"
),
locreq
.
resolve
(
"assets/important.png"
)
);
return
{
photo
:
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
();
await
page
.
goto
(
`http://localhost:
${
port
}
`
);
await
page
.
getByRole
(
"button"
,
{
name
:
"Wyślij"
}).
click
();
console
.
log
({
received_photo
});
assert
(
received_photo
!==
undefined
&&
(
received_photo
as
any
).
old
!==
null
);
});
});
});
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Tue, Dec 24, 14:02 (17 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
557205
Default Alt Text
photo.test.ts (2 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment