ArtDecoCard.purs 3.3 KB

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