|
1 | 1 | defmodule ExCSSModules.ViewTest do |
2 | 2 | @example_stylesheet __ENV__.file |
3 | | - |> Path.dirname |
| 3 | + |> Path.dirname() |
4 | 4 | |> Path.join("../support/stylesheet.css") |
5 | 5 |
|
6 | 6 | use ExUnit.Case |
7 | 7 |
|
8 | | - defmodule ViewModuleTest do |
9 | | - use ExCSSModules.View, stylesheet: __ENV__.file |
10 | | - |> Path.dirname |
11 | | - |> Path.join("../support/stylesheet.css") |
| 8 | + defmodule ViewModule.Test do |
| 9 | + use ExCSSModules.View, |
| 10 | + stylesheet: |
| 11 | + __ENV__.file |
| 12 | + |> Path.dirname() |
| 13 | + |> Path.join("../support/stylesheet.css") |
12 | 14 | end |
13 | 15 |
|
14 | | - defmodule EmbeddedViewModuleTest do |
15 | | - use ExCSSModules.View, stylesheet: __ENV__.file |
16 | | - |> Path.dirname |
17 | | - |> Path.join("../support/stylesheet.css"), |
18 | | - embed_stylesheet: true |
| 16 | + defmodule ViewModule.Embedded.Test do |
| 17 | + use ExCSSModules.View, |
| 18 | + stylesheet: |
| 19 | + __ENV__.file |
| 20 | + |> Path.dirname() |
| 21 | + |> Path.join("../support/stylesheet.css"), |
| 22 | + embed_stylesheet: true |
| 23 | + end |
| 24 | + |
| 25 | + defmodule ViewModule.StylesheetDefinitions.EmptyObject.Test do |
| 26 | + use ExCSSModules.View, |
| 27 | + stylesheet: |
| 28 | + __ENV__.file |
| 29 | + |> Path.dirname() |
| 30 | + |> Path.join("../support/stylesheet_definitions_with_empty_object.css") |
| 31 | + end |
| 32 | + |
| 33 | + defmodule ViewModule.StylesheetDefinitions.EmptyFile.Test do |
| 34 | + use ExCSSModules.View, |
| 35 | + stylesheet: |
| 36 | + __ENV__.file |
| 37 | + |> Path.dirname() |
| 38 | + |> Path.join("../support/empty_file.css") |
| 39 | + end |
| 40 | + |
| 41 | + defmodule ViewModule.StylesheetDefinitions.NoFile.Test do |
| 42 | + use ExCSSModules.View, |
| 43 | + stylesheet: |
| 44 | + __ENV__.file |
| 45 | + |> Path.dirname() |
| 46 | + |> Path.join("../support/no_stylesheet_definitions.css") |
19 | 47 | end |
20 | 48 |
|
21 | 49 | describe "stylesheet_definition/0" do |
22 | 50 | test "gets the stylesheet string" do |
23 | | - assert ViewModuleTest.stylesheet_definition |
24 | | - == Path.expand(@example_stylesheet) |
| 51 | + assert ViewModule.Test.stylesheet_definition() == |
| 52 | + Path.expand(@example_stylesheet) |
25 | 53 | end |
26 | 54 |
|
27 | 55 | test "gets the embedded stylesheet" do |
28 | | - assert EmbeddedViewModuleTest.stylesheet_definition |
29 | | - == ExCSSModules.stylesheet(@example_stylesheet) |
| 56 | + assert ViewModule.Embedded.Test.stylesheet_definition() == |
| 57 | + ExCSSModules.stylesheet(@example_stylesheet) |
30 | 58 | end |
31 | 59 | end |
32 | 60 |
|
33 | 61 | describe "stylesheet/0" do |
34 | 62 | test "calls the stylesheet" do |
35 | | - assert ViewModuleTest.stylesheet |
36 | | - == ExCSSModules.stylesheet(@example_stylesheet) |
| 63 | + assert ViewModule.Test.stylesheet() == |
| 64 | + ExCSSModules.stylesheet(@example_stylesheet) |
| 65 | + end |
| 66 | + |
| 67 | + test "returns an empty map if the stylesheet definitions json file contains just an empty object" do |
| 68 | + assert ViewModule.StylesheetDefinitions.EmptyObject.Test.stylesheet() == %{} |
| 69 | + end |
| 70 | + |
| 71 | + test "raises if the stylesheet definitions json file is empty" do |
| 72 | + message = |
| 73 | + """ |
| 74 | + test/support/empty_file.css.json: File is empty. |
| 75 | + Error compiling ExCSSModules: Remove the file and/or (re)build your style definitions JSON files before compiling your application. |
| 76 | + """ |
| 77 | + |
| 78 | + assert_raise(CompileError, message, fn -> |
| 79 | + ViewModule.StylesheetDefinitions.EmptyFile.Test.stylesheet() |
| 80 | + end) |
| 81 | + end |
| 82 | + |
| 83 | + test "raises if the stylesheet definitions json file does not exist" do |
| 84 | + message = |
| 85 | + """ |
| 86 | + test/support/no_stylesheet_definitions.css.json: File does not exist. |
| 87 | + Error compiling ExCSSModules: Be sure to build your style definitions JSON files before compiling your application. |
| 88 | + """ |
| 89 | + |
| 90 | + assert_raise(CompileError, message, fn -> |
| 91 | + ViewModule.StylesheetDefinitions.NoFile.Test.stylesheet() |
| 92 | + end) |
37 | 93 | end |
38 | 94 | end |
39 | 95 |
|
40 | 96 | describe "class_selector/1" do |
41 | 97 | test "prepends the class_name with a dot" do |
42 | | - assert ViewModuleTest.class_selector("title") == |
43 | | - ExCSSModules.class_selector(@example_stylesheet, "title") |
| 98 | + assert ViewModule.Test.class_selector("title") == |
| 99 | + ExCSSModules.class_selector(@example_stylesheet, "title") |
44 | 100 | end |
45 | 101 | end |
46 | 102 |
|
47 | 103 | describe "class_name/1" do |
48 | 104 | test "calls the css/2 method on ExCSSModules" do |
49 | | - assert ViewModuleTest.class_name("title") == |
50 | | - ExCSSModules.class_name(@example_stylesheet, "title") |
| 105 | + assert ViewModule.Test.class_name("title") == |
| 106 | + ExCSSModules.class_name(@example_stylesheet, "title") |
51 | 107 | end |
52 | 108 | end |
53 | 109 |
|
54 | 110 | describe "class_name/2" do |
55 | 111 | test "calls the css/3 method on ExCSSModules" do |
56 | | - assert ViewModuleTest.class_name("title", true) == |
57 | | - ExCSSModules.class_name(@example_stylesheet, "title", true) |
58 | | - assert ViewModuleTest.class_name("title", false) == |
59 | | - ExCSSModules.class_name(@example_stylesheet, "title", false) |
| 112 | + assert ViewModule.Test.class_name("title", true) == |
| 113 | + ExCSSModules.class_name(@example_stylesheet, "title", true) |
| 114 | + |
| 115 | + assert ViewModule.Test.class_name("title", false) == |
| 116 | + ExCSSModules.class_name(@example_stylesheet, "title", false) |
60 | 117 | end |
61 | 118 | end |
62 | 119 |
|
63 | 120 | describe "class/1" do |
64 | 121 | test "calls the class/2 method on ExCSSModules" do |
65 | | - assert ViewModuleTest.class("title") == |
66 | | - ExCSSModules.class(@example_stylesheet, "title") |
| 122 | + assert ViewModule.Test.class("title") == |
| 123 | + ExCSSModules.class(@example_stylesheet, "title") |
67 | 124 | end |
68 | 125 | end |
69 | 126 |
|
70 | 127 | describe "class/2" do |
71 | 128 | test "calls the class/3 method on ExCSSModules" do |
72 | | - assert ViewModuleTest.class("title", true) == |
73 | | - ExCSSModules.class(@example_stylesheet, "title", true) |
74 | | - assert ViewModuleTest.class("title", false) == |
75 | | - ExCSSModules.class(@example_stylesheet, "title", false) |
| 129 | + assert ViewModule.Test.class("title", true) == |
| 130 | + ExCSSModules.class(@example_stylesheet, "title", true) |
| 131 | + |
| 132 | + assert ViewModule.Test.class("title", false) == |
| 133 | + ExCSSModules.class(@example_stylesheet, "title", false) |
76 | 134 | end |
77 | 135 | end |
78 | 136 | end |
0 commit comments