Skip to content

Commit

Permalink
tests: MediaByContentTypeQuery tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nikcio committed May 5, 2024
1 parent 9548423 commit b05d1a1
Show file tree
Hide file tree
Showing 18 changed files with 1,143 additions and 9 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ query MediaAtRootQuery(
items {
url(urlMode: ABSOLUTE)
properties {
...typedProperties
...customMediaType
__typename
}
urlSegment
Expand All @@ -70,7 +70,7 @@ query MediaAtRootQuery(
parent {
url(urlMode: ABSOLUTE)
properties {
...typedProperties
...customMediaType
__typename
}
urlSegment
Expand All @@ -87,5 +87,5 @@ query MediaAtRootQuery(
hasNextPage
}
}
""" + Fragments.TypedProperties;
""" + Fragments.CustomMediaType;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System.Net.Http.Json;

namespace Nikcio.UHeadless.IntegrationTests.Defaults;

public partial class ApiTests
{
private const string _mediaByContentTypeSnapshotPath = $"{SnapshotConstants.BasePath}/MediaByContentType";

[Theory]
[InlineData("image", 1, 0, true)]
[InlineData("folder", 1, 0, true)]
[InlineData("customMediaType", 1, 10, true)]
[InlineData("image", 1, 1, true)]
[InlineData("image", 2, 1, true)]
[InlineData("image", 1, 1000, true)]
[InlineData("image", 1000, 1000, true)]
[InlineData("image", 1, 5, true)]
[InlineData("image", 0, 5, false)]
[InlineData("image", -1, 5, false)]
[InlineData("image", 0, -1, false)]
[InlineData("", 1, 1, false)]
public async Task MediaByContentTypeQuery_Snaps_Async(
string contentType,
int page,
int pageSize,
bool expectSuccess)
{
var snapshotProvider = new SnapshotProvider($"{_mediaByContentTypeSnapshotPath}/Snaps");
HttpClient client = _factory.CreateClient();

using var request = JsonContent.Create(new
{
query = MediaByContentTypeQueries.GetItems,
variables = new
{
contentType,
page,
pageSize,
}
});

HttpResponseMessage response = await client.PostAsync("/graphql", request).ConfigureAwait(true);

string responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(true);

string snapshotName = $"MediaByContentType_Snaps_{contentType}_{page}_{pageSize}";

await snapshotProvider.AssertIsSnapshotEqualAsync(snapshotName, responseContent).ConfigureAwait(true);
Assert.Equal(expectSuccess, response.IsSuccessStatusCode);
}
}

public static class MediaByContentTypeQueries
{
public const string GetItems = """
query MediaAtRootQuery(
$contentType: String!
$page: Int!,
$pageSize: Int!
) {
mediaByContentType(
contentType: $contentType
page: $page,
pageSize: $pageSize
) {
items {
url(urlMode: ABSOLUTE)
properties {
...customMediaType
__typename
}
urlSegment
name
id
key
templateId
parent {
url(urlMode: ABSOLUTE)
properties {
...customMediaType
__typename
}
urlSegment
name
id
key
templateId
}
__typename
}
page
pageSize
totalItems
hasNextPage
}
}
""" + Fragments.CustomMediaType;
}
211 changes: 210 additions & 1 deletion src/Nikcio.UHeadless.IntegrationTests/Fragments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Nikcio.UHeadless.IntegrationTests;
public static class Fragments
{
/// <summary>
/// This is meant to select as many properties as possiable to give the best image of changes in the output from the tests.
/// This is meant to select as many properties as possible to give the best image of changes in the output from the tests.
/// </summary>
public const string TypedProperties = """
fragment typedProperties on TypedProperties {
Expand Down Expand Up @@ -766,7 +766,204 @@ ... on IEmailAddressEditorCulture {
}
__typename
}
""" + TypedContentProperties + TypedImageProperties + TypedBlockGridContent + TypedBlockGridSettings + TypedBlockListContent + TypedBlockListSettings + TypedMemberProperties;

/// <summary>
/// Used to select properties from the custom media type.
/// </summary>
public const string CustomMediaType = """
fragment customMediaType on ICustomMediaType {
eyeDropperColorPicker {
value
model
__typename
}
article {
value
model
__typename
}
audio {
value
model
__typename
}
file {
value
model
__typename
}
video {
value
model
__typename
}
imageCropper {
value
model
__typename
}
imageMediaPicker {
mediaItems {
url(urlMode: ABSOLUTE)
properties {
...typedImageProperties
__typename
}
urlSegment
name
id
key
__typename
}
model
__typename
}
blockList {
blocks {
contentAlias
settingsAlias
contentProperties {
...typedBlockListContent
__typename
}
settingsProperties {
...typedBlockListSettings
__typename
}
__typename
}
model
__typename
}
memberGroupPicker {
value
model
__typename
}
memberPicker {
members {
properties {
...typedMemberProperties
__typename
}
name
id
key
__typename
}
model
__typename
}
multinodeTreepicker {
items {
url(urlMode: ABSOLUTE)
properties {
...typedContentProperties
__typename
}
urlSegment
name
id
key
__typename
}
model
__typename
}
multiUrlPicker {
links {
url(urlMode: ABSOLUTE)
properties {
...typedContentProperties
__typename
}
urlSegment
target
type
name
id
key
__typename
}
model
__typename
}
numeric {
value
model
__typename
}
radiobox {
value
model
__typename
}
checkboxList {
value
model
__typename
}
slider {
value
model
__typename
}
tags {
value
model
__typename
}
textarea {
value
model
__typename
}
textstring {
value
model
__typename
}
userPicker {
value
model
__typename
}
contentPicker {
items {
url(urlMode: ABSOLUTE)
properties {
...typedContentProperties
__typename
}
urlSegment
name
id
key
__typename
}
model
__typename
}
datePickerWithTime {
value
model
__typename
}
decimal {
value
model
__typename
}
emailAddress {
value
model
__typename
}
}
""" + TypedContentProperties + TypedImageProperties + TypedBlockGridContent + TypedBlockGridSettings + TypedBlockListContent + TypedBlockListSettings + TypedMemberProperties;

private const string TypedContentProperties = """
fragment typedContentProperties on TypedProperties {
... on IBlockGridEditor {
blockGrid {
Expand Down Expand Up @@ -1521,7 +1718,9 @@ ... on IEmailAddressEditorCulture {
}
__typename
}
""";

private const string TypedImageProperties = """
fragment typedImageProperties on TypedProperties {
... on IImage {
umbracoWidth {
Expand All @@ -1547,7 +1746,9 @@ ... on IImage {
__typename
}
}
""";

private const string TypedBlockGridContent = """
fragment typedBlockGridContent on TypedBlockGridContentProperties {
... on IUmbBlockGridDemoHeadlineBlock {
headline {
Expand Down Expand Up @@ -1585,7 +1786,9 @@ ... on IUmbBlockGridDemoRichTextBlock {
__typename
}
}
""";

private const string TypedBlockGridSettings = """
fragment typedBlockGridSettings on TypedBlockGridSettingsProperties {
... on IUmbBlockGridDemoHeadlineBlock {
headline {
Expand Down Expand Up @@ -1623,7 +1826,9 @@ ... on IUmbBlockGridDemoRichTextBlock {
__typename
}
}
""";

private const string TypedBlockListContent = """
fragment typedBlockListContent on TypedBlockListContentProperties {
... on IBlockGridEditor {
blockGrid {
Expand Down Expand Up @@ -2402,7 +2607,9 @@ ... on ICheckboxListEditorCulture {
}
}
}
""";

private const string TypedBlockListSettings = """
fragment typedBlockListSettings on TypedBlockGridSettingsProperties {
... on IBlockGridEditor {
blockGrid {
Expand Down Expand Up @@ -3182,7 +3389,9 @@ ... on ICheckboxListEditorCulture {
}
__typename
}
""";

private const string TypedMemberProperties = """
fragment typedMemberProperties on TypedProperties {
... on ITestMember {
blockList {
Expand Down
Loading

0 comments on commit b05d1a1

Please sign in to comment.