Skip to content

Commit

Permalink
.#56 Add tests for bootstrap add-on
Browse files Browse the repository at this point in the history
  • Loading branch information
malparty committed Jul 20, 2021
1 parent 241f71d commit a2684ad
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
78 changes: 78 additions & 0 deletions cmd/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,4 +430,82 @@ var _ = Describe("Create template", func() {
Expect(content).NotTo(ContainSubstring(expectedContent))
})
})

Context("given bootstrap add-on", func() {
It("contains lib/web/assets/stylesheets/vendors/bootstrap folder", func() {
cookiecutter := tests.Cookiecutter{
Variant: tests.Web,
CssAddon: tests.Bootstrap,
}
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
_, err := os.Stat("lib/web/assets/stylesheets/vendors/bootstrap")

Expect(os.IsNotExist(err)).To(BeFalse())
})

It("contains bootstrap package in package.json", func() {
cookiecutter := tests.Cookiecutter{
Variant: tests.Web,
CssAddon: tests.Bootstrap,
}
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
content := tests.ReadFile("package.json")

expectedContent := "\"bootstrap\": \"5.0.2\""

Expect(content).To(ContainSubstring(expectedContent))
})

It("contains bootstrap scss import in lib/web/assets/stylesheets/application.scss", func() {
cookiecutter := tests.Cookiecutter{
Variant: tests.Web,
CssAddon: tests.Bootstrap,
}
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
content := tests.ReadFile("lib/web/assets/stylesheets/application.scss")

expectedContent := "@import \"./vendors/bootstrap\";"

Expect(content).To(ContainSubstring(expectedContent))
})
})

Context("given NO bootstrap add-on", func() {
It("does NOT contain lib/web/assets/stylesheets/vendors/bootstrap folder", func() {
cookiecutter := tests.Cookiecutter{
Variant: tests.Web,
CssAddon: tests.None,
}
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
_, err := os.Stat("lib/web/assets/stylesheets/vendors/bootstrap")

Expect(os.IsNotExist(err)).To(BeTrue())
})

It("does NOT contain bootstrap package in package.json", func() {
cookiecutter := tests.Cookiecutter{
Variant: tests.Web,
CssAddon: tests.None,
}
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
content := tests.ReadFile("package.json")

expectedContent := "\"bootstrap\": \"5.0.2\""

Expect(content).NotTo(ContainSubstring(expectedContent))
})

It("does NOT contain bootstrap scss import in lib/web/assets/stylesheets/application.scss", func() {
cookiecutter := tests.Cookiecutter{
Variant: tests.Web,
CssAddon: tests.None,
}
cookiecutter.CreateProjectFromGinTemplate(currentTemplatePath)
content := tests.ReadFile("lib/web/assets/stylesheets/application.scss")

expectedContent := "@import \"./vendors/bootstrap\";"

Expect(content).NotTo(ContainSubstring(expectedContent))
})
})
})
20 changes: 20 additions & 0 deletions tests/cookiecutter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,28 @@ import (
)

type Choices string
type Variants string
type CssAddons string

const (
Yes Choices = "1"
No Choices = "2"

API Variants = "1"
Web Variants = "2"
Both Variants = "3"

None CssAddons = "1"
Bootstrap CssAddons = "2"
Tailwind CssAddons = "3"
)

// Field and order MUST be the same as cookiecutter.json
type Cookiecutter struct {
AppName string
UseLogrus Choices
Variant Variants
CssAddon CssAddons
}

func (c *Cookiecutter) fillDefaultValue() {
Expand All @@ -27,6 +39,14 @@ func (c *Cookiecutter) fillDefaultValue() {
if c.UseLogrus != Yes && c.UseLogrus != No {
c.UseLogrus = No
}

if c.CssAddon != Bootstrap && c.CssAddon != Tailwind && c.CssAddon != None {
c.CssAddon = None
}

if c.Variant != API && c.Variant != Web && c.Variant != Both {
c.Variant = API
}
}

func (c *Cookiecutter) structToString() string {
Expand Down

0 comments on commit a2684ad

Please sign in to comment.