elm-pages-v3-beta/tests/Pages/Review/DeadCodeEliminateDataTest.elm

422 lines
8.8 KiB
Elm
Raw Normal View History

2022-02-13 23:42:31 +03:00
module Pages.Review.DeadCodeEliminateDataTest exposing (all)
import Pages.Review.DeadCodeEliminateData exposing (rule)
import Review.Test
import Test exposing (Test, describe, test)
all : Test
all =
2022-02-27 01:10:31 +03:00
describe "dead code elimination"
2022-02-13 23:42:31 +03:00
[ test "replaces data record setter" <|
\() ->
"""module Page.Index exposing (Data, Model, Msg, page)
import DataSource exposing (DataSource)
2022-03-05 20:50:01 +03:00
import RouteBuilder exposing (Page, StaticPayload)
2022-02-13 23:42:31 +03:00
import Pages.PageUrl exposing (PageUrl)
import Pages.Url
import Path
import Route exposing (Route)
import Shared
import View exposing (View)
type alias Model =
{}
type alias Msg =
()
type alias RouteParams =
{}
type alias Data =
()
2022-03-05 20:50:01 +03:00
page : StatelessRoute RouteParams Data
2022-02-13 23:42:31 +03:00
page =
2022-03-05 20:50:01 +03:00
RouteBuilder.single
2022-02-13 23:42:31 +03:00
{ head = head
, data = data
}
2022-03-05 20:50:01 +03:00
|> RouteBuilder.buildNoState { view = view }
2022-02-13 23:42:31 +03:00
data : DataSource Data
data =
DataSource.succeed ()
"""
|> Review.Test.run rule
|> Review.Test.expectErrors
[ Review.Test.error
{ message = "Codemod"
, details =
[ "" ]
, under =
"""data = data
}"""
}
|> Review.Test.whenFixed
"""module Page.Index exposing (Data, Model, Msg, page)
import DataSource exposing (DataSource)
2022-03-05 20:50:01 +03:00
import RouteBuilder exposing (Page, StaticPayload)
2022-02-13 23:42:31 +03:00
import Pages.PageUrl exposing (PageUrl)
import Pages.Url
import Path
import Route exposing (Route)
import Shared
import View exposing (View)
type alias Model =
{}
type alias Msg =
()
type alias RouteParams =
{}
type alias Data =
()
2022-03-05 20:50:01 +03:00
page : StatelessRoute RouteParams Data
2022-02-13 23:42:31 +03:00
page =
2022-03-05 20:50:01 +03:00
RouteBuilder.single
2022-02-13 23:42:31 +03:00
{ head = head
, data = DataSource.fail ""
}
2022-03-05 20:50:01 +03:00
|> RouteBuilder.buildNoState { view = view }
2022-02-13 23:42:31 +03:00
data : DataSource Data
data =
DataSource.succeed ()
"""
]
, test "replaces data record setter with non-empty RouteParams" <|
\() ->
"""module Page.Blog.Slug_ exposing (Data, Model, Msg, page)
import DataSource exposing (DataSource)
2022-03-05 20:50:01 +03:00
import RouteBuilder exposing (Page, StaticPayload)
2022-02-13 23:42:31 +03:00
import Pages.PageUrl exposing (PageUrl)
import Pages.Url
import Path
import Route exposing (Route)
import Shared
import View exposing (View)
type alias Model =
{}
type alias Msg =
()
type alias RouteParams =
{ slug : String }
type alias Data =
()
2022-03-05 20:50:01 +03:00
page : StatelessRoute RouteParams Data
2022-02-13 23:42:31 +03:00
page =
Page.preRender
{ data = data
, head = head
, pages = pages
}
2022-03-05 20:50:01 +03:00
|> RouteBuilder.buildNoState { view = view }
2022-02-13 23:42:31 +03:00
data : DataSource Data
data =
DataSource.succeed ()
"""
|> Review.Test.run rule
|> Review.Test.expectErrors
[ Review.Test.error
{ message = "Codemod"
, details =
[ "" ]
, under =
"""data = data"""
}
|> Review.Test.whenFixed
"""module Page.Blog.Slug_ exposing (Data, Model, Msg, page)
import DataSource exposing (DataSource)
2022-03-05 20:50:01 +03:00
import RouteBuilder exposing (Page, StaticPayload)
2022-02-13 23:42:31 +03:00
import Pages.PageUrl exposing (PageUrl)
import Pages.Url
import Path
import Route exposing (Route)
import Shared
import View exposing (View)
type alias Model =
{}
type alias Msg =
()
type alias RouteParams =
{ slug : String }
type alias Data =
()
2022-03-05 20:50:01 +03:00
page : StatelessRoute RouteParams Data
2022-02-13 23:42:31 +03:00
page =
Page.preRender
{ data = \\_ -> DataSource.fail ""
, head = head
, pages = pages
}
2022-03-05 20:50:01 +03:00
|> RouteBuilder.buildNoState { view = view }
2022-02-13 23:42:31 +03:00
data : DataSource Data
data =
DataSource.succeed ()
"""
]
2022-03-05 20:50:01 +03:00
, test "replaces data record setter with RouteBuilder.serverRendered" <|
\() ->
"""module Page.Login exposing (Data, Model, Msg, page)
type alias Model =
{}
type alias Msg =
()
type alias RouteParams =
{}
2022-03-05 20:50:01 +03:00
page : StatelessRoute RouteParams Data
page =
2022-03-05 20:50:01 +03:00
RouteBuilder.serverRender
{ head = head
, data = data
}
2022-03-05 20:50:01 +03:00
|> RouteBuilder.buildNoState { view = view }
"""
|> Review.Test.run rule
|> Review.Test.expectErrors
[ Review.Test.error
{ message = "Codemod"
, details =
[ "" ]
, under =
"""data = data
}"""
}
|> Review.Test.whenFixed
"""module Page.Login exposing (Data, Model, Msg, page)
type alias Model =
{}
type alias Msg =
()
type alias RouteParams =
{}
2022-03-05 20:50:01 +03:00
page : StatelessRoute RouteParams Data
page =
2022-03-05 20:50:01 +03:00
RouteBuilder.serverRender
{ head = head
, data = \\_ -> Request.oneOf []
}
2022-03-05 20:50:01 +03:00
|> RouteBuilder.buildNoState { view = view }
2022-02-13 23:42:31 +03:00
"""
]
, test "no Request.oneOf fix after replacement is made" <|
\() ->
"""module Page.Login exposing (Data, Model, Msg, page)
type alias Model =
{}
type alias Msg =
()
type alias RouteParams =
{}
2022-03-05 20:50:01 +03:00
page : StatelessRoute RouteParams Data
page =
2022-03-05 20:50:01 +03:00
RouteBuilder.serverRender
{ head = head
, data = \\_ -> Request.oneOf []
}
2022-03-05 20:50:01 +03:00
|> RouteBuilder.buildNoState { view = view }
"""
|> Review.Test.run rule
|> Review.Test.expectNoErrors
2022-02-13 23:42:31 +03:00
, test "no fix after replacement is made" <|
\() ->
"""module Page.Index exposing (Data, Model, Msg, page)
import DataSource exposing (DataSource)
2022-03-05 20:50:01 +03:00
import RouteBuilder exposing (Page, StaticPayload)
2022-02-13 23:42:31 +03:00
import Pages.PageUrl exposing (PageUrl)
import Pages.Url
import Path
import Route exposing (Route)
import Shared
import View exposing (View)
type alias Model =
{}
type alias Msg =
()
type alias RouteParams =
{}
type alias Data =
()
2022-03-05 20:50:01 +03:00
page : StatelessRoute RouteParams Data
2022-02-13 23:42:31 +03:00
page =
2022-03-05 20:50:01 +03:00
RouteBuilder.single
2022-02-13 23:42:31 +03:00
{ head = head
, data = DataSource.fail ""
}
2022-03-05 20:50:01 +03:00
|> RouteBuilder.buildNoState { view = view }
2022-02-13 23:42:31 +03:00
data : DataSource Data
data =
DataSource.succeed ()
"""
|> Review.Test.run rule
|> Review.Test.expectNoErrors
, test "replaces data record setter in Shared module" <|
\() ->
"""module Shared exposing (Data, Model, Msg, template)
import Browser.Navigation
import DataSource
import Html exposing (Html)
import Html.Styled
import Pages.Flags
import Pages.PageUrl exposing (PageUrl)
import Path exposing (Path)
import Route exposing (Route)
import SharedTemplate exposing (SharedTemplate)
import TableOfContents
import View exposing (View)
import View.Header
template : SharedTemplate Msg Model Data msg
template =
{ init = init
, update = update
, view = view
, data = data
, subscriptions = subscriptions
, onPageChange = Just OnPageChange
}
type alias Data =
TableOfContents.TableOfContents TableOfContents.Data
type alias Model =
{ showMobileMenu : Bool
, counter : Int
, navigationKey : Maybe Browser.Navigation.Key
}
"""
|> Review.Test.run rule
|> Review.Test.expectErrors
[ Review.Test.error
{ message = "Codemod"
, details =
[ "" ]
, under =
"""data = data
,"""
}
|> Review.Test.whenFixed
"""module Shared exposing (Data, Model, Msg, template)
import Browser.Navigation
import DataSource
import Html exposing (Html)
import Html.Styled
import Pages.Flags
import Pages.PageUrl exposing (PageUrl)
import Path exposing (Path)
import Route exposing (Route)
import SharedTemplate exposing (SharedTemplate)
import TableOfContents
import View exposing (View)
import View.Header
template : SharedTemplate Msg Model Data msg
template =
{ init = init
, update = update
, view = view
, data = DataSource.fail ""
, subscriptions = subscriptions
, onPageChange = Just OnPageChange
}
type alias Data =
TableOfContents.TableOfContents TableOfContents.Data
type alias Model =
{ showMobileMenu : Bool
, counter : Int
, navigationKey : Maybe Browser.Navigation.Key
}
"""
]
]