JobsUnifiedTopCard.purs 6.1 KB

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