ArtDecoCard.purs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. module Test.ArtDecoCard where
  2. import LinkedIn.ArtDecoCard
  3. import Prelude
  4. import Data.Either (Either(..))
  5. import Data.List.NonEmpty (NonEmptyList(..))
  6. import Data.List.NonEmpty as NEL
  7. import Data.List (List(..), (:))
  8. import Data.Maybe (Maybe(..), isJust)
  9. import Data.NonEmpty (NonEmpty(..))
  10. import Effect (Effect)
  11. import LinkedIn (DetachedNode(..), LinkedInUIElement(..), getArtDecoCards)
  12. import LinkedIn.Types (ParseError)
  13. import Node.JsDom (jsDomFromFile)
  14. import Partial.Unsafe (unsafePartial)
  15. import Test.Assert (assert, assertEqual)
  16. testArtDecoCards :: Effect Unit
  17. testArtDecoCards = do
  18. dom <- jsDomFromFile "test/examples/andrew_ng_experiences.html"
  19. artDecoCards <- getArtDecoCards dom
  20. assert $ isJust artDecoCards
  21. headCard <- unsafePartial $ parseHeadCard artDecoCards
  22. assertEqual {
  23. actual: headCard,
  24. expected: Right (
  25. ArtDecoCardElement {
  26. pvs_entity: (ArtDecoPvsEntity {
  27. center: (ArtDecoCenter {
  28. content: (ArtDecoCenterContent
  29. (NonEmptyList (NonEmpty
  30. (ArtDecoPvsEntitySubComponent (
  31. DetachedElement {
  32. classes: ("" : Nil),
  33. 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!",
  34. id: Nothing,
  35. tag: "SPAN"
  36. })) Nil))),
  37. header: (ArtDecoCenterHeader {
  38. bold: (DetachedElement {
  39. classes: ("" : Nil),
  40. content: "Founder",
  41. id: Nothing,
  42. tag: "SPAN" }
  43. ), light: (Just (NonEmptyList (
  44. NonEmpty (
  45. DetachedElement {
  46. classes: ("pvs-entity__caption-wrapper" : Nil),
  47. content: "juin 2017 - aujourd’hui · 6 ans 7 mois",
  48. id: Nothing,
  49. tag: "SPAN"
  50. }) ((DetachedElement {
  51. classes: ("" : Nil),
  52. content: "Palo Alto, California, United States",
  53. id: Nothing,
  54. tag: "SPAN"
  55. }) : Nil)))),
  56. normal: (Just (DetachedElement {
  57. classes: ("" : Nil),
  58. content: "DeepLearning.AI",
  59. id: Nothing,
  60. tag: "SPAN" }))
  61. }) }),
  62. side: unit
  63. })
  64. }
  65. )
  66. }
  67. parseHeadCard ∷ Partial => Maybe (NonEmptyList LinkedInUIElement) → Effect (Either ParseError ArtDecoCardElement)
  68. parseHeadCard (Just l) = do
  69. parsed <- (\(LinkedInUIElement _ n) -> parseArtDecoCard n) $ NEL.head l
  70. pure $ parsed
  71. testArtDecoCard :: Effect Unit
  72. testArtDecoCard = do
  73. testArtDecoCards