Преглед изворни кода

Slightly simplify test code

jherve пре 1 година
родитељ
комит
b0abd1b358

+ 2 - 0
src/LinkedIn/Output/Types.purs

@@ -21,6 +21,7 @@ data Output =
   | OutJobOffer JO.JobOffer
   | OutJobOffer JO.JobOffer
 
 
 derive instance Generic Output _
 derive instance Generic Output _
+derive instance Eq Output
 instance Show Output where
 instance Show Output where
   show = genericShow
   show = genericShow
 instance EncodeJson Output where
 instance EncodeJson Output where
@@ -34,6 +35,7 @@ data OutputError =
   | ErrorUrlNotSupported PageUrl
   | ErrorUrlNotSupported PageUrl
 
 
 derive instance Generic OutputError _
 derive instance Generic OutputError _
+derive instance Eq OutputError
 instance Show OutputError where
 instance Show OutputError where
   show = genericShow
   show = genericShow
 instance EncodeJson OutputError where
 instance EncodeJson OutputError where

+ 1 - 0
src/LinkedIn/Profile/Project.purs

@@ -21,6 +21,7 @@ data Project = Project {
 }
 }
 
 
 derive instance Generic Project _
 derive instance Generic Project _
+derive instance Eq Project
 instance Show Project where
 instance Show Project where
   show = genericShow
   show = genericShow
 instance EncodeJson Project where
 instance EncodeJson Project where

+ 1 - 0
src/LinkedIn/Profile/Skill.purs

@@ -17,6 +17,7 @@ data Skill = Skill {
 }
 }
 
 
 derive instance Generic Skill _
 derive instance Generic Skill _
+derive instance Eq Skill
 instance Show Skill where
 instance Show Skill where
   show = genericShow
   show = genericShow
 instance EncodeJson Skill where
 instance EncodeJson Skill where

Разлика између датотеке није приказан због своје велике величине
+ 58 - 61
test/ArtDecoCard.purs


+ 16 - 25
test/JobsUnifiedTopCard.purs

@@ -2,42 +2,33 @@ module Test.JobsUnifiedTopCard where
 
 
 import Prelude
 import Prelude
 
 
-import Data.Either (Either(..), hush, isRight)
+import Control.Monad.Except (runExceptT)
+import Data.Either (Either(..))
 import Data.List (List(..), (:))
 import Data.List (List(..), (:))
 import Data.List.NonEmpty (NonEmptyList(..))
 import Data.List.NonEmpty (NonEmptyList(..))
-import Data.Maybe (Maybe(..), fromJust)
+import Data.Maybe (Maybe(..))
 import Data.NonEmpty (NonEmpty(..))
 import Data.NonEmpty (NonEmpty(..))
-import Data.Traversable (traverse)
 import Effect.Class (liftEffect)
 import Effect.Class (liftEffect)
-import LinkedIn.DetachedNode (DetachedNode(..), toDetached)
-import LinkedIn.Extractible (query)
+import LinkedIn.DetachedNode (DetachedNode(..))
 import LinkedIn.Jobs.JobOffer (JobOffer(..))
 import LinkedIn.Jobs.JobOffer (JobOffer(..))
-import LinkedIn.Jobs.JobOffer as JJO
+import LinkedIn.Output (run, runToDetached)
+import LinkedIn.Output.Types (Output(..))
 import LinkedIn.Page.JobOffer (JobOfferPage(..))
 import LinkedIn.Page.JobOffer (JobOfferPage(..))
-import LinkedIn.QueryRunner (runQuery)
 import LinkedIn.UI.Basic.Types (JobFlexibility(..))
 import LinkedIn.UI.Basic.Types (JobFlexibility(..))
 import LinkedIn.UI.Components.JobsUnifiedTopCard (JobsUnifiedTopCardElement(..), TopCardAction(..), TopCardInsight(..), TopCardInsightContent(..), TopCardPrimaryDescription(..), TopCardSecondaryInsight(..))
 import LinkedIn.UI.Components.JobsUnifiedTopCard (JobsUnifiedTopCardElement(..), TopCardAction(..), TopCardInsight(..), TopCardInsightContent(..), TopCardPrimaryDescription(..), TopCardSecondaryInsight(..))
 import Node.JsDom (jsDomFromFile)
 import Node.JsDom (jsDomFromFile)
-import Partial.Unsafe (unsafePartial)
 import Test.Spec (Spec, describe, it)
 import Test.Spec (Spec, describe, it)
 import Test.Spec.Assertions (shouldEqual)
 import Test.Spec.Assertions (shouldEqual)
-import Test.Utils (fromDetachedToUI)
+import Type.Proxy (Proxy(..))
 
 
 jobsUnifiedTopCardSpec :: Spec Unit
 jobsUnifiedTopCardSpec :: Spec Unit
 jobsUnifiedTopCardSpec = do
 jobsUnifiedTopCardSpec = do
   describe "Jobs top card parsing" do
   describe "Jobs top card parsing" do
-    it "works" do
+    it "reads well as a JobOfferPage DetachedNode" do
       dom <- liftEffect $ jsDomFromFile "test/examples/job_offer.html"
       dom <- liftEffect $ jsDomFromFile "test/examples/job_offer.html"
-      wep <- liftEffect $ runQuery $ query @JobOfferPage dom
+      topCard <- liftEffect $ runExceptT $ runToDetached (Proxy :: Proxy JobOfferPage) dom
 
 
-      isRight wep `shouldEqual` true
-
-      let
-        JobOfferPage jobCard = unsafePartial $ fromJust $ hush wep
-
-      topCard <- liftEffect $ traverse toDetached jobCard
-
-      topCard `shouldEqual` JobsUnifiedTopCardElement {
+      topCard `shouldEqual` Right(JobOfferPage (JobsUnifiedTopCardElement {
         actions: (Just (NonEmptyList
         actions: (Just (NonEmptyList
           (NonEmpty (TopCardActionButton (DetachedButton {
           (NonEmpty (TopCardActionButton (DetachedButton {
             classes: ("jobs-apply-button" : "artdeco-button" : "artdeco-button--3" : "artdeco-button--primary" : "ember-view" : Nil),
             classes: ("jobs-apply-button" : "artdeco-button" : "artdeco-button--3" : "artdeco-button--primary" : "ember-view" : Nil),
@@ -129,13 +120,13 @@ jobsUnifiedTopCardSpec = do
             ))
             ))
           ))
           ))
         })
         })
-      }
+      }))
 
 
+    it "reads the JobOffer" do
+      dom <- liftEffect $ jsDomFromFile "test/examples/job_offer.html"
+      jobOffer <- liftEffect $ runExceptT $ run (Proxy :: Proxy JobOfferPage) dom
 
 
-      let
-        jobOffer = (JJO.fromUI <=< fromDetachedToUI) topCard
-
-      jobOffer `shouldEqual` Right (JobOffer {
+      jobOffer `shouldEqual` Right (OutJobOffer (JobOffer {
         companyDomain: (Just "Technologies et services de l’information"),
         companyDomain: (Just "Technologies et services de l’information"),
         companyLink: "https://www.linkedin.com/company/lincoln-/life",
         companyLink: "https://www.linkedin.com/company/lincoln-/life",
         companyName: "LINCOLN",
         companyName: "LINCOLN",
@@ -144,4 +135,4 @@ jobsUnifiedTopCardSpec = do
         location: (Just "Boulogne-Billancourt, Île-de-France, France"),
         location: (Just "Boulogne-Billancourt, Île-de-France, France"),
         flexibility: (Just JobFlexOnSite),
         flexibility: (Just JobFlexOnSite),
         title: "Data Engineer H/F - Secteur Energie"
         title: "Data Engineer H/F - Secteur Energie"
-      })
+      }))