Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22394572
image.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
3 KB
Referenced Files
None
Subscribers
None
image.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
{
Image
}
from
"./image.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
(
"photo-control"
,
()
=>
{
describe
(
"basic tests"
,
async
()
=>
{
let
server
:
ReturnType
<
Koa
[
"listen"
]
>
;
let
browser
:
Browser
;
let
page
:
Page
;
after
(()
=>
{
server
.
close
();
});
it
(
"sends the old photo if it wasn't changed and it has an initial value"
,
async
()
=>
{
const
port
=
await
getPort
();
console
.
info
(
`Using port
${
port
}
for photo.test.ts`
);
const
app
=
new
Koa
();
const
router
=
new
Router
();
const
fields
=
{
photo
:
new
Fields
.
File
(
false
),
};
let
received_photo
:
unknown
;
mount
(
router
,
"/"
,
new
(
class
extends
Form
<
typeof
fields
,
unknown
>
{
getFields
=
()
=>
fields
;
getControls
=
()
=>
[
new
Image
(
fields
.
photo
)];
async
onSubmit
(
ctx
:
Context
)
{
const
data
=
await
this
.
getParsedValues
(
ctx
);
received_photo
=
data
.
photo
;
}
async
getInitialValues
(
_ctx
:
Context
)
{
const
file
=
new
PathFilePointer
(
new
FileManager
(
"/tmp"
,
"/uploaded_files"
),
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
();
assert
(
received_photo
!==
undefined
&&
(
received_photo
as
any
).
old
!==
null
);
});
it
(
"doesn't require image input if it already has old-value"
,
async
()
=>
{
const
port
=
await
getPort
();
console
.
info
(
`Using port
${
port
}
for photo.test.ts`
);
const
app
=
new
Koa
();
const
router
=
new
Router
();
const
fields
=
{
photo
:
new
Fields
.
File
(
true
),
};
let
received_photo
:
unknown
;
let
submit_called
=
false
;
mount
(
router
,
"/"
,
new
(
class
extends
Form
<
typeof
fields
,
unknown
>
{
getFields
=
()
=>
fields
;
getControls
=
()
=>
[
new
Image
(
fields
.
photo
)];
async
onSubmit
(
ctx
:
Context
)
{
submit_called
=
true
;
const
data
=
await
this
.
getParsedValues
(
ctx
);
received_photo
=
data
.
photo
;
}
async
getInitialValues
(
_ctx
:
Context
)
{
const
file
=
new
PathFilePointer
(
new
FileManager
(
"/tmp"
,
"/uploaded_files"
),
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
();
assert
(
submit_called
,
"Submit not called - something prevented submit on click?"
);
});
}).
timeout
(
10000
);
});
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Fri, Nov 27, 16:18 (1 d, 17 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1201048
Default Alt Text
image.test.ts (3 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline