Skip to content

Commit ad10217

Browse files
committed
.#59 Add Tests for TailWindCSS add-on
1 parent fa3d84f commit ad10217

File tree

2 files changed

+129
-2
lines changed

2 files changed

+129
-2
lines changed

cmd/create_test.go

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,4 +874,130 @@ var _ = Describe("Create template", func() {
874874
Expect(content).NotTo(ContainSubstring(expectedContent))
875875
})
876876
})
877+
878+
Context("given tailwind add-on", func() {
879+
It("contains lib/web/assets/stylesheets/vendors/tailwind folder", func() {
880+
cookiecutter := tests.Cookiecutter{
881+
Variant: tests.Web,
882+
CssAddon: tests.Tailwind,
883+
}
884+
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
885+
_, err := os.Stat("lib/web/assets/stylesheets/vendors/tailwind")
886+
887+
Expect(os.IsNotExist(err)).To(BeFalse())
888+
})
889+
890+
It("contains tailwind.config.js file", func() {
891+
cookiecutter := tests.Cookiecutter{
892+
Variant: tests.Web,
893+
CssAddon: tests.Tailwind,
894+
}
895+
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
896+
_, err := os.Stat("tailwind.config.js")
897+
898+
Expect(os.IsNotExist(err)).To(BeFalse())
899+
})
900+
901+
It("contains tailwind package in package.json", func() {
902+
cookiecutter := tests.Cookiecutter{
903+
Variant: tests.Web,
904+
CssAddon: tests.Tailwind,
905+
}
906+
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
907+
content := tests.ReadFile("package.json")
908+
909+
expectedContent := "\"tailwindcss\": \"2.2.7\""
910+
911+
Expect(content).To(ContainSubstring(expectedContent))
912+
})
913+
914+
It("contains tailwind scss import in lib/web/assets/stylesheets/application.scss", func() {
915+
cookiecutter := tests.Cookiecutter{
916+
Variant: tests.Web,
917+
CssAddon: tests.Tailwind,
918+
}
919+
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
920+
content := tests.ReadFile("lib/web/assets/stylesheets/application.scss")
921+
922+
expectedContent := "@import \"./vendors/tailwind\";"
923+
924+
Expect(content).To(ContainSubstring(expectedContent))
925+
})
926+
927+
It("contains tailwind requirement in postcss.config.js", func() {
928+
cookiecutter := tests.Cookiecutter{
929+
Variant: tests.Web,
930+
CssAddon: tests.Tailwind,
931+
}
932+
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
933+
content := tests.ReadFile("postcss.config.js")
934+
935+
expectedContent := "require(\"tailwindcss\")"
936+
937+
Expect(content).To(ContainSubstring(expectedContent))
938+
})
939+
})
940+
941+
Context("given NO tailwind add-on", func() {
942+
It("does NOT contain lib/web/assets/stylesheets/vendors/tailwind folder", func() {
943+
cookiecutter := tests.Cookiecutter{
944+
Variant: tests.Web,
945+
CssAddon: tests.None,
946+
}
947+
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
948+
_, err := os.Stat("lib/web/assets/stylesheets/vendors/tailwind")
949+
950+
Expect(os.IsNotExist(err)).To(BeTrue())
951+
})
952+
953+
It("does NOT contain tailwind.config.js file", func() {
954+
cookiecutter := tests.Cookiecutter{
955+
Variant: tests.Web,
956+
CssAddon: tests.None,
957+
}
958+
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
959+
_, err := os.Stat("tailwind.config.js")
960+
961+
Expect(os.IsNotExist(err)).To(BeTrue())
962+
})
963+
964+
It("does NOT contain tailwind package in package.json", func() {
965+
cookiecutter := tests.Cookiecutter{
966+
Variant: tests.Web,
967+
CssAddon: tests.None,
968+
}
969+
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
970+
content := tests.ReadFile("package.json")
971+
972+
expectedContent := "\"tailwindcss\":"
973+
974+
Expect(content).NotTo(ContainSubstring(expectedContent))
975+
})
976+
977+
It("does NOT contain tailwind scss import in lib/web/assets/stylesheets/application.scss", func() {
978+
cookiecutter := tests.Cookiecutter{
979+
Variant: tests.Web,
980+
CssAddon: tests.None,
981+
}
982+
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
983+
content := tests.ReadFile("lib/web/assets/stylesheets/application.scss")
984+
985+
expectedContent := "@import \"./vendors/tailwind\";"
986+
987+
Expect(content).NotTo(ContainSubstring(expectedContent))
988+
})
989+
990+
It("does NOT contain tailwind requirement in postcss.config.js", func() {
991+
cookiecutter := tests.Cookiecutter{
992+
Variant: tests.Web,
993+
CssAddon: tests.None,
994+
}
995+
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
996+
content := tests.ReadFile("postcss.config.js")
997+
998+
expectedContent := "require(\"tailwindcss\")"
999+
1000+
Expect(content).NotTo(ContainSubstring(expectedContent))
1001+
})
1002+
})
8771003
})

tests/cookiecutter.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const (
1919
Both Variants = "3"
2020

2121
Bootstrap CssAddons = "1"
22-
None CssAddons = "2"
22+
Tailwind CssAddons = "2"
23+
None CssAddons = "3"
2324
)
2425

2526
// Field and order MUST be the same as cookiecutter.json
@@ -44,7 +45,7 @@ func (c *Cookiecutter) fillDefaultValue() {
4445
c.UseHeroku = No
4546
}
4647

47-
if c.CssAddon != Bootstrap && c.CssAddon != None {
48+
if c.CssAddon != Bootstrap && c.CssAddon != Tailwind && c.CssAddon != None {
4849
c.CssAddon = None
4950
}
5051

0 commit comments

Comments
 (0)