JobsUnifiedTopCard.purs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. module Test.JobsUnifiedTopCard where
  2. import LinkedIn.JobsUnifiedTopCard
  3. import Prelude
  4. import Data.Date (Month(..))
  5. import Data.Either (Either(..))
  6. import Data.List (List(..), (:))
  7. import Data.List.NonEmpty (NonEmptyList(..))
  8. import Data.List.NonEmpty as NEL
  9. import Data.Maybe (Maybe(..), isJust)
  10. import Data.NonEmpty (NonEmpty(..))
  11. import Data.Traversable (traverse)
  12. import Effect (Effect)
  13. import LinkedIn.DetachedNode (DetachedNode(..), toDetached)
  14. import LinkedIn (LinkedInUIElement(..), getJobsUnifiedTopCard)
  15. import LinkedIn.Profile.WorkExperience (WorkExperience(..))
  16. import LinkedIn.Profile.WorkExperience as PWE
  17. import LinkedIn.QueryRunner (QueryError, runQuery)
  18. import LinkedIn.Types (ParseError(..))
  19. import LinkedIn.UIElements.Types (Duration(..), TimeSpan(..))
  20. import Node.JsDom (jsDomFromFile)
  21. import Partial.Unsafe (unsafePartial)
  22. import Test.Assert (assert, assertEqual)
  23. import Test.Utils (toMonthYear')
  24. testJobsUnifiedTopCard :: Effect Unit
  25. testJobsUnifiedTopCard = do
  26. dom <- jsDomFromFile "test/examples/job_offer.html"
  27. topCard <- getJobsUnifiedTopCard dom
  28. assert $ isJust topCard
  29. headCard <- unsafePartial $ parseHeadCard topCard
  30. assertEqual {
  31. actual: headCard,
  32. expected: Right (JobsUnifiedTopCardElement {
  33. actions: (Just (NonEmptyList
  34. (NonEmpty (TopCardActionApplyButton (DetachedButton {
  35. classes: ("jobs-apply-button" : "artdeco-button" : "artdeco-button--3" : "artdeco-button--primary" : "ember-view" : Nil),
  36. content: "Candidature simplifiée",
  37. role: Nothing
  38. })) ((TopCardActionApplyButton (DetachedButton {
  39. classes: ("jobs-save-button" : "artdeco-button" : "artdeco-button--3" : "artdeco-button--secondary" : Nil),
  40. content: "Enregistrer Enregistrer Data Engineer H/F - Secteur Energie chez LINCOLN",
  41. role: Nothing
  42. })) : Nil)))),
  43. header: (DetachedElement {
  44. classes: ("t-24" : "t-bold" : "job-details-jobs-unified-top-card__job-title" : Nil),
  45. content: "Data Engineer H/F - Secteur Energie",
  46. id: Nothing,
  47. tag: "H1"
  48. }),
  49. insights: (Just (NonEmptyList
  50. (NonEmpty (TopCardInsight {
  51. content: (TopCardInsightContentSecondary {
  52. primary: (DetachedElement {
  53. classes: ("" : Nil),
  54. content: "Sur site",
  55. id: Nothing,
  56. tag: "SPAN"
  57. }),
  58. secondary: (NonEmptyList (NonEmpty (TopCardSecondaryInsightNested
  59. (DetachedElement {
  60. classes: ("" : Nil),
  61. content: "Temps plein",
  62. id: Nothing,
  63. tag: "SPAN"
  64. })) ((TopCardSecondaryInsightPlain
  65. (DetachedElement {
  66. classes: ("job-details-jobs-unified-top-card__job-insight-view-model-secondary" : Nil),
  67. content: "Confirmé",
  68. id: (Just "undefined"),
  69. tag: "SPAN"
  70. })) : Nil))) }),
  71. icon: (DetachedElement {
  72. classes: ("" : Nil),
  73. content: "",
  74. id: Nothing,
  75. tag: "LI-ICON"
  76. })
  77. }) ((TopCardInsight {
  78. content: (TopCardInsightContentSingle (DetachedElement {
  79. classes: ("" : Nil),
  80. content: "201-500 employés · Technologies et services de l’information",
  81. id: (Just "undefined"),
  82. tag: "SPAN" })),
  83. icon: (DetachedElement {
  84. classes: ("" : Nil),
  85. content: "",
  86. id: Nothing,
  87. tag: "LI-ICON" })
  88. }) : (TopCardInsight {
  89. content: (TopCardInsightContentSingle (DetachedElement {
  90. classes: ("" : Nil),
  91. content: "2 anciens élèves travaillent ici",
  92. id: (Just "undefined"),
  93. tag: "SPAN" })),
  94. icon: (DetachedElement {
  95. classes: ("" : Nil),
  96. content: "",
  97. id: Nothing,
  98. tag: "LI-ICON" })
  99. }) : (TopCardInsight {
  100. content: (TopCardInsightContentSingle (DetachedElement {
  101. classes: ("" : Nil),
  102. content: "Découvrez comment vous vous positionnez par rapport à 87 candidats. Essai Premium pour 0 EUR",
  103. id: (Just "undefined"),
  104. tag: "SPAN" })),
  105. icon: (DetachedElement {
  106. classes: Nil,
  107. content: "",
  108. id: Nothing,
  109. tag: "svg"
  110. })
  111. }) : (TopCardInsight {
  112. content: (TopCardInsightContentButton (DetachedButton {
  113. classes: ("job-details-jobs-unified-top-card__job-insight-text-button" : Nil),
  114. content: "9 compétences sur 11 correspondent à votre profil, vous pourriez bien convenir pour ce poste",
  115. role: Nothing
  116. })),
  117. icon: (DetachedElement {
  118. classes: Nil,
  119. content: "",
  120. id: Nothing,
  121. tag: "svg"
  122. })
  123. }) : Nil)))),
  124. primaryDescription: (TopCardPrimaryDescription {
  125. link: (DetachedA { content: "LINCOLN", href: "https://www.linkedin.com/company/lincoln-/life" }),
  126. text: (DetachedText "· Boulogne-Billancourt, Île-de-France, France"),
  127. tvmText: (Just (NonEmptyList
  128. (NonEmpty (DetachedElement {
  129. classes: ("tvm__text" : "tvm__text--neutral" : Nil),
  130. content: "il y a 2 semaines",
  131. id: Nothing,
  132. tag: "SPAN"
  133. }) ((DetachedElement {
  134. classes: ("tvm__text" : "tvm__text--neutral" : Nil),
  135. content: "·",
  136. id: Nothing,
  137. tag: "SPAN"
  138. }) : (DetachedElement {
  139. classes: ("tvm__text" : "tvm__text--neutral" : Nil),
  140. content: "87 candidats",
  141. id: Nothing,
  142. tag: "SPAN"
  143. }) : Nil
  144. ))
  145. ))
  146. })
  147. })
  148. }
  149. parseHeadCard ∷ Partial ⇒ Maybe (NonEmptyList LinkedInUIElement) → Effect (Either QueryError (JobsUnifiedTopCardElement DetachedNode))
  150. parseHeadCard (Just l) = do
  151. queried <- (\(LinkedInUIElement _ n) -> runQuery $ queryJobsUnifiedTopCardElement n) $ NEL.head l
  152. case queried of
  153. Left l -> pure $ Left l
  154. Right q -> do
  155. parsed <- traverse toDetached q
  156. pure $ Right parsed