oh-my-posh/src/segments/angular_test.go

45 lines
1.4 KiB
Go
Raw Normal View History

2022-01-26 06:54:36 -08:00
package segments
2021-10-13 00:05:29 -07:00
import (
"fmt"
"oh-my-posh/environment"
"oh-my-posh/mock"
"oh-my-posh/properties"
2021-10-13 00:05:29 -07:00
"testing"
"github.com/stretchr/testify/assert"
)
func TestAngularCliVersionDisplayed(t *testing.T) {
cases := []struct {
Case string
FullVersion string
Version string
2021-10-13 00:05:29 -07:00
}{
{Case: "Angular 13.0.3", FullVersion: "13.0.3", Version: "{ \"name\": \"@angular/core\",\"version\": \"13.0.3\"}"},
{Case: "Angular 11.0.1", FullVersion: "11.0.1", Version: "{ \"name\": \"@angular/core\",\"version\": \"11.0.1\"}"},
2021-10-13 00:05:29 -07:00
}
for _, ta := range cases {
params := &mockedLanguageParams{
extension: "angular.json",
2021-10-13 00:05:29 -07:00
}
var env = new(mock.MockedEnvironment)
// mock getVersion methods
env.On("Pwd").Return("/usr/home/dev/my-app")
env.On("Home").Return("/usr/home")
env.On("HasFiles", params.extension).Return(true)
env.On("HasFilesInDir", "/usr/home/dev/my-app/node_modules/@angular/core", "package.json").Return(true)
env.On("FileContent", "/usr/home/dev/my-app/node_modules/@angular/core/package.json").Return(ta.Version)
env.On("TemplateCache").Return(&environment.TemplateCache{
Env: make(map[string]string),
})
props := properties.Map{}
2022-01-26 05:10:18 -08:00
angular := &Angular{}
angular.Init(props, env)
assert.True(t, angular.Enabled(), fmt.Sprintf("Failed in case: %s", ta.Case))
assert.Equal(t, ta.FullVersion, renderTemplate(env, angular.Template(), angular), fmt.Sprintf("Failed in case: %s", ta.Case))
2021-10-13 00:05:29 -07:00
}
}