Escali License control 1
CommonComponentsTest.razor
Gå til dokumentasjonen til denne filen.
1@using Escali.LicenseControl.Client.Components
2@using Escali.LicenseControl.Client.Utils
3@using AutoMapper
4@using Microsoft.AspNetCore.Http
5@inject DbContext _db
6@inherits TestContext
7@inject AlertService _alertService
8@inject IComponent _componentBase
9@inject StateService _stateService
10@inject UserViewModel _userViewModel
11
12@code {
13
14 private void AddServices()
15 {
16 Services.AddDbContext<DataContext>();
17 Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
18 Services.AddScoped<StateService>();
19 Services.AddScoped<AlertService>();
20
21 Services.AddScoped<CurrencyViewModel>();
22 Services.AddScoped<ProductViewModel>();
23 Services.AddScoped<ModuleViewModel>();
24 Services.AddScoped<SegmentViewModel>();
25 Services.AddScoped<MainSegmentViewModel>();
26 Services.AddScoped<PriceListViewModel>();
27 Services.AddScoped<UserViewModel>();
28 Services.AddScoped<CustomerViewModel>();
29 Services.AddScoped<PriorityViewModel>();
30 Services.AddScoped<RegionViewModel>();
31 Services.AddScoped<PriceElementViewModel>();
32 Services.AddScoped<AgreementViewModel>();
33 Services.AddScoped<AgreementElementViewModel>();
34 Services.AddScoped<ModuleLevelViewModel>();
35 }
36 [Fact]
37 public void DropdownComponent_RenderSuccessfully()
38 {
39 var component = Render(@<Dropdown />
40 );
41 component.Find($".dropdown");
42 }
43
44 private (string, Action)[] CreateDropdownOptions(string context)
45 {
46 return new (string, Action)[] {
47 ("Oppdater modul", () => Console.WriteLine(context)),
48 };
49 }
50
51 [Fact]
52 public void DropdownComponentAdded_RenderSuccessfully()
53 {
54 string hello = "hello";
55 var component = RenderComponent<Dropdown>(parameters => parameters
56 .Add(p => p.Options, CreateDropdownOptions(hello))
57 );
58
59 component.FindAll("div").Count().Equals(3);
60 }
61
62 [Fact]
63 public void HeaderComponent_RenderSuccessfully()
64 {
65 AddServices();
66
67 var component = Render(
68 @<Header />
69 );
70 component.Find($".header");
71 }
72
73 [Fact]
74 public void StandardModalComponent_RenderSuccessfully()
75 {
76 var component = Render(
77 @<StandardModal ShowModal="true" Header="first" HeaderSecond="second" SubmitButtonName="submit"/>
78 );
79 component.Find($".modal-dialog");
80 }
81
82 [Fact]
83 public void StandardModalComponent_RenderSuccessfully_ButShowModalIsFalse()
84 {
85 var component = Render(
86 @<StandardModal ShowModal="false" />
87 );
88
89 component.MarkupMatches(string.Empty);
90 }
91
92 [Fact]
93 public void HeaderUserButtonComponent_RenderSuccessfully()
94 {
95 AddServices();
96 var component = Render(
97 @<HeaderUserButton />
98 );
99 component.Find($".button-menu-group");
100 }
101
102 [Fact]
103 public void HeaderUserButtonComponent_WithUsersList_RenderSuccessfully()
104 {
105 AddServices();
106 var options = new DbContextOptionsBuilder<DataContext>().UseInMemoryDatabase(databaseName: "db")
107 .Options;
108
109 using(var context = new DataContext(options))
110 {
111 context.Users.Add(new User { UserEmail = "user@user.com", UserConsulentName="user" });
112 context.Users.Add(new User { UserEmail = "simen@user.com", UserConsulentName="simen" });
113 context.SaveChanges();
114 }
115
116 using(var context = new DataContext(options))
117 {
118 var component = Render(@<HeaderUserButton />
119 );
120 component.FindAll("option").Count().Equals(3);
121 Assert.NotNull(context.Users);
122 }
123 }
124
125 [Fact]
126 public void TooltipComponent_RenderSuccessfully()
127 {
128 var component = Render(
129 @<Tooltip />
130 );
131 component.Find($".tooltip");
132 }
133
134
135
136}