ArtDecoCard.purs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. module Test.ArtDecoCard where
  2. import Prelude
  3. import Data.Date (Month(..))
  4. import Data.Either (Either(..))
  5. import Data.List (List(..), (:))
  6. import Data.List.NonEmpty (NonEmptyList(..))
  7. import Data.List.NonEmpty as NEL
  8. import Data.Maybe (Maybe(..), isJust)
  9. import Data.NonEmpty (NonEmpty(..))
  10. import Data.Traversable (traverse)
  11. import Effect (Effect)
  12. import LinkedIn.ArtDeco (ArtDecoCenter(..), ArtDecoCenterContent(..), ArtDecoCenterHeader(..), ArtDecoPvsEntity(..), ArtDecoPvsEntitySubComponent(..))
  13. import LinkedIn.ArtDecoCard (ArtDecoCardElement(..), queryArtDecoCard)
  14. import LinkedIn.DetachedNode (DetachedNode(..), toDetached)
  15. import LinkedIn (LinkedInUIElement(..), getArtDecoCards)
  16. import LinkedIn.Profile.WorkExperience (WorkExperience(..))
  17. import LinkedIn.Profile.WorkExperience as PWE
  18. import LinkedIn.QueryRunner (QueryError, runQuery)
  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. testArtDecoCards :: Effect Unit
  25. testArtDecoCards = do
  26. dom <- jsDomFromFile "test/examples/andrew_ng_experiences.html"
  27. artDecoCards <- getArtDecoCards dom
  28. assert $ isJust artDecoCards
  29. headCard <- unsafePartial $ parseHeadCard artDecoCards
  30. assertEqual {
  31. actual: headCard,
  32. expected: Right (
  33. ArtDecoCardElement {
  34. pvs_entity: (ArtDecoPvsEntity {
  35. center: (ArtDecoCenter {
  36. content: (ArtDecoCenterContent
  37. (NonEmptyList (NonEmpty
  38. (ArtDecoPvsEntitySubComponent (Just (
  39. DetachedElement {
  40. classes: ("" : Nil),
  41. content: "DeepLearning.AI provides\ntechnical training on Generative AI, Machine Learning, Deep Learning,\nand other topics. We also offer a widely read newsletter, The Batch\n(thebatch.ai), that covers what matters in AI right now. Our courses are often created with industry-leading AI companies (AWS,\nGoogle, OpenAI, etc.), and we offer both short courses that can be\ncompleted in an hour, and longer courses and specializations hosted on\nCoursera that give you a solid foundation in some aspect of AI. These\ncourses are designed to offer hands-on practice with AI technologies,\nand you will gain practical, job-ready skills. Whether you are just starting out in AI or seeking to further an existing\ncareer, come see if we can help, at http://deeplearning.ai!",
  42. id: Nothing,
  43. tag: "SPAN"
  44. }))) Nil))),
  45. header: (ArtDecoCenterHeader {
  46. bold: (DetachedElement {
  47. classes: ("" : Nil),
  48. content: "Founder",
  49. id: Nothing,
  50. tag: "SPAN" }
  51. ), light: (Just (NonEmptyList (
  52. NonEmpty (
  53. DetachedElement {
  54. classes: ("pvs-entity__caption-wrapper" : Nil),
  55. content: "juin 2017 - aujourd’hui · 6 ans 7 mois",
  56. id: Nothing,
  57. tag: "SPAN"
  58. }) ((DetachedElement {
  59. classes: ("" : Nil),
  60. content: "Palo Alto, California, United States",
  61. id: Nothing,
  62. tag: "SPAN"
  63. }) : Nil)))),
  64. normal: (Just (DetachedElement {
  65. classes: ("" : Nil),
  66. content: "DeepLearning.AI",
  67. id: Nothing,
  68. tag: "SPAN" }))
  69. }) }),
  70. side: unit
  71. })
  72. }
  73. )
  74. }
  75. case headCard of
  76. Left _ -> pure unit
  77. Right card -> do
  78. assertEqual {
  79. actual: PWE.fromUI card,
  80. expected:
  81. Right (WorkExperience {
  82. company: Just "DeepLearning.AI",
  83. contractType: Nothing,
  84. description: Just "DeepLearning.AI provides\ntechnical training on Generative AI, Machine Learning, Deep Learning,\nand other topics. We also offer a widely read newsletter, The Batch\n(thebatch.ai), that covers what matters in AI right now. Our courses are often created with industry-leading AI companies (AWS,\nGoogle, OpenAI, etc.), and we offer both short courses that can be\ncompleted in an hour, and longer courses and specializations hosted on\nCoursera that give you a solid foundation in some aspect of AI. These\ncourses are designed to offer hands-on practice with AI technologies,\nand you will gain practical, job-ready skills. Whether you are just starting out in AI or seeking to further an existing\ncareer, come see if we can help, at http://deeplearning.ai!",
  85. duration: Just (YearsMonth 6 7),
  86. position: "Founder",
  87. timeSpan: Just (TimeSpanToToday (toMonthYear' June 2017))
  88. })
  89. }
  90. parseHeadCard ∷ Partial => Maybe (NonEmptyList LinkedInUIElement) → Effect (Either QueryError (ArtDecoCardElement DetachedNode))
  91. parseHeadCard (Just l) = do
  92. queried <- (\(LinkedInUIElement _ n) -> runQuery $ queryArtDecoCard n) $ NEL.head l
  93. case queried of
  94. Left l' -> pure $ Left l'
  95. Right q -> do
  96. parsed <- traverse toDetached q
  97. pure $ Right parsed
  98. testArtDecoCard :: Effect Unit
  99. testArtDecoCard = do
  100. testArtDecoCards