ArtDecoCard.purs 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. module Test.ArtDecoCard where
  2. import Prelude
  3. import Data.Date (Month(..))
  4. import Data.Either (Either(..))
  5. import Data.List (List(..), (:))
  6. import Data.List.NonEmpty (NonEmptyList(..))
  7. import Data.List.NonEmpty as NEL
  8. import Data.Maybe (Maybe(..))
  9. import Data.NonEmpty (NonEmpty(..))
  10. import LinkedIn.DetachedNode (DetachedNode(..))
  11. import LinkedIn.Output.Types (Output(..))
  12. import LinkedIn.Page.WorkExperiences (WorkExperiencesPage(..))
  13. import LinkedIn.Profile.WorkExperience (WorkExperience(..))
  14. import LinkedIn.UI.Basic.Types (Duration(..), TimeSpan(..))
  15. import LinkedIn.UI.Components.ArtDeco (ArtDecoCenter(..), ArtDecoCenterContent(..), ArtDecoCenterHeader(..), ArtDecoPvsEntity(..), ArtDecoPvsEntitySubComponent(..))
  16. import LinkedIn.UI.Components.ArtDecoCard (ArtDecoCardElement(..))
  17. import Test.Spec (Spec, describe, it)
  18. import Test.Spec.Assertions (fail, shouldEqual)
  19. import Test.Utils (detachFromFile, getOutputFromFile, toMonthYear')
  20. import Type.Proxy (Proxy(..))
  21. type TestCase a = { detached ∷ a DetachedNode , filePath ∷ String , output ∷ WorkExperience }
  22. andrewNgWorkExperience ∷ TestCase ArtDecoCardElement
  23. andrewNgWorkExperience = {
  24. filePath: "test/examples/andrew_ng_experiences.html",
  25. detached: ArtDecoCardElement {
  26. pvs_entity: (ArtDecoPvsEntity {
  27. center: (ArtDecoCenter {
  28. content: (ArtDecoCenterContent (NonEmptyList (NonEmpty (ArtDecoPvsEntitySubComponent (
  29. DetachedElement {classes: Nil, 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!", id: Nothing, tag: "SPAN"}))
  30. Nil
  31. ))),
  32. header: (ArtDecoCenterHeader {
  33. bold: (DetachedElement {classes: Nil, content: "Founder", id: Nothing, tag: "SPAN" }),
  34. light: (Just (NonEmptyList (NonEmpty (
  35. DetachedElement {classes: ("pvs-entity__caption-wrapper" : Nil), content: "juin 2017 - aujourd’hui · 6 ans 7 mois", id: Nothing,tag: "SPAN"})
  36. ((DetachedElement {classes: Nil, content: "Palo Alto, California, United States", id: Nothing,tag: "SPAN"}) : Nil)
  37. ))),
  38. normal: (Just (DetachedElement {classes: Nil, content: "DeepLearning.AI", id: Nothing, tag: "SPAN" }))
  39. })
  40. }),
  41. side: unit
  42. })
  43. },
  44. output: WorkExperience {
  45. company: Just "DeepLearning.AI",
  46. contractType: Nothing,
  47. 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!",
  48. duration: Just (YearsMonth 6 7),
  49. position: "Founder",
  50. timeSpan: Just (TimeSpanToToday (toMonthYear' June 2017))
  51. }
  52. }
  53. artDecoCardsSpec :: Spec Unit
  54. artDecoCardsSpec = do
  55. describe "Art deco cards parsing" do
  56. it "works" do
  57. cards <- detachFromFile (Proxy :: Proxy WorkExperiencesPage) andrewNgWorkExperience.filePath
  58. case cards of
  59. Left _ -> fail "Detach operation failed"
  60. Right (WorkExperiencesPage c) -> do
  61. let head = NEL.head c
  62. head `shouldEqual` andrewNgWorkExperience.detached
  63. it "reads the work experience" do
  64. wxpPage <- getOutputFromFile (Proxy :: Proxy WorkExperiencesPage) andrewNgWorkExperience.filePath
  65. case wxpPage of
  66. Right (OutWorkExperiences weps) -> do
  67. let head = NEL.head weps
  68. head `shouldEqual` andrewNgWorkExperience.output
  69. _ -> fail "Test failed"