ArtDecoCard.purs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. module Test.ArtDecoCard where
  2. import LinkedIn.ArtDeco
  3. import LinkedIn.ArtDecoCard
  4. import Prelude
  5. import Data.Date (Month(..))
  6. import Data.Either (Either(..))
  7. import Data.List (List(..), (:))
  8. import Data.List.NonEmpty (NonEmptyList(..))
  9. import Data.List.NonEmpty as NEL
  10. import Data.Maybe (Maybe(..), isJust)
  11. import Data.NonEmpty (NonEmpty(..))
  12. import Data.Traversable (traverse)
  13. import Effect (Effect)
  14. import LinkedIn (DetachedNode(..), LinkedInUIElement(..), getArtDecoCards, toDetached)
  15. import LinkedIn.Profile.WorkExperience (WorkExperience(..))
  16. import LinkedIn.Profile.WorkExperience as PWE
  17. import LinkedIn.QueryRunner (QueryError, runQuery)
  18. import LinkedIn.UIElements.Types (Duration(..), TimeSpan(..))
  19. import Node.JsDom (jsDomFromFile)
  20. import Partial.Unsafe (unsafePartial)
  21. import Test.Assert (assert, assertEqual)
  22. import Test.Utils (toMonthYear')
  23. testArtDecoCards :: Effect Unit
  24. testArtDecoCards = do
  25. dom <- jsDomFromFile "test/examples/andrew_ng_experiences.html"
  26. artDecoCards <- getArtDecoCards dom
  27. assert $ isJust artDecoCards
  28. headCard <- unsafePartial $ parseHeadCard artDecoCards
  29. assertEqual {
  30. actual: headCard,
  31. expected: Right (
  32. ArtDecoCardElement {
  33. pvs_entity: (ArtDecoPvsEntity {
  34. center: (ArtDecoCenter {
  35. content: (ArtDecoCenterContent
  36. (NonEmptyList (NonEmpty
  37. (ArtDecoPvsEntitySubComponent (Just (
  38. DetachedElement {
  39. classes: ("" : Nil),
  40. 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!",
  41. id: Nothing,
  42. tag: "SPAN"
  43. }))) Nil))),
  44. header: (ArtDecoCenterHeader {
  45. bold: (DetachedElement {
  46. classes: ("" : Nil),
  47. content: "Founder",
  48. id: Nothing,
  49. tag: "SPAN" }
  50. ), light: (Just (NonEmptyList (
  51. NonEmpty (
  52. DetachedElement {
  53. classes: ("pvs-entity__caption-wrapper" : Nil),
  54. content: "juin 2017 - aujourd’hui · 6 ans 7 mois",
  55. id: Nothing,
  56. tag: "SPAN"
  57. }) ((DetachedElement {
  58. classes: ("" : Nil),
  59. content: "Palo Alto, California, United States",
  60. id: Nothing,
  61. tag: "SPAN"
  62. }) : Nil)))),
  63. normal: (Just (DetachedElement {
  64. classes: ("" : Nil),
  65. content: "DeepLearning.AI",
  66. id: Nothing,
  67. tag: "SPAN" }))
  68. }) }),
  69. side: unit
  70. })
  71. }
  72. )
  73. }
  74. case headCard of
  75. Left _ -> pure unit
  76. Right card -> do
  77. assertEqual {
  78. actual: PWE.fromUI card,
  79. expected:
  80. Right (WorkExperience {
  81. company: Just "DeepLearning.AI",
  82. contractType: Nothing,
  83. 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!",
  84. duration: Just (YearsMonth 6 7),
  85. position: "Founder",
  86. timeSpan: Just (TimeSpanToToday (toMonthYear' June 2017))
  87. })
  88. }
  89. parseHeadCard ∷ Partial => Maybe (NonEmptyList LinkedInUIElement) → Effect (Either QueryError (ArtDecoCardElement DetachedNode))
  90. parseHeadCard (Just l) = do
  91. queried <- (\(LinkedInUIElement _ n) -> runQuery $ queryArtDecoCard n) $ NEL.head l
  92. case queried of
  93. Left l -> pure $ Left l
  94. Right q -> do
  95. parsed <- traverse toDetached q
  96. pure $ Right parsed
  97. testArtDecoCard :: Effect Unit
  98. testArtDecoCard = do
  99. testArtDecoCards