Skip to content

Commit

Permalink
Merge pull request #655 from trheyi/main
Browse files Browse the repository at this point in the history
chore: Update local build test to remove files before building
  • Loading branch information
trheyi committed Jul 5, 2024
2 parents bde2243 + 4f3f835 commit 1a623fe
Showing 1 changed file with 112 additions and 5 deletions.
117 changes: 112 additions & 5 deletions sui/storages/local/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,25 @@ func TestTemplateBuild(t *testing.T) {
t.Fatalf("GetTemplate error: %v", err)
}

err = tmpl.Build(&core.BuildOption{SSR: true})
root := application.App.Root()
public := tmpl.(*Template).local.GetPublic()
path := filepath.Join(root, "public", public.Root)

// Remove files and directories in Public directory if exists
err = os.RemoveAll(path)
if err != nil && !os.IsNotExist(err) {
t.Fatalf("RemoveAll error: %v", err)
}

err = tmpl.Build(&core.BuildOption{SSR: true, ExecScripts: true})
if err != nil {
t.Fatalf("Components error: %v", err)
}

index := "/index.sui"

// Check SUI
root := application.App.Root()
public := tmpl.(*Template).local.GetPublic()
path := filepath.Join(root, "public", public.Root)
assert.FileExists(t, filepath.Join(path, index))

content, err := os.ReadFile(filepath.Join(path, index))
if err != nil {
t.Fatalf("ReadFile error: %v", err)
Expand All @@ -54,6 +60,16 @@ func TestTemplateBuildAsComponent(t *testing.T) {
t.Fatalf("GetTemplate error: %v", err)
}

root := application.App.Root()
public := tmpl.(*Template).local.GetPublic()
path := filepath.Join(root, "public", public.Root)

// Remove files and directories in Public directory if exists
err = os.RemoveAll(path)
if err != nil && !os.IsNotExist(err) {
t.Fatalf("RemoveAll error: %v", err)
}

err = tmpl.Build(&core.BuildOption{SSR: true})
if err != nil {
t.Fatalf("Components error: %v", err)
Expand All @@ -63,9 +79,100 @@ func TestTemplateBuildAsComponent(t *testing.T) {
cinput := "/flowbite/components/edit/input.jit"

// Check JIT
assert.FileExists(t, filepath.Join(path, cselect))
assert.FileExists(t, filepath.Join(path, cinput))

content, err := os.ReadFile(filepath.Join(path, cselect))
if err != nil {
t.Fatalf("ReadFile error: %v", err)
}

assert.NotContains(t, string(content), "body")
assert.NotContains(t, string(content), `<script name="config" type="json">`)
assert.NotContains(t, string(content), `<script name="data" type="json">`)
assert.NotContains(t, string(content), `<script name="global" type="json">`)
assert.Contains(t, string(content), "function Init()")
assert.Contains(t, string(content), `type="flowbite-edit-select"`)
}

func TestPageBuild(t *testing.T) {
tests := prepare(t)
defer clean()

tmpl, err := tests.Test.GetTemplate("advanced")
if err != nil {
t.Fatalf("GetTemplate error: %v", err)
}

root := application.App.Root()
public := tmpl.(*Template).local.GetPublic()
path := filepath.Join(root, "public", public.Root)

// Remove files and directories in Public directory if exists
err = os.RemoveAll(path)
if err != nil && !os.IsNotExist(err) {
t.Fatalf("RemoveAll error: %v", err)
}

page, err := tmpl.Page("/index")
if err != nil {
t.Fatalf("Page error: %v", err)
}

err = page.Build(nil, &core.BuildOption{SSR: true})
if err != nil {
t.Fatalf("Page Build error: %v", err)
}
index := "/index.sui"

// Check SUI
assert.FileExists(t, filepath.Join(path, index))

content, err := os.ReadFile(filepath.Join(path, index))
if err != nil {
t.Fatalf("ReadFile error: %v", err)
}

assert.Contains(t, string(content), "body")
assert.Contains(t, string(content), `<script src="/unit-test/assets/js/import.js"></script>`)
assert.Contains(t, string(content), `<script name="config" type="json">`)
assert.Contains(t, string(content), `<script name="data" type="json">`)
assert.Contains(t, string(content), `<script name="global" type="json">`)
}

func TestPageBuildAsComponent(t *testing.T) {
tests := prepare(t)
defer clean()

tmpl, err := tests.Web.GetTemplate("default")
if err != nil {
t.Fatalf("GetTemplate error: %v", err)
}

root := application.App.Root()
public := tmpl.(*Template).local.GetPublic()
path := filepath.Join(root, "public", public.Root)

// Remove files and directories in Public directory if exists
err = os.RemoveAll(path)
if err != nil && !os.IsNotExist(err) {
t.Fatalf("RemoveAll error: %v", err)
}

page, err := tmpl.Page("/[form]")
if err != nil {
t.Fatalf("Page error: %v", err)
}

err = page.Build(nil, &core.BuildOption{SSR: true})
if err != nil {
t.Fatalf("Components error: %v", err)
}

cselect := "/flowbite/components/edit/select.jit"
cinput := "/flowbite/components/edit/input.jit"

// Check JIT
assert.FileExists(t, filepath.Join(path, cselect))
assert.FileExists(t, filepath.Join(path, cinput))

Expand Down

0 comments on commit 1a623fe

Please sign in to comment.