DashboardControllerTests.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System.IO;
  2. using System.Net;
  3. using System.Net.Mime;
  4. using System.Text;
  5. using System.Text.Json;
  6. using System.Threading.Tasks;
  7. using Jellyfin.Api.Models;
  8. using MediaBrowser.Common.Json;
  9. using Xunit;
  10. namespace Jellyfin.Server.Integration.Tests.Controllers
  11. {
  12. public sealed class DashboardControllerTests : IClassFixture<JellyfinApplicationFactory>
  13. {
  14. private readonly JellyfinApplicationFactory _factory;
  15. private readonly JsonSerializerOptions _jsonOpions = JsonDefaults.GetOptions();
  16. public DashboardControllerTests(JellyfinApplicationFactory factory)
  17. {
  18. _factory = factory;
  19. }
  20. [Fact]
  21. public async Task GetDashboardConfigurationPage_NonExistingPage_NotFound()
  22. {
  23. var client = _factory.CreateClient();
  24. var response = await client.GetAsync("web/ConfigurationPage?name=ThisPageDoesntExists").ConfigureAwait(false);
  25. Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
  26. }
  27. [Fact]
  28. public async Task GetDashboardConfigurationPage_ExistingPage_CorrectPage()
  29. {
  30. var client = _factory.CreateClient();
  31. var response = await client.GetAsync("/web/ConfigurationPage?name=TestPlugin").ConfigureAwait(false);
  32. Assert.True(response.IsSuccessStatusCode);
  33. Assert.Equal(MediaTypeNames.Text.Html, response.Content.Headers.ContentType?.MediaType);
  34. StreamReader reader = new StreamReader(typeof(TestPlugin).Assembly.GetManifestResourceStream("Jellyfin.Server.Integration.Tests.TestPage.html")!);
  35. Assert.Equal(await response.Content.ReadAsStringAsync(), reader.ReadToEnd());
  36. }
  37. [Fact]
  38. public async Task GetDashboardConfigurationPage_BrokenPage_NotFound()
  39. {
  40. var client = _factory.CreateClient();
  41. var response = await client.GetAsync("/web/ConfigurationPage?name=BrokenPage").ConfigureAwait(false);
  42. Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
  43. }
  44. [Fact]
  45. public async Task GetConfigurationPages_NoParams_AllConfigurationPages()
  46. {
  47. var client = _factory.CreateClient();
  48. var response = await client.GetAsync("/web/ConfigurationPages").ConfigureAwait(false);
  49. Assert.True(response.IsSuccessStatusCode);
  50. var res = await response.Content.ReadAsStreamAsync();
  51. _ = await JsonSerializer.DeserializeAsync<ConfigurationPageInfo[]>(res, _jsonOpions);
  52. // TODO: check content
  53. }
  54. [Fact]
  55. public async Task GetConfigurationPages_True_MainMenuConfigurationPages()
  56. {
  57. var client = _factory.CreateClient();
  58. var response = await client.GetAsync("/web/ConfigurationPages?enableInMainMenu=true").ConfigureAwait(false);
  59. Assert.True(response.IsSuccessStatusCode);
  60. Assert.Equal(MediaTypeNames.Application.Json, response.Content.Headers.ContentType?.MediaType);
  61. Assert.Equal(Encoding.UTF8.BodyName, response.Content.Headers.ContentType?.CharSet);
  62. var res = await response.Content.ReadAsStreamAsync();
  63. var data = await JsonSerializer.DeserializeAsync<ConfigurationPageInfo[]>(res, _jsonOpions);
  64. Assert.Empty(data);
  65. }
  66. }
  67. }