Repository: microsoft/playwright
File: tests/library/browsercontext-timezone-id.spec.ts (TypeScript)

Code before:
 * Copyright 2018 Google Inc. All rights reserved.
 * Modifications copyright (c) Microsoft Corporation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { browserTest as it, expect } from '../config/browserTest';

it('should work @smoke', async ({ browser, browserName }) => {
  // Note: timezone names are rendered differently between browsers and platforms,
  // so we only check the GMT offset.
  const func = () => new Date(1479579154987).toString();
  {
    const context = await browser.newContext({ locale: 'en-US', timezoneId: 'America/Jamaica' });
    const page = await context.newPage();
    expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 13:12:34 GMT-0500');
    await context.close();
  }
  {
    const context = await browser.newContext({ locale: 'en-US', timezoneId: 'Pacific/Honolulu' });
    const page = await context.newPage();
    expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 08:12:34 GMT-1000');
    await context.close();
  }
  {
    const context = await browser.newContext({ locale: 'en-US', timezoneId: browserName === 'firefox' ? 'America/Argentina/Buenos_Aires' : 'America/Buenos_Aires' });
    const page = await context.newPage();
    expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 15:12:34 GMT-0300');
    await context.close();
  }
  {
    const context = await browser.newContext({ locale: 'en-US', timezoneId: 'Europe/Berlin' });
    const page = await context.newPage();
    expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 19:12:34 GMT+0100');
    await context.close();
  }
});

it('should throw for invalid timezone IDs when creating pages', async ({ browser, channel, browserName, isBidi }) => {
  for (const timezoneId of ['Foo/Bar', 'Baz/Qux']) {
    if (isBidi) {

Review comment (suggestion):
```suggestion
    expect(await page.evaluate(func)).toContain('Sat Nov 19 2016 13:12:34 GMT-0500');
```

Code after:
 * Copyright 2018 Google Inc. All rights reserved.
 * Modifications copyright (c) Microsoft Corporation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { browserTest as it, expect } from '../config/browserTest';

it('should work @smoke', async ({ browser, browserName }) => {
  // Note: timezone names are rendered differently between browsers and platforms,
  // so we only check the GMT offset.
  const func = () => new Date(1479579154987).toString();
  {
    const context = await browser.newContext({ locale: 'en-US', timezoneId: 'America/Jamaica' });
    const page = await context.newPage();
    expect(await page.evaluate(func)).toContain('Sat Nov 19 2016 13:12:34 GMT-0500');
    await context.close();
  }
  {
    const context = await browser.newContext({ locale: 'en-US', timezoneId: 'Pacific/Honolulu' });
    const page = await context.newPage();
    expect(await page.evaluate(func)).toContain('Sat Nov 19 2016 08:12:34 GMT-1000');
    await context.close();
  }
  {
    const context = await browser.newContext({ locale: 'en-US', timezoneId: browserName === 'firefox' ? 'America/Argentina/Buenos_Aires' : 'America/Buenos_Aires' });
    const page = await context.newPage();
    expect(await page.evaluate(func)).toContain('Sat Nov 19 2016 15:12:34 GMT-0300');
    await context.close();
  }
  {
    const context = await browser.newContext({ locale: 'en-US', timezoneId: 'Europe/Berlin' });
    const page = await context.newPage();
    expect(await page.evaluate(func)).toContain('Sat Nov 19 2016 19:12:34 GMT+0100');
    await context.close();
  }
});

it('should throw for invalid timezone IDs when creating pages', async ({ browser, channel, browserName, isBidi }) => {
  for (const timezoneId of ['Foo/Bar', 'Baz/Qux']) {
    if (isBidi) {