@@ -1,183 +1,183 @@
11module Test.Main where
22
3−import Control.Monad.Except (runExcept)
4−import Data.Either (isLeft)
5−import Data.Maybe (Maybe(..))
6−import Effect (Effect)
7−import Effect.Aff (launchAff_, try)
8−import Effect.Class (liftEffect)
9−import Effect.Console as Console
10−import Effect.Ref as Ref
11−import Foreign as Foreign
12−import Node.Encoding as Encoding
13−import Node.FS.Aff as FS
14−import Node.Stream as Stream
15−import Playwright
16−import Playwright.ConsoleMessage as ConsoleMessage
17−import Playwright.Dialog as Dialog
18−import Playwright.Download as Download
19−import Playwright.Event (on)
20−import Playwright.Event as Event
21−import Prelude
22−import Test.Unit (suite, test)
23−import Test.Unit.Assert as Assert
24−import Test.Unit.Main (runTest)
25−import TestUtils (cwd, isNull, testClickEvent, withBrowser, withBrowserPage)
26−import Untagged.Union (fromOneOf)
3+-- import Control.Monad.Except (runExcept)
4+-- import Data.Either (isLeft)
5+-- import Data.Maybe (Maybe(..))
6+-- import Effect (Effect)
7+-- import Effect.Aff (launchAff_, try)
8+-- import Effect.Class (liftEffect)
9+-- import Effect.Console as Console
10+-- import Effect.Ref as Ref
11+-- import Foreign as Foreign
12+-- import Node.Encoding as Encoding
13+-- import Node.FS.Aff as FS
14+-- import Node.Stream as Stream
15+-- import Playwright
16+-- import Playwright.ConsoleMessage as ConsoleMessage
17+-- import Playwright.Dialog as Dialog
18+-- import Playwright.Download as Download
19+-- import Playwright.Event (on)
20+-- import Playwright.Event as Event
21+-- import Prelude
22+-- import Test.Unit (suite, test)
23+-- import Test.Unit.Assert as Assert
24+-- import Test.Unit.Main (runTest)
25+-- import TestUtils (cwd, isNull, testClickEvent, withBrowser, withBrowserPage)
26+-- import Untagged.Union (fromOneOf)
2727
28−static :: String -> URL
29−static file =
30− URL $ "file://" <> cwd <> "/test/static/" <> file
28+-- static :: String -> URL
29+-- static file =
30+-- URL $ "file://" <> cwd <> "/test/static/" <> file
3131
32−main :: Effect Unit
33−main = runTest do
34− let
35− hello = static "hello.html"
36− index = static "index.html"
37− suite "browser" do
38− test "launch, close" do
39− browser <- launch chromium {}
40− close browser
41− test "close/isClosed" do
42− withBrowserPage hello
43− \page -> do
44− Assert.assertFalse "new page is closed" =<<
45− liftEffect (isClosed page)
46− close page
47− Assert.assert "page is not closed" =<< liftEffect (isClosed page)
48− test "version" do
49− withBrowser
50− \browser -> do
51− v <- liftEffect $ version browser
52− Assert.assert "version is empty" (v /= "")
53− test "url" do
54− withBrowserPage hello
55− \page -> do
56− Assert.equal hello =<< liftEffect (url page)
57− test "screenshot" do
58− withBrowserPage hello
59− \page -> do
60− void $ screenshot page { path: "screenshot.png" }
61− FS.unlink "screenshot.png"
62− test "textContent" do
63− withBrowserPage hello
64− \page -> do
65− text <- textContent page (Selector "body")
66− Assert.equal (Just "hello\n") (fromOneOf text)
67− test "mainFrame" do
68− withBrowserPage hello
69− \page -> do
70− frame <- liftEffect $ mainFrame page
71− frameName <- liftEffect $ name frame
72− Assert.equal "" frameName
73− test "click" do
74− withBrowserPage index $ testClickEvent "click" click
75− test "dblclick" do
76− withBrowserPage index $ testClickEvent "dblclick" dblclick
77− test "waitForSelector" do
78− withBrowserPage hello
79− \page -> do
80− void $ waitForSelector page (Selector "body") {}
81− res <- try $ waitForSelector page (Selector "nonexistent") { timeout: 100 }
82− Assert.assert "waitForSelector fails when no element" $
83− isLeft res
84− test "waitForFunction" do
85− withBrowserPage hello
86− \page -> do
87− void $ evaluate page
88− "setTimeout(() => document.body.textContent += 'uniqstring', 1)"
89− void $ waitForFunction
90− page
91− "document.body.textContent.includes('uniqstring')"
92− { timeout: 5000, polling: 100 }
93− suite "FFI" do
94− test "exposeBinding" do
95− withBrowserPage hello \page -> do
96− ref <- liftEffect $ Ref.new Nothing
97− frgnRef <- liftEffect $ Ref.new Nothing
98− exposeBinding page "hi_ffi"
99− (
100− \({frame}) frgn -> do
101− url <- liftEffect $ url frame
102− liftEffect do
103− Console.log "hi"
104− Ref.write (Just frgn) frgnRef
105− Ref.write (Just url) ref
106− )
107− void $ evaluate page "hi_ffi(12);"
108− waitForTimeout page 100
109− mbUrl <- liftEffect $ Ref.read ref
110− mbForeign <- liftEffect $ Ref.read frgnRef
111− Assert.equal (Just hello) mbUrl
112− Assert.assert "exposeBinding is not able to accept an argument" $
113− pure (pure 12) == (runExcept <<< Foreign.readInt <$> mbForeign)
114− suite "events" do
115− test "console" do
116− withBrowserPage hello
117− \page -> do
118− messageRef <- liftEffect $ Ref.new Nothing
119− liftEffect $ on Event.console page $ \cslMessage -> do
120− realMessage <- ConsoleMessage.text cslMessage
121− Ref.write (Just realMessage) messageRef
122− void $ evaluate page
123− """
124− console.log('hi');
125− """
126− realMessage <- liftEffect $ Ref.read messageRef
127− Assert.equal (Just "hi") realMessage
128− test "console: ConsoleMessageType" do
129− withBrowserPage hello
130− \page -> do
131− typeRef <- liftEffect $ Ref.new Nothing
132− liftEffect $ on Event.console page $ \cslMessage -> do
133− realType <- ConsoleMessage.type' cslMessage
134− Ref.write (Just realType) typeRef
135− void $ evaluate page
136− """
137− console.debug('hi');
138− """
139− realType <- liftEffect $ Ref.read typeRef
140− Assert.equal (Just ConsoleMessage.Debug) realType
141− test "download" do
142− withBrowserPage hello
143− \page -> do
144− downloadRef <- liftEffect $ Ref.new Nothing
145− liftEffect $ on Event.download page $ \download -> launchAff_ do
146− fname <- liftEffect $ Download.suggestedFilename download
147− Assert.equal "hello.txt" fname
148− mbStream <- Download.createReadStream download
149− failureStatus <- Download.failure download
150− Assert.equal true (isNull failureStatus)
151− case mbStream of
152− Nothing -> Assert.assert "Unable to get stream" false
153− Just stream -> do
154− liftEffect $ Stream.onDataString stream Encoding.UTF8 $ \string -> do
155− Ref.write (Just string) downloadRef
156− void $ evaluate page
157− """
158− function download(filename, text) {
159− var element = document.createElement('a');
160− element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
161− element.setAttribute('download', filename);
162− document.body.appendChild(element);
163− element.click();
164− document.body.removeChild(element);
165− }
166− download("hello.txt","hiiii");
167− """
168− waitForTimeout page 100
169− downloadContent <- liftEffect $ Ref.read downloadRef
170− Assert.equal (Just "hiiii") downloadContent
171− test "dialog" do
172− withBrowserPage hello
173− \page -> do
174− liftEffect $ on Event.dialog page $ \dialog -> launchAff_ do
175− defaultValue <- liftEffect $ Dialog.defaultValue dialog
176− Assert.equal "hello" defaultValue
177− message <- liftEffect $ Dialog.message dialog
178− Assert.equal "hi" message
179− Dialog.dismiss dialog
180− void $ evaluate page
181− """
182− prompt("hi", "hello");
183− """
32+-- main :: Effect Unit
33+-- main = runTest do
34+-- let
35+-- hello = static "hello.html"
36+-- index = static "index.html"
37+-- suite "browser" do
38+-- test "launch, close" do
39+-- browser <- launch chromium {}
40+-- close browser
41+-- test "close/isClosed" do
42+-- withBrowserPage hello
43+-- \page -> do
44+-- Assert.assertFalse "new page is closed" =<<
45+-- liftEffect (isClosed page)
46+-- close page
47+-- Assert.assert "page is not closed" =<< liftEffect (isClosed page)
48+-- test "version" do
49+-- withBrowser
50+-- \browser -> do
51+-- v <- liftEffect $ version browser
52+-- Assert.assert "version is empty" (v /= "")
53+-- test "url" do
54+-- withBrowserPage hello
55+-- \page -> do
56+-- Assert.equal hello =<< liftEffect (url page)
57+-- test "screenshot" do
58+-- withBrowserPage hello
59+-- \page -> do
60+-- void $ screenshot page { path: "screenshot.png" }
61+-- FS.unlink "screenshot.png"
62+-- test "textContent" do
63+-- withBrowserPage hello
64+-- \page -> do
65+-- text <- textContent page (Selector "body")
66+-- Assert.equal (Just "hello\n") (fromOneOf text)
67+-- test "mainFrame" do
68+-- withBrowserPage hello
69+-- \page -> do
70+-- frame <- liftEffect $ mainFrame page
71+-- frameName <- liftEffect $ name frame
72+-- Assert.equal "" frameName
73+-- test "click" do
74+-- withBrowserPage index $ testClickEvent "click" click
75+-- test "dblclick" do
76+-- withBrowserPage index $ testClickEvent "dblclick" dblclick
77+-- test "waitForSelector" do
78+-- withBrowserPage hello
79+-- \page -> do
80+-- void $ waitForSelector page (Selector "body") {}
81+-- res <- try $ waitForSelector page (Selector "nonexistent") { timeout: 100 }
82+-- Assert.assert "waitForSelector fails when no element" $
83+-- isLeft res
84+-- test "waitForFunction" do
85+-- withBrowserPage hello
86+-- \page -> do
87+-- void $ evaluate page
88+-- "setTimeout(() => document.body.textContent += 'uniqstring', 1)"
89+-- void $ waitForFunction
90+-- page
91+-- "document.body.textContent.includes('uniqstring')"
92+-- { timeout: 5000, polling: 100 }
93+-- suite "FFI" do
94+-- test "exposeBinding" do
95+-- withBrowserPage hello \page -> do
96+-- ref <- liftEffect $ Ref.new Nothing
97+-- frgnRef <- liftEffect $ Ref.new Nothing
98+-- exposeBinding page "hi_ffi"
99+-- (
100+-- \({frame}) frgn -> do
101+-- url <- liftEffect $ url frame
102+-- liftEffect do
103+-- Console.log "hi"
104+-- Ref.write (Just frgn) frgnRef
105+-- Ref.write (Just url) ref
106+-- )
107+-- void $ evaluate page "hi_ffi(12);"
108+-- waitForTimeout page 100
109+-- mbUrl <- liftEffect $ Ref.read ref
110+-- mbForeign <- liftEffect $ Ref.read frgnRef
111+-- Assert.equal (Just hello) mbUrl
112+-- Assert.assert "exposeBinding is not able to accept an argument" $
113+-- pure (pure 12) == (runExcept <<< Foreign.readInt <$> mbForeign)
114+-- suite "events" do
115+-- test "console" do
116+-- withBrowserPage hello
117+-- \page -> do
118+-- messageRef <- liftEffect $ Ref.new Nothing
119+-- liftEffect $ on Event.console page $ \cslMessage -> do
120+-- realMessage <- ConsoleMessage.text cslMessage
121+-- Ref.write (Just realMessage) messageRef
122+-- void $ evaluate page
123+-- """
124+-- console.log('hi');
125+-- """
126+-- realMessage <- liftEffect $ Ref.read messageRef
127+-- Assert.equal (Just "hi") realMessage
128+-- test "console: ConsoleMessageType" do
129+-- withBrowserPage hello
130+-- \page -> do
131+-- typeRef <- liftEffect $ Ref.new Nothing
132+-- liftEffect $ on Event.console page $ \cslMessage -> do
133+-- realType <- ConsoleMessage.type' cslMessage
134+-- Ref.write (Just realType) typeRef
135+-- void $ evaluate page
136+-- """
137+-- console.debug('hi');
138+-- """
139+-- realType <- liftEffect $ Ref.read typeRef
140+-- Assert.equal (Just ConsoleMessage.Debug) realType
141+-- test "download" do
142+-- withBrowserPage hello
143+-- \page -> do
144+-- downloadRef <- liftEffect $ Ref.new Nothing
145+-- liftEffect $ on Event.download page $ \download -> launchAff_ do
146+-- fname <- liftEffect $ Download.suggestedFilename download
147+-- Assert.equal "hello.txt" fname
148+-- mbStream <- Download.createReadStream download
149+-- failureStatus <- Download.failure download
150+-- Assert.equal true (isNull failureStatus)
151+-- case mbStream of
152+-- Nothing -> Assert.assert "Unable to get stream" false
153+-- Just stream -> do
154+-- liftEffect $ Stream.onDataString stream Encoding.UTF8 $ \string -> do
155+-- Ref.write (Just string) downloadRef
156+-- void $ evaluate page
157+-- """
158+-- function download(filename, text) {
159+-- var element = document.createElement('a');
160+-- element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
161+-- element.setAttribute('download', filename);
162+-- document.body.appendChild(element);
163+-- element.click();
164+-- document.body.removeChild(element);
165+-- }
166+-- download("hello.txt","hiiii");
167+-- """
168+-- waitForTimeout page 100
169+-- downloadContent <- liftEffect $ Ref.read downloadRef
170+-- Assert.equal (Just "hiiii") downloadContent
171+-- test "dialog" do
172+-- withBrowserPage hello
173+-- \page -> do
174+-- liftEffect $ on Event.dialog page $ \dialog -> launchAff_ do
175+-- defaultValue <- liftEffect $ Dialog.defaultValue dialog
176+-- Assert.equal "hello" defaultValue
177+-- message <- liftEffect $ Dialog.message dialog
178+-- Assert.equal "hi" message
179+-- Dialog.dismiss dialog
180+-- void $ evaluate page
181+-- """
182+-- prompt("hi", "hello");
183+-- """