From 777d29cf9f499cef0bd87e0355a66e084044e415 Mon Sep 17 00:00:00 2001 From: Lucas Payr Date: Tue, 26 Jan 2021 22:12:35 +0100 Subject: [PATCH] Added Tests --- build.sh | 2 +- elm.json | 13 +- example/elm.json | 2 +- example/tests/elm-verify-examples.json | 4 + src/Widget.elm | 176 +++++++++++++++++- tests/VerifyExamples/Widget/Button0.elm | 37 ++++ tests/VerifyExamples/Widget/Dialog0.elm | 47 +++++ tests/VerifyExamples/Widget/IconButton0.elm | 37 ++++ tests/VerifyExamples/Widget/Modal0.elm | 38 ++++ tests/VerifyExamples/Widget/MultiSelect0.elm | 48 +++++ tests/VerifyExamples/Widget/Select0.elm | 47 +++++ tests/VerifyExamples/Widget/SelectButton0.elm | 47 +++++ tests/VerifyExamples/Widget/Switch0.elm | 35 ++++ tests/VerifyExamples/Widget/TextButton0.elm | 34 ++++ tests/elm-verify-examples.json | 8 +- 15 files changed, 559 insertions(+), 16 deletions(-) create mode 100644 example/tests/elm-verify-examples.json create mode 100644 tests/VerifyExamples/Widget/Button0.elm create mode 100644 tests/VerifyExamples/Widget/Dialog0.elm create mode 100644 tests/VerifyExamples/Widget/IconButton0.elm create mode 100644 tests/VerifyExamples/Widget/Modal0.elm create mode 100644 tests/VerifyExamples/Widget/MultiSelect0.elm create mode 100644 tests/VerifyExamples/Widget/Select0.elm create mode 100644 tests/VerifyExamples/Widget/SelectButton0.elm create mode 100644 tests/VerifyExamples/Widget/Switch0.elm create mode 100644 tests/VerifyExamples/Widget/TextButton0.elm diff --git a/build.sh b/build.sh index 2af032d..313b1c1 100644 --- a/build.sh +++ b/build.sh @@ -1 +1 @@ -elm-verify-examples --run-tests \ No newline at end of file +elm-verify-examples && elm-test \ No newline at end of file diff --git a/elm.json b/elm.json index c2b2de3..d1047b2 100644 --- a/elm.json +++ b/elm.json @@ -6,10 +6,10 @@ "version": "2.3.0", "exposed-modules": [ "Widget", - "Widget.Style.Material", - "Widget.Style.Material.Typography", - "Widget.Style.Material.Color", - "Widget.Style.Customize", + "Widget.Material", + "Widget.Material.Typography", + "Widget.Material.Color", + "Widget.Customize", "Widget.Layout", "Widget.ScrollingNav", "Widget.Snackbar", @@ -20,7 +20,7 @@ "Orasund/elm-ui-framework": "1.6.1 <= v < 2.0.0", "avh4/elm-color": "1.0.0 <= v < 2.0.0", "elm/browser": "1.0.2 <= v < 2.0.0", - "elm/core": "1.0.0 <= v < 2.0.0", + "elm/core": "1.0.2 <= v < 2.0.0", "elm/html": "1.0.0 <= v < 2.0.0", "elm/svg": "1.0.1 <= v < 2.0.0", "elm/time": "1.0.0 <= v < 2.0.0", @@ -31,6 +31,7 @@ "wernerdegroot/listzipper": "4.0.0 <= v < 5.0.0" }, "test-dependencies": { - "elm-explorations/test": "1.2.1 <= v < 2.0.0" + "elm-explorations/test": "1.2.1 <= v < 2.0.0", + "icidasset/elm-material-icons": "5.0.0 <= v < 6.0.0" } } \ No newline at end of file diff --git a/example/elm.json b/example/elm.json index a4a3cd6..03646c5 100644 --- a/example/elm.json +++ b/example/elm.json @@ -48,4 +48,4 @@ "elm/random": "1.0.0" } } -} +} \ No newline at end of file diff --git a/example/tests/elm-verify-examples.json b/example/tests/elm-verify-examples.json new file mode 100644 index 0000000..7f2c8f2 --- /dev/null +++ b/example/tests/elm-verify-examples.json @@ -0,0 +1,4 @@ +{ + "root": "../src", + "tests": [] +} diff --git a/src/Widget.elm b/src/Widget.elm index 491eb09..4911839 100644 --- a/src/Widget.elm +++ b/src/Widget.elm @@ -231,16 +231,20 @@ type alias TextButton msg = {-| A button containing only an icon, the text is used for screenreaders. - import Widget.Style.Material as Material + import Widget.Material as Material + import Material.Icons as MaterialIcons + import Material.Icons.Types exposing (Coloring(..)) + import Widget.Icon as Icon type Msg - = Like + = Like iconButton (Material.iconButton Material.defaultPalette) - { text = Like - , icon = MaterialIcons.hearth |> Icon.elmMaterialIcons Color + { text = "Like" + , icon = MaterialIcons.favorite |> Icon.elmMaterialIcons Color , onPress = Just Like } + |> always "Ignore this line" --> "Ignore this line" -} iconButton : @@ -261,6 +265,19 @@ iconButton = {-| A button with just text and not icon. + + import Widget.Material as Material + import Material.Icons as MaterialIcons + + type Msg + = Like + + textButton (Material.textButton Material.defaultPalette) + { text = "Like" + , onPress = Just Like + } + |> always "Ignore this line" --> "Ignore this line" + -} textButton : ButtonStyle msg @@ -283,6 +300,22 @@ textButton style { text, onPress } = {-| A button containing a text and an icon. + + import Widget.Material as Material + import Material.Icons as MaterialIcons + import Material.Icons.Types exposing (Coloring(..)) + import Widget.Icon as Icon + + type Msg + = Submit + + button (Material.containedButton Material.defaultPalette) + { text = "Submit" + , icon = MaterialIcons.favorite |> Icon.elmMaterialIcons Color + , onPress = Just Submit + } + |> always "Ignore this line" --> "Ignore this line" + -} button : ButtonStyle msg @@ -341,6 +374,20 @@ type alias Switch msg = {-| A boolean switch + + import Widget.Material as Material + import Material.Icons as MaterialIcons + + type Msg + = Activate + + switch (Material.switch Material.defaultPalette) + { description = "Activate Dark Mode" + , onPress = Just Activate + , active = False + } + |> always "Ignore this line" --> "Ignore this line" + -} switch : SwitchStyle msg @@ -402,6 +449,32 @@ type alias MultiSelect msg = {-| A simple button that can be selected. + + import Widget.Material as Material + import Material.Icons as MaterialIcons + import Element + + type Msg + = ChangedSelected Int + + { selected = Just 1 + , options = + [ 1, 2, 42 ] + |> List.map + (\int -> + { text = String.fromInt int + , icon = always Element.none + } + ) + , onSelect = (\i -> Just <| ChangedSelected i) + } + |> Widget.select + |> Widget.buttonRow + { elementRow = Material.buttonRow + , content = Material.toggleButton Material.defaultPalette + } + |> always "Ignore this line" --> "Ignore this line" + -} selectButton : ButtonStyle msg @@ -412,6 +485,32 @@ selectButton = {-| Selects one out of multiple options. This can be used for radio buttons or Menus. + + import Widget.Material as Material + import Material.Icons as MaterialIcons + import Element + + type Msg + = ChangedSelected Int + + { selected = Just 1 + , options = + [ 1, 2, 42 ] + |> List.map + (\int -> + { text = String.fromInt int + , icon = always Element.none + } + ) + , onSelect = (\i -> Just <| ChangedSelected i) + } + |> Widget.select + |> Widget.buttonRow + { elementRow = Material.buttonRow + , content = Material.toggleButton Material.defaultPalette + } + |> always "Ignore this line" --> "Ignore this line" + -} select : Select msg @@ -421,6 +520,33 @@ select = {-| Selects multible options. This can be used for checkboxes. + + import Widget.Material as Material + import Material.Icons as MaterialIcons + import Set + import Element + + type Msg + = ChangedSelected Int + + { selected = [1,2] |> Set.fromList + , options = + [ 1, 2, 42 ] + |> List.map + (\int -> + { text = String.fromInt int + , icon = always Element.none + } + ) + , onSelect = (\i -> Just <| ChangedSelected i) + } + |> Widget.multiSelect + |> Widget.buttonRow + { elementRow = Material.buttonRow + , content = Material.toggleButton Material.defaultPalette + } + |> always "Ignore this line" --> "Ignore this line" + -} multiSelect : MultiSelect msg @@ -468,6 +594,22 @@ type alias Dialog msg = {-| A modal. + import Widget.Material as Material + import Element + + type Msg + = Submit + | Close + + Element.layout + (modal + { onDismiss = Just Close + , content = + Element.text "Click outside this window to close it." + } + ) + |> always "Ignore this line" --> "Ignore this line" + Technical Remark: - To stop the screen from scrolling, set the height of the layout to the height of the screen. @@ -479,6 +621,32 @@ modal = {-| A Dialog Window. + + import Widget.Material as Material + import Element + + type Msg + = Submit + | Close + + Element.layout + (dialog (Material.alertDialog Material.defaultPalette) + { title = Just "Accept" + , text = "Are you sure?" + , accept = + { text = "Accept" + , onPress = Just Submit + } + |> Just + , dismiss = + { text = "Cancel" + , onPress = Just Close + } + |> Just + } + ) + |> always "Ignore this line" --> "Ignore this line" + -} dialog : DialogStyle msg diff --git a/tests/VerifyExamples/Widget/Button0.elm b/tests/VerifyExamples/Widget/Button0.elm new file mode 100644 index 0000000..b200e86 --- /dev/null +++ b/tests/VerifyExamples/Widget/Button0.elm @@ -0,0 +1,37 @@ +module VerifyExamples.Widget.Button0 exposing (..) + +-- This file got generated by [elm-verify-examples](https://github.com/stoeffel/elm-verify-examples). +-- Please don't modify this file by hand! + +import Test +import Expect + +import Widget exposing (..) +import Widget.Icon as Icon +import Material.Icons.Types exposing (Coloring(..)) +import Material.Icons as MaterialIcons +import Widget.Material as Material + +type Msg + = Submit + + + + + +spec0 : Test.Test +spec0 = + Test.test "#button: \n\n button (Material.containedButton Material.defaultPalette)\n { text = \"Submit\"\n , icon = MaterialIcons.favorite |> Icon.elmMaterialIcons Color\n , onPress = Just Submit\n }\n |> always \"Ignore this line\"\n --> \"Ignore this line\"" <| + \() -> + Expect.equal + ( + button (Material.containedButton Material.defaultPalette) + { text = "Submit" + , icon = MaterialIcons.favorite |> Icon.elmMaterialIcons Color + , onPress = Just Submit + } + |> always "Ignore this line" + ) + ( + "Ignore this line" + ) \ No newline at end of file diff --git a/tests/VerifyExamples/Widget/Dialog0.elm b/tests/VerifyExamples/Widget/Dialog0.elm new file mode 100644 index 0000000..778ea2b --- /dev/null +++ b/tests/VerifyExamples/Widget/Dialog0.elm @@ -0,0 +1,47 @@ +module VerifyExamples.Widget.Dialog0 exposing (..) + +-- This file got generated by [elm-verify-examples](https://github.com/stoeffel/elm-verify-examples). +-- Please don't modify this file by hand! + +import Test +import Expect + +import Widget exposing (..) +import Element +import Widget.Material as Material + +type Msg + = Submit + | Close + + + + + +spec0 : Test.Test +spec0 = + Test.test "#dialog: \n\n Element.layout\n (dialog (Material.alertDialog Material.defaultPalette)\n { title = Just \"Accept\"\n , text = \"Are you sure?\"\n , accept =\n { text = \"Accept\"\n , onPress = Just Submit\n }\n |> Just\n , dismiss =\n { text = \"Cancel\"\n , onPress = Just Close\n }\n |> Just\n }\n )\n |> always \"Ignore this line\"\n --> \"Ignore this line\"" <| + \() -> + Expect.equal + ( + Element.layout + (dialog (Material.alertDialog Material.defaultPalette) + { title = Just "Accept" + , text = "Are you sure?" + , accept = + { text = "Accept" + , onPress = Just Submit + } + |> Just + , dismiss = + { text = "Cancel" + , onPress = Just Close + } + |> Just + } + ) + |> always "Ignore this line" + ) + ( + "Ignore this line" + ) \ No newline at end of file diff --git a/tests/VerifyExamples/Widget/IconButton0.elm b/tests/VerifyExamples/Widget/IconButton0.elm new file mode 100644 index 0000000..57e9dbe --- /dev/null +++ b/tests/VerifyExamples/Widget/IconButton0.elm @@ -0,0 +1,37 @@ +module VerifyExamples.Widget.IconButton0 exposing (..) + +-- This file got generated by [elm-verify-examples](https://github.com/stoeffel/elm-verify-examples). +-- Please don't modify this file by hand! + +import Test +import Expect + +import Widget exposing (..) +import Widget.Icon as Icon +import Material.Icons.Types exposing (Coloring(..)) +import Material.Icons as MaterialIcons +import Widget.Material as Material + +type Msg + = Like + + + + + +spec0 : Test.Test +spec0 = + Test.test "#iconButton: \n\n iconButton (Material.iconButton Material.defaultPalette)\n { text = \"Like\"\n , icon = MaterialIcons.favorite |> Icon.elmMaterialIcons Color\n , onPress = Just Like\n }\n |> always \"Ignore this line\"\n --> \"Ignore this line\"" <| + \() -> + Expect.equal + ( + iconButton (Material.iconButton Material.defaultPalette) + { text = "Like" + , icon = MaterialIcons.favorite |> Icon.elmMaterialIcons Color + , onPress = Just Like + } + |> always "Ignore this line" + ) + ( + "Ignore this line" + ) \ No newline at end of file diff --git a/tests/VerifyExamples/Widget/Modal0.elm b/tests/VerifyExamples/Widget/Modal0.elm new file mode 100644 index 0000000..3bbe168 --- /dev/null +++ b/tests/VerifyExamples/Widget/Modal0.elm @@ -0,0 +1,38 @@ +module VerifyExamples.Widget.Modal0 exposing (..) + +-- This file got generated by [elm-verify-examples](https://github.com/stoeffel/elm-verify-examples). +-- Please don't modify this file by hand! + +import Test +import Expect + +import Widget exposing (..) +import Element +import Widget.Material as Material + +type Msg + = Submit + | Close + + + + + +spec0 : Test.Test +spec0 = + Test.test "#modal: \n\n Element.layout\n (modal\n { onDismiss = Just Close\n , content =\n Element.text \"Click outside this window to close it.\"\n }\n )\n |> always \"Ignore this line\"\n --> \"Ignore this line\"" <| + \() -> + Expect.equal + ( + Element.layout + (modal + { onDismiss = Just Close + , content = + Element.text "Click outside this window to close it." + } + ) + |> always "Ignore this line" + ) + ( + "Ignore this line" + ) \ No newline at end of file diff --git a/tests/VerifyExamples/Widget/MultiSelect0.elm b/tests/VerifyExamples/Widget/MultiSelect0.elm new file mode 100644 index 0000000..907d0e1 --- /dev/null +++ b/tests/VerifyExamples/Widget/MultiSelect0.elm @@ -0,0 +1,48 @@ +module VerifyExamples.Widget.MultiSelect0 exposing (..) + +-- This file got generated by [elm-verify-examples](https://github.com/stoeffel/elm-verify-examples). +-- Please don't modify this file by hand! + +import Test +import Expect + +import Widget exposing (..) +import Element +import Set +import Material.Icons as MaterialIcons +import Widget.Material as Material + +type Msg + = ChangedSelected Int + + + + + +spec0 : Test.Test +spec0 = + Test.test "#multiSelect: \n\n { selected = [1,2] |> Set.fromList\n , options =\n [ 1, 2, 42 ]\n |> List.map\n (\\int ->\n { text = String.fromInt int\n , icon = always Element.none\n }\n )\n , onSelect = (\\i -> Just <| ChangedSelected i)\n }\n |> Widget.multiSelect\n |> Widget.buttonRow\n { elementRow = Material.buttonRow\n , content = Material.toggleButton Material.defaultPalette\n }\n |> always \"Ignore this line\"\n --> \"Ignore this line\"" <| + \() -> + Expect.equal + ( + { selected = [1,2] |> Set.fromList + , options = + [ 1, 2, 42 ] + |> List.map + (\int -> + { text = String.fromInt int + , icon = always Element.none + } + ) + , onSelect = (\i -> Just <| ChangedSelected i) + } + |> Widget.multiSelect + |> Widget.buttonRow + { elementRow = Material.buttonRow + , content = Material.toggleButton Material.defaultPalette + } + |> always "Ignore this line" + ) + ( + "Ignore this line" + ) \ No newline at end of file diff --git a/tests/VerifyExamples/Widget/Select0.elm b/tests/VerifyExamples/Widget/Select0.elm new file mode 100644 index 0000000..ddfced8 --- /dev/null +++ b/tests/VerifyExamples/Widget/Select0.elm @@ -0,0 +1,47 @@ +module VerifyExamples.Widget.Select0 exposing (..) + +-- This file got generated by [elm-verify-examples](https://github.com/stoeffel/elm-verify-examples). +-- Please don't modify this file by hand! + +import Test +import Expect + +import Widget exposing (..) +import Element +import Material.Icons as MaterialIcons +import Widget.Material as Material + +type Msg + = ChangedSelected Int + + + + + +spec0 : Test.Test +spec0 = + Test.test "#select: \n\n { selected = Just 1\n , options =\n [ 1, 2, 42 ]\n |> List.map\n (\\int ->\n { text = String.fromInt int\n , icon = always Element.none\n }\n )\n , onSelect = (\\i -> Just <| ChangedSelected i)\n }\n |> Widget.select\n |> Widget.buttonRow\n { elementRow = Material.buttonRow\n , content = Material.toggleButton Material.defaultPalette\n }\n |> always \"Ignore this line\"\n --> \"Ignore this line\"" <| + \() -> + Expect.equal + ( + { selected = Just 1 + , options = + [ 1, 2, 42 ] + |> List.map + (\int -> + { text = String.fromInt int + , icon = always Element.none + } + ) + , onSelect = (\i -> Just <| ChangedSelected i) + } + |> Widget.select + |> Widget.buttonRow + { elementRow = Material.buttonRow + , content = Material.toggleButton Material.defaultPalette + } + |> always "Ignore this line" + ) + ( + "Ignore this line" + ) \ No newline at end of file diff --git a/tests/VerifyExamples/Widget/SelectButton0.elm b/tests/VerifyExamples/Widget/SelectButton0.elm new file mode 100644 index 0000000..6bb0cd2 --- /dev/null +++ b/tests/VerifyExamples/Widget/SelectButton0.elm @@ -0,0 +1,47 @@ +module VerifyExamples.Widget.SelectButton0 exposing (..) + +-- This file got generated by [elm-verify-examples](https://github.com/stoeffel/elm-verify-examples). +-- Please don't modify this file by hand! + +import Test +import Expect + +import Widget exposing (..) +import Element +import Material.Icons as MaterialIcons +import Widget.Material as Material + +type Msg + = ChangedSelected Int + + + + + +spec0 : Test.Test +spec0 = + Test.test "#selectButton: \n\n { selected = Just 1\n , options =\n [ 1, 2, 42 ]\n |> List.map\n (\\int ->\n { text = String.fromInt int\n , icon = always Element.none\n }\n )\n , onSelect = (\\i -> Just <| ChangedSelected i)\n }\n |> Widget.select\n |> Widget.buttonRow\n { elementRow = Material.buttonRow\n , content = Material.toggleButton Material.defaultPalette\n }\n |> always \"Ignore this line\"\n --> \"Ignore this line\"" <| + \() -> + Expect.equal + ( + { selected = Just 1 + , options = + [ 1, 2, 42 ] + |> List.map + (\int -> + { text = String.fromInt int + , icon = always Element.none + } + ) + , onSelect = (\i -> Just <| ChangedSelected i) + } + |> Widget.select + |> Widget.buttonRow + { elementRow = Material.buttonRow + , content = Material.toggleButton Material.defaultPalette + } + |> always "Ignore this line" + ) + ( + "Ignore this line" + ) \ No newline at end of file diff --git a/tests/VerifyExamples/Widget/Switch0.elm b/tests/VerifyExamples/Widget/Switch0.elm new file mode 100644 index 0000000..3cc30f9 --- /dev/null +++ b/tests/VerifyExamples/Widget/Switch0.elm @@ -0,0 +1,35 @@ +module VerifyExamples.Widget.Switch0 exposing (..) + +-- This file got generated by [elm-verify-examples](https://github.com/stoeffel/elm-verify-examples). +-- Please don't modify this file by hand! + +import Test +import Expect + +import Widget exposing (..) +import Material.Icons as MaterialIcons +import Widget.Material as Material + +type Msg + = Activate + + + + + +spec0 : Test.Test +spec0 = + Test.test "#switch: \n\n switch (Material.switch Material.defaultPalette)\n { description = \"Activate Dark Mode\"\n , onPress = Just Activate\n , active = False\n }\n |> always \"Ignore this line\"\n --> \"Ignore this line\"" <| + \() -> + Expect.equal + ( + switch (Material.switch Material.defaultPalette) + { description = "Activate Dark Mode" + , onPress = Just Activate + , active = False + } + |> always "Ignore this line" + ) + ( + "Ignore this line" + ) \ No newline at end of file diff --git a/tests/VerifyExamples/Widget/TextButton0.elm b/tests/VerifyExamples/Widget/TextButton0.elm new file mode 100644 index 0000000..52f24cd --- /dev/null +++ b/tests/VerifyExamples/Widget/TextButton0.elm @@ -0,0 +1,34 @@ +module VerifyExamples.Widget.TextButton0 exposing (..) + +-- This file got generated by [elm-verify-examples](https://github.com/stoeffel/elm-verify-examples). +-- Please don't modify this file by hand! + +import Test +import Expect + +import Widget exposing (..) +import Material.Icons as MaterialIcons +import Widget.Material as Material + +type Msg + = Like + + + + + +spec0 : Test.Test +spec0 = + Test.test "#textButton: \n\n textButton (Material.textButton Material.defaultPalette)\n { text = \"Like\"\n , onPress = Just Like\n }\n |> always \"Ignore this line\"\n --> \"Ignore this line\"" <| + \() -> + Expect.equal + ( + textButton (Material.textButton Material.defaultPalette) + { text = "Like" + , onPress = Just Like + } + |> always "Ignore this line" + ) + ( + "Ignore this line" + ) \ No newline at end of file diff --git a/tests/elm-verify-examples.json b/tests/elm-verify-examples.json index 891385d..f1e9491 100644 --- a/tests/elm-verify-examples.json +++ b/tests/elm-verify-examples.json @@ -2,10 +2,10 @@ "root": "../src", "tests": [ "Widget", - "Widget.Style.Material", - "Widget.Style.Material.Typography", - "Widget.Style.Material.Color", - "Widget.Style.Customize", + "Widget.Material", + "Widget.Material.Typography", + "Widget.Material.Color", + "Widget.Customize", "Widget.Layout", "Widget.ScrollingNav", "Widget.Snackbar",