Skip to content

Commit

Permalink
Test for adding image with transparent background
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinungf committed Dec 2, 2023
1 parent 47b58eb commit 16ac8de
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 31 additions & 2 deletions SpreadCheetah.Test/Tests/SpreadsheetImageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,37 @@ public async Task Spreadsheet_AddImage_Png()
Assert.Equal("Image 1", picture.Name);
}

[Fact]
public async Task Spreadsheet_AddImage_PngWithTransparentBackground()
{
// Arrange
const string reference = "B3";
using var pngStream = EmbeddedResources.GetStream("yellow-500x500-transparent.png");
using var outputStream = new MemoryStream();
await using var spreadsheet = await Spreadsheet.CreateNewAsync(outputStream);
var embeddedImage = await spreadsheet.EmbedImageAsync(pngStream);
await spreadsheet.StartWorksheetAsync("Sheet 1");
var canvas = ImageCanvas.OriginalSize(reference.AsSpan());

// Act
spreadsheet.AddImage(canvas, embeddedImage);

// Assert
await spreadsheet.FinishAsync();
SpreadsheetAssert.Valid(outputStream);

using var workbook = new XLWorkbook(outputStream);
var worksheet = Assert.Single(workbook.Worksheets);
var picture = Assert.Single(worksheet.Pictures);
Assert.Equal(reference, picture.TopLeftCell.Address.ToString());
Assert.Equal(XLPictureFormat.Png, picture.Format);
Assert.Equal(500, picture.OriginalWidth);
Assert.Equal(500, picture.OriginalHeight);
Assert.Equal(0, picture.Top);
Assert.Equal(0, picture.Left);
Assert.Equal("Image 1", picture.Name);
}

[Fact]
public async Task Spreadsheet_AddImage_PngWithLargeResolution()
{
Expand Down Expand Up @@ -690,6 +721,4 @@ public async Task Spreadsheet_AddImage_PngWithFillCellsAndOffsets(int left, int
Assert.Equal(expectedWidth, actualWidth);
Assert.Equal(expectedHeight, actualHeight);
}

// TODO: Test for transparent image
}

0 comments on commit 16ac8de

Please sign in to comment.