@@ -1,21 +1,25 @@
1module Test.Main where
1module Test.Main where
3−import Control.Monad.Error.Class (try)
4import Data.Either (isLeft)
3import Data.Either (isLeft)
5import Data.Maybe (Maybe(..))
4import Data.Maybe (Maybe(..))
6import Effect (Effect)
5import Effect (Effect)
6+import Effect.Aff (launchAff_, try)
7import Effect.Class (liftEffect)
7import Effect.Class (liftEffect)
8import Effect.Ref as Ref
8import Effect.Ref as Ref
9+import Node.Encoding as Encoding
9import Node.FS.Aff as FS
10import Node.FS.Aff as FS
11+import Node.Stream as Stream
10import Playwright
12import Playwright
11import Playwright.ConsoleMessage as ConsoleMessage
13import Playwright.ConsoleMessage as ConsoleMessage
12−import Playwright.Event as Event
14+import Playwright.Dialog as Dialog
15+import Playwright.Download as Download
13import Playwright.Event (on)
16import Playwright.Event (on)
14−import Prelude (Unit, bind, discard, void, ($), (/=), (<>), (=<<))
17+import Playwright.Event as Event
15import Test.Unit (suite, test)
19import Test.Unit (suite, test)
16import Test.Unit.Assert as Assert
20import Test.Unit.Assert as Assert
17import Test.Unit.Main (runTest)
21import Test.Unit.Main (runTest)
18−import TestUtils (cwd, testClickEvent, withBrowser, withBrowserPage)
22+import TestUtils (cwd, isNull, testClickEvent, withBrowser, withBrowserPage)
19import Untagged.Union (fromOneOf)
23import Untagged.Union (fromOneOf)
21static :: String -> URL
25static :: String -> URL
@@ -110,3 +114,47 @@ main = runTest do
111 realType <- liftEffect $ Ref.read typeRef
115 realType <- liftEffect $ Ref.read typeRef
112 Assert.equal (Just ConsoleMessage.Debug) realType
116 Assert.equal (Just ConsoleMessage.Debug) realType
118+ withBrowserPage hello
120+ downloadRef <- liftEffect $ Ref.new Nothing
121+ liftEffect $ on Event.download page $ \download -> launchAff_ do
122+ fname <- liftEffect $ Download.suggestedFilename download
123+ Assert.equal "hello.txt" fname
124+ mbStream <- Download.createReadStream download
125+ failureStatus <- Download.failure download
126+ Assert.equal true (isNull failureStatus)
128+ Nothing -> Assert.assert "Unable to get stream" false
130+ liftEffect $ Stream.onDataString stream Encoding.UTF8 $ \string -> do
131+ Ref.write (Just string) downloadRef
132+ void $ evaluate page
134+ function download(filename, text) {
135+ var element = document.createElement('a');
136+ element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
137+ element.setAttribute('download', filename);
138+ document.body.appendChild(element);
140+ document.body.removeChild(element);
142+ download("hello.txt","hiiii");
144+ waitForTimeout page 100
145+ downloadContent <- liftEffect $ Ref.read downloadRef
146+ Assert.equal (Just "hiiii") downloadContent
148+ withBrowserPage hello
150+ downloadRef <- liftEffect $ Ref.new Nothing
151+ liftEffect $ on Event.dialog page $ \dialog -> launchAff_ do
152+ defaultValue <- liftEffect $ Dialog.defaultValue dialog
153+ Assert.equal "hello" defaultValue
154+ message <- liftEffect $ Dialog.message dialog
155+ Assert.equal "hi" message
156+ Dialog.dismiss dialog
157+ void $ evaluate page
159+ prompt("hi", "hello");