ArtDecoCard.purs 4.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. module Test.ArtDecoCard where
  2. import Prelude
  3. import Data.Date (Month(..))
  4. import Data.Either (Either(..), hush, isRight)
  5. import Data.List (List(..), (:))
  6. import Data.List.NonEmpty (NonEmptyList(..))
  7. import Data.List.NonEmpty as NEL
  8. import Data.Maybe (Maybe(..), fromJust)
  9. import Data.NonEmpty (NonEmpty(..))
  10. import Data.Traversable (traverse)
  11. import Effect.Class (liftEffect)
  12. import LinkedIn.DetachedNode (DetachedNode(..), toDetached)
  13. import LinkedIn.Extractible (query)
  14. import LinkedIn.Page.WorkExperiences (WorkExperiencesPage(..))
  15. import LinkedIn.Profile.WorkExperience (WorkExperience(..))
  16. import LinkedIn.Profile.WorkExperience as PWE
  17. import LinkedIn.QueryRunner (runQuery)
  18. import LinkedIn.UI.Basic.Types (Duration(..), TimeSpan(..))
  19. import LinkedIn.UI.Components.ArtDeco (ArtDecoCenter(..), ArtDecoCenterContent(..), ArtDecoCenterHeader(..), ArtDecoPvsEntity(..), ArtDecoPvsEntitySubComponent(..))
  20. import LinkedIn.UI.Components.ArtDecoCard (ArtDecoCardElement(..))
  21. import Node.JsDom (jsDomFromFile)
  22. import Partial.Unsafe (unsafePartial)
  23. import Test.Spec (Spec, describe, it)
  24. import Test.Spec.Assertions (shouldEqual)
  25. import Test.Utils (toMonthYear', fromDetachedToUI)
  26. artDecoCardsSpec :: Spec Unit
  27. artDecoCardsSpec = do
  28. describe "Art deco cards parsing" do
  29. it "works" do
  30. dom <- liftEffect $ jsDomFromFile "test/examples/andrew_ng_experiences.html"
  31. wep <- liftEffect $ runQuery $ query @WorkExperiencesPage dom
  32. isRight wep `shouldEqual` true
  33. let
  34. WorkExperiencesPage cards = unsafePartial $ fromJust $ hush wep
  35. head = NEL.head cards
  36. headCard <- liftEffect $ traverse toDetached head
  37. headCard `shouldEqual` ArtDecoCardElement {
  38. pvs_entity: (ArtDecoPvsEntity {
  39. center: (ArtDecoCenter {
  40. content: (ArtDecoCenterContent
  41. (NonEmptyList (NonEmpty
  42. (ArtDecoPvsEntitySubComponent (Just (
  43. DetachedElement {
  44. classes: Nil,
  45. 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!",
  46. id: Nothing,
  47. tag: "SPAN"
  48. }))) Nil))),
  49. header: (ArtDecoCenterHeader {
  50. bold: (DetachedElement {
  51. classes: Nil,
  52. content: "Founder",
  53. id: Nothing,
  54. tag: "SPAN" }
  55. ), light: (Just (NonEmptyList (
  56. NonEmpty (
  57. DetachedElement {
  58. classes: ("pvs-entity__caption-wrapper" : Nil),
  59. content: "juin 2017 - aujourd’hui · 6 ans 7 mois",
  60. id: Nothing,
  61. tag: "SPAN"
  62. }) ((DetachedElement {
  63. classes: Nil,
  64. content: "Palo Alto, California, United States",
  65. id: Nothing,
  66. tag: "SPAN"
  67. }) : Nil)))),
  68. normal: (Just (DetachedElement {
  69. classes: Nil,
  70. content: "DeepLearning.AI",
  71. id: Nothing,
  72. tag: "SPAN" }))
  73. }) }),
  74. side: unit
  75. })
  76. }
  77. let
  78. jobOffer = (PWE.fromUI <=< fromDetachedToUI) headCard
  79. jobOffer `shouldEqual` Right (WorkExperience {
  80. company: Just "DeepLearning.AI",
  81. contractType: Nothing,
  82. 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!",
  83. duration: Just (YearsMonth 6 7),
  84. position: "Founder",
  85. timeSpan: Just (TimeSpanToToday (toMonthYear' June 2017))
  86. })