2022-01-26 06:54:36 -08:00
|
|
|
package segments
|
2021-10-13 00:05:29 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-01-26 01:23:18 -08:00
|
|
|
"oh-my-posh/environment"
|
|
|
|
"oh-my-posh/mock"
|
2022-01-26 04:53:35 -08:00
|
|
|
"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 {
|
2022-01-23 12:37:51 -08:00
|
|
|
Case string
|
|
|
|
FullVersion string
|
|
|
|
Version string
|
2021-10-13 00:05:29 -07:00
|
|
|
}{
|
2022-01-23 12:37:51 -08: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{
|
2021-12-06 22:27:28 -08:00
|
|
|
extension: "angular.json",
|
2021-10-13 00:05:29 -07:00
|
|
|
}
|
|
|
|
|
2022-01-26 01:23:18 -08:00
|
|
|
var env = new(mock.MockedEnvironment)
|
2021-12-06 22:27:28 -08:00
|
|
|
// mock getVersion methods
|
2022-01-23 12:37:51 -08:00
|
|
|
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)
|
2022-01-26 01:23:18 -08:00
|
|
|
env.On("TemplateCache").Return(&environment.TemplateCache{
|
2022-01-23 12:37:51 -08:00
|
|
|
Env: make(map[string]string),
|
|
|
|
})
|
2022-01-26 04:53:35 -08:00
|
|
|
props := properties.Map{}
|
2022-01-26 05:10:18 -08:00
|
|
|
angular := &Angular{}
|
2022-01-26 05:26:56 -08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|