|
| 1 | +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +import 'dart:convert'; |
| 6 | + |
| 7 | +import 'package:http/http.dart' as http; |
| 8 | +import 'package:pub_integration/src/fake_test_context_provider.dart'; |
| 9 | +import 'package:pub_integration/src/test_browser.dart'; |
| 10 | +import 'package:test/test.dart'; |
| 11 | + |
| 12 | +void main() { |
| 13 | + group('theme switch', () { |
| 14 | + late final TestContextProvider fakeTestScenario; |
| 15 | + final httpClient = http.Client(); |
| 16 | + |
| 17 | + setUpAll(() async { |
| 18 | + fakeTestScenario = await TestContextProvider.start(); |
| 19 | + }); |
| 20 | + |
| 21 | + tearDownAll(() async { |
| 22 | + await fakeTestScenario.close(); |
| 23 | + httpClient.close(); |
| 24 | + }); |
| 25 | + |
| 26 | + test('bulk tests', () async { |
| 27 | + final origin = fakeTestScenario.pubHostedUrl; |
| 28 | + // Importing one package + local analysis |
| 29 | + await httpClient.post(Uri.parse('$origin/fake-test-profile'), |
| 30 | + body: json.encode({ |
| 31 | + 'testProfile': { |
| 32 | + 'defaultUser': '[email protected]', |
| 33 | + 'packages': [ |
| 34 | + {'name': 'oxygen'} |
| 35 | + ], |
| 36 | + }, |
| 37 | + 'analysis': 'local', |
| 38 | + })); |
| 39 | + |
| 40 | + final user = await fakeTestScenario.createAnonymousTestUser(); |
| 41 | + |
| 42 | + // test keyboard navigation |
| 43 | + await user.withBrowserPage((page) async { |
| 44 | + await page.gotoOrigin('/experimental?dark=1'); |
| 45 | + |
| 46 | + Future<void> expectDarkTheme() async { |
| 47 | + expect(await page.$OrNull('body.light-theme'), isNull); |
| 48 | + expect(await page.$OrNull('body.dark-theme'), isNotNull); |
| 49 | + } |
| 50 | + |
| 51 | + Future<void> expectLightTheme() async { |
| 52 | + expect(await page.$OrNull('body.light-theme'), isNotNull); |
| 53 | + expect(await page.$OrNull('body.dark-theme'), isNull); |
| 54 | + } |
| 55 | + |
| 56 | + // baseline check |
| 57 | + await page.gotoOrigin('/'); |
| 58 | + await expectLightTheme(); |
| 59 | + await page.gotoOrigin('/documentation/oxygen/latest/'); |
| 60 | + await expectLightTheme(); |
| 61 | + |
| 62 | + // switch to dark on dartdoc page |
| 63 | + await page.click('#theme-button'); |
| 64 | + await expectDarkTheme(); |
| 65 | + await page.gotoOrigin('/'); |
| 66 | + await expectDarkTheme(); |
| 67 | + |
| 68 | + // switch to light on dartdoc page |
| 69 | + await page.gotoOrigin('/documentation/oxygen/latest/'); |
| 70 | + await expectDarkTheme(); |
| 71 | + await page.click('#theme-button'); |
| 72 | + await expectLightTheme(); |
| 73 | + await page.gotoOrigin('/'); |
| 74 | + await expectLightTheme(); |
| 75 | + |
| 76 | + // switch to dark on the pub.dev page |
| 77 | + await page.click('button.-pub-theme-toggle'); |
| 78 | + await expectDarkTheme(); |
| 79 | + await page.gotoOrigin('/documentation/oxygen/latest/'); |
| 80 | + await expectDarkTheme(); |
| 81 | + |
| 82 | + // switch to light on the pub.dev page |
| 83 | + await page.gotoOrigin('/'); |
| 84 | + await expectDarkTheme(); |
| 85 | + await page.click('button.-pub-theme-toggle'); |
| 86 | + await expectLightTheme(); |
| 87 | + await page.gotoOrigin('/documentation/oxygen/latest/'); |
| 88 | + await expectLightTheme(); |
| 89 | + }); |
| 90 | + }); |
| 91 | + }, timeout: Timeout.factor(testTimeoutFactor)); |
| 92 | +} |
0 commit comments