oh-my-posh/src/segment_angular_test.go

40 lines
1.2 KiB
Go
Raw Normal View History

2021-10-13 00:05:29 -07:00
package main
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestAngularCliVersionDisplayed(t *testing.T) {
cases := []struct {
Case string
ExpectedString string
Version string
}{
{Case: "Angular 13.0.3", ExpectedString: "13.0.3", Version: "{ \"name\": \"@angular/core\",\"version\": \"13.0.3\"}"},
{Case: "Angular 11.0.1", ExpectedString: "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(MockedEnvironment)
// mock getVersion methods
2022-01-20 04:35:46 -08:00
env.On("pwd").Return("/usr/home/dev/my-app")
env.On("homeDir").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("getFileContent", "/usr/home/dev/my-app/node_modules/@angular/core/package.json").Return(ta.Version)
env.onTemplate()
2022-01-01 11:08:08 -08:00
props := properties{}
2021-10-13 00:05:29 -07:00
angular := &angular{}
angular.init(props, env)
assert.True(t, angular.enabled(), fmt.Sprintf("Failed in case: %s", ta.Case))
assert.Equal(t, ta.ExpectedString, angular.string(), fmt.Sprintf("Failed in case: %s", ta.Case))
}
}