|
| 1 | +import { browser, expect } from "@wdio/globals"; |
| 2 | +import { |
| 3 | + ExecutionPanel, |
| 4 | + HistoryItem, |
| 5 | +} from "../../utils/page_objects/execution"; |
| 6 | +import { firebaseSuite, firebaseTest } from "../../utils/test_hooks"; |
| 7 | +import { EditorView } from "../../utils/page_objects/editor"; |
| 8 | +import { |
| 9 | + mockProject, |
| 10 | + mutationsPath, |
| 11 | + queriesPath, |
| 12 | + queryWithFragmentPath, |
| 13 | +} from "../../utils/projects"; |
| 14 | +import { FirebaseCommands } from "../../utils/page_objects/commands"; |
| 15 | +import { FirebaseSidebar } from "../../utils/page_objects/sidebar"; |
| 16 | +import { mockUser } from "../../utils/user"; |
| 17 | +import { Workbench, Notification } from "wdio-vscode-service"; |
| 18 | +import { Notifications } from "../../utils/page_objects/notifications"; |
| 19 | +import path from "path"; |
| 20 | + |
| 21 | +firebaseSuite("Execution", async function () { |
| 22 | + firebaseTest( |
| 23 | + "should be able to start emulator and execute operation", |
| 24 | + async function () { |
| 25 | + const workbench = await browser.getWorkbench(); |
| 26 | + |
| 27 | + const sidebar = new FirebaseSidebar(workbench); |
| 28 | + await sidebar.openExtensionSidebar(); |
| 29 | + |
| 30 | + const commands = new FirebaseCommands(); |
| 31 | + await commands.waitForUser(); |
| 32 | + |
| 33 | + await mockUser({ email: "[email protected]" }); |
| 34 | + await mockProject("test-project"); |
| 35 | + |
| 36 | + const execution = new ExecutionPanel(workbench); |
| 37 | + const editor = new EditorView(workbench); |
| 38 | + |
| 39 | + // Click run local while emulator is not started |
| 40 | + await editor.openFile(mutationsPath); |
| 41 | + await editor.runLocalButton.waitForDisplayed(); |
| 42 | + await editor.runLocalButton.click(); |
| 43 | + |
| 44 | + // get start emulator notification |
| 45 | + const notificationUtil = new Notifications(workbench); |
| 46 | + const startEmulatorsNotif = |
| 47 | + await notificationUtil.getStartEmulatorNotification(); |
| 48 | + expect(startEmulatorsNotif).toExist(); |
| 49 | + |
| 50 | + console.log( |
| 51 | + "Starting emulators from local execution. Waiting for emulators to start...", |
| 52 | + ); |
| 53 | + |
| 54 | + await commands.waitForEmulators(); |
| 55 | + |
| 56 | + const current = await sidebar.currentEmulators(); |
| 57 | + expect(current).toContain("dataconnect :9399"); |
| 58 | + await browser.pause(4000); // strange case where emulators are showing before actually callable |
| 59 | + |
| 60 | + // Test 1 - Execute adhoc read data |
| 61 | + |
| 62 | + // Open the schema file |
| 63 | + const schemaFilePath = path.join( |
| 64 | + __dirname, |
| 65 | + "..", |
| 66 | + "..", |
| 67 | + "test_projects", |
| 68 | + "fishfood", |
| 69 | + "dataconnect", |
| 70 | + "schema", |
| 71 | + "schema.gql", |
| 72 | + ); |
| 73 | + await editor.openFile(schemaFilePath); |
| 74 | + |
| 75 | + // Verify that inline Read Data button is displayed |
| 76 | + const readDataButton = await editor.readDataButton; |
| 77 | + await readDataButton.waitForDisplayed(); |
| 78 | + |
| 79 | + // Click the Read Data button |
| 80 | + await readDataButton.click(); |
| 81 | + |
| 82 | + // Wait a bit for the query to be generated |
| 83 | + await browser.pause(5000); |
| 84 | + |
| 85 | + // Verify the generated query |
| 86 | + const activeEditor = await editor.getActiveEditor(); |
| 87 | + const editorTitle = activeEditor?.document.fileName.split("/").pop(); |
| 88 | + const editorContent = await editor.activeEditorContent(); |
| 89 | + |
| 90 | + expect(editorContent).toHaveText(`query { |
| 91 | + posts{ |
| 92 | + id |
| 93 | + content |
| 94 | + } |
| 95 | +}`); |
| 96 | + // file should be created, saved, then opened |
| 97 | + expect(activeEditor?.document.isDirty).toBe(false); |
| 98 | + |
| 99 | + await editor.runLocalButton.waitForDisplayed(); |
| 100 | + await editor.runLocalButton.click(); |
| 101 | + |
| 102 | + async function getExecutionStatus(name: string) { |
| 103 | + await browser.pause(1000); |
| 104 | + let item = await execution.history.getSelectedItem(); |
| 105 | + let status = await item.getStatus(); |
| 106 | + let label = await item.getLabel(); |
| 107 | + while (status === "pending" && label !== name) { |
| 108 | + await browser.pause(1000); |
| 109 | + item = await execution.history.getSelectedItem(); |
| 110 | + status = await item.getStatus(); |
| 111 | + } |
| 112 | + return item; |
| 113 | + } |
| 114 | + |
| 115 | + // Check the history entry |
| 116 | + const item3 = await getExecutionStatus("anonymous"); |
| 117 | + expect(await item3.getLabel()).toBe("anonymous"); |
| 118 | + expect(await item3.getStatus()).toBe("success"); |
| 119 | + await editor.closeAllEditors(); |
| 120 | + }, |
| 121 | + ); |
| 122 | +}); |
0 commit comments