|
| 1 | +using System.Threading.Tasks; |
| 2 | +using PuppeteerSharp.Media; |
| 3 | +using Xunit; |
| 4 | +using Xunit.Abstractions; |
| 5 | + |
| 6 | +namespace PuppeteerSharp.Tests.PageTests |
| 7 | +{ |
| 8 | + [Collection(TestConstants.TestFixtureCollectionName)] |
| 9 | + public class EmulateTimezoneTests : PuppeteerPageBaseTest |
| 10 | + { |
| 11 | + public EmulateTimezoneTests(ITestOutputHelper output) : base(output) |
| 12 | + { |
| 13 | + } |
| 14 | + |
| 15 | + [Fact] |
| 16 | + public async Task ShouldWork() |
| 17 | + { |
| 18 | + await Page.EvaluateExpressionAsync("globalThis.date = new Date(1479579154987);"); |
| 19 | + await Page.EmulateTimezoneAsync("America/Jamaica"); |
| 20 | + Assert.Equal( |
| 21 | + "Sat Nov 19 2016 13:12:34 GMT-0500 (Eastern Standard Time)", |
| 22 | + await Page.EvaluateExpressionAsync<string>("date.toString()")); |
| 23 | + |
| 24 | + await Page.EmulateTimezoneAsync("Pacific/Honolulu"); |
| 25 | + Assert.Equal( |
| 26 | + "Sat Nov 19 2016 08:12:34 GMT-1000 (Hawaii-Aleutian Standard Time)", |
| 27 | + await Page.EvaluateExpressionAsync<string>("date.toString()")); |
| 28 | + |
| 29 | + await Page.EmulateTimezoneAsync("America/Buenos_Aires"); |
| 30 | + Assert.Equal( |
| 31 | + "Sat Nov 19 2016 15:12:34 GMT-0300 (Argentina Standard Time)", |
| 32 | + await Page.EvaluateExpressionAsync<string>("date.toString()")); |
| 33 | + |
| 34 | + await Page.EmulateTimezoneAsync("Europe/Berlin"); |
| 35 | + Assert.Equal( |
| 36 | + "Sat Nov 19 2016 19:12:34 GMT+0100 (Central European Standard Time)", |
| 37 | + await Page.EvaluateExpressionAsync<string>("date.toString()")); |
| 38 | + } |
| 39 | + |
| 40 | + [Fact] |
| 41 | + public async Task ShouldThrowForInvalidTimezoneId() |
| 42 | + { |
| 43 | + var exception = await Assert.ThrowsAnyAsync<PuppeteerException>( |
| 44 | + () => Page.EmulateTimezoneAsync("Foo/Bar")); |
| 45 | + Assert.Contains("Invalid timezone ID: Foo/Bar", exception.Message); |
| 46 | + |
| 47 | + exception = await Assert.ThrowsAnyAsync<PuppeteerException>( |
| 48 | + () => Page.EmulateTimezoneAsync("Baz/Qux")); |
| 49 | + Assert.Contains("Invalid timezone ID: Baz/Qux", exception.Message); |
| 50 | + } |
| 51 | + } |
| 52 | +} |
0 commit comments