|
1 |
| -import { expect, type Locator, type Page, test } from '@playwright/test'; |
| 1 | +import { expect, test } from '@playwright/test'; |
2 | 2 | import { buildSchema, graphqlSync } from 'graphql';
|
3 | 3 |
|
4 |
| -interface VoyagerURLSearchParams { |
5 |
| - url?: string; |
6 |
| - withCredential?: boolean; |
7 |
| -} |
8 |
| - |
9 |
| -async function gotoVoyagerPage( |
10 |
| - page: Page, |
11 |
| - searchParams?: VoyagerURLSearchParams, |
12 |
| -) { |
13 |
| - const search = new URLSearchParams(); |
14 |
| - if (searchParams?.url != null) { |
15 |
| - search.append('url', searchParams.url); |
16 |
| - } |
17 |
| - if (searchParams?.withCredential != null) { |
18 |
| - search.append('withCredential', searchParams.withCredential.toString()); |
19 |
| - } |
20 |
| - |
21 |
| - await page.goto('/?' + search.toString()); |
22 |
| - return new PlaywrightVoyagerPage(page); |
23 |
| -} |
24 |
| - |
25 |
| -class PlaywrightVoyagerPage { |
26 |
| - readonly page: Page; |
27 |
| - readonly graphLoadingAnimation: Locator; |
28 |
| - |
29 |
| - readonly changeSchemaDialog: PlaywrightChangeSchemaDialog; |
30 |
| - |
31 |
| - constructor(page: Page) { |
32 |
| - this.page = page; |
33 |
| - |
34 |
| - this.graphLoadingAnimation = page |
35 |
| - .getByRole('status') |
36 |
| - .getByText('Transmitting...'); |
37 |
| - |
38 |
| - this.changeSchemaDialog = new PlaywrightChangeSchemaDialog(page); |
39 |
| - } |
40 |
| - |
41 |
| - async waitForGraphToBeLoaded() { |
42 |
| - await this.graphLoadingAnimation.waitFor({ state: 'hidden' }); |
43 |
| - } |
44 |
| -} |
45 |
| - |
46 |
| -class PlaywrightChangeSchemaDialog { |
47 |
| - readonly dialog: Locator; |
48 |
| - readonly openButton: Locator; |
49 |
| - |
50 |
| - readonly presetsTab: PlaywrightChangeSchemaPresetsTab; |
51 |
| - readonly sdlTab: PlaywrightChangeSchemaSDLTab; |
52 |
| - readonly introspectionTab: PlaywrightChangeSchemaIntrospectionTab; |
53 |
| - |
54 |
| - readonly displayButton: Locator; |
55 |
| - readonly cancelButton: Locator; |
56 |
| - |
57 |
| - constructor(page: Page) { |
58 |
| - this.dialog = page.getByRole('dialog'); |
59 |
| - this.openButton = page.getByRole('button', { |
60 |
| - name: 'Change Schema', |
61 |
| - }); |
62 |
| - |
63 |
| - this.presetsTab = new PlaywrightChangeSchemaPresetsTab(this.dialog); |
64 |
| - this.sdlTab = new PlaywrightChangeSchemaSDLTab(this.dialog); |
65 |
| - this.introspectionTab = new PlaywrightChangeSchemaIntrospectionTab( |
66 |
| - this.dialog, |
67 |
| - ); |
68 |
| - |
69 |
| - this.displayButton = this.dialog.getByRole('button', { name: 'Display' }); |
70 |
| - this.cancelButton = this.dialog.getByRole('button', { name: 'Cancel' }); |
71 |
| - } |
72 |
| -} |
73 |
| - |
74 |
| -class PlaywrightChangeSchemaBaseTab { |
75 |
| - readonly tab: Locator; |
76 |
| - readonly tabPanel: Locator; |
77 |
| - |
78 |
| - constructor(dialog: Locator, name: string) { |
79 |
| - this.tab = dialog.getByRole('tab', { name }); |
80 |
| - this.tabPanel = dialog.getByRole('tabpanel', { name }); |
81 |
| - } |
82 |
| -} |
83 |
| - |
84 |
| -const SchemaPresets = [ |
85 |
| - 'Star Wars', |
86 |
| - 'Yelp', |
87 |
| - 'Shopify Storefront', |
88 |
| - 'GitHub', |
89 |
| -] as const; |
90 |
| -class PlaywrightChangeSchemaPresetsTab extends PlaywrightChangeSchemaBaseTab { |
91 |
| - readonly presetButtons: { [name in typeof SchemaPresets[number]]: Locator }; |
92 |
| - |
93 |
| - constructor(dialog: Locator) { |
94 |
| - super(dialog, 'Presets'); |
95 |
| - |
96 |
| - this.presetButtons = {} as any; |
97 |
| - for (const name of SchemaPresets) { |
98 |
| - this.presetButtons[name] = this.tabPanel.getByRole('button', { name }); |
99 |
| - } |
100 |
| - } |
101 |
| -} |
102 |
| - |
103 |
| -class PlaywrightChangeSchemaSDLTab extends PlaywrightChangeSchemaBaseTab { |
104 |
| - readonly sdlTextArea: Locator; |
105 |
| - |
106 |
| - constructor(dialog: Locator) { |
107 |
| - super(dialog, 'SDL'); |
108 |
| - |
109 |
| - this.sdlTextArea = this.tabPanel.getByPlaceholder('Paste SDL Here'); |
110 |
| - } |
111 |
| -} |
112 |
| - |
113 |
| -class PlaywrightChangeSchemaIntrospectionTab extends PlaywrightChangeSchemaBaseTab { |
114 |
| - readonly introspectionTextArea: Locator; |
115 |
| - readonly copyIntrospectionQueryButton: Locator; |
116 |
| - |
117 |
| - constructor(dialog: Locator) { |
118 |
| - super(dialog, 'Introspection'); |
119 |
| - |
120 |
| - this.introspectionTextArea = this.tabPanel.getByPlaceholder( |
121 |
| - 'Paste Introspection Here', |
122 |
| - ); |
123 |
| - this.copyIntrospectionQueryButton = this.tabPanel.getByRole('button', { |
124 |
| - name: 'Copied!', |
125 |
| - }); |
126 |
| - } |
127 |
| -} |
| 4 | +import { gotoVoyagerPage, SchemaPresets } from './PageObjectModel'; |
128 | 5 |
|
129 | 6 | test('open demo', async ({ page }) => {
|
130 | 7 | const voyagerPage = await gotoVoyagerPage(page);
|
|
0 commit comments