ArtDecoCard.purs 5.0 KB

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