2022-01-28 09:42:31 +01:00
|
|
|
import test, { expect, Page } from '@playwright/test'
|
|
|
|
import { importTypebotInDatabase } from '../../services/database'
|
|
|
|
import path from 'path'
|
|
|
|
import { typebotViewer } from '../../services/selectorUtils'
|
2022-03-18 12:30:42 +01:00
|
|
|
import cuid from 'cuid'
|
2022-01-28 09:42:31 +01:00
|
|
|
|
|
|
|
test.describe.parallel('Google sheets integration', () => {
|
|
|
|
test('Insert row should work', async ({ page }) => {
|
2022-03-18 12:30:42 +01:00
|
|
|
const typebotId = cuid()
|
2022-01-28 09:42:31 +01:00
|
|
|
await importTypebotInDatabase(
|
|
|
|
path.join(
|
|
|
|
__dirname,
|
|
|
|
'../../fixtures/typebots/integrations/googleSheets.json'
|
|
|
|
),
|
|
|
|
{
|
|
|
|
id: typebotId,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
await page.goto(`/typebots/${typebotId}/edit`)
|
|
|
|
await fillInSpreadsheetInfo(page)
|
|
|
|
await page.click('text=Select an operation')
|
|
|
|
await page.click('text=Insert a row')
|
|
|
|
|
2022-02-02 08:05:02 +01:00
|
|
|
await page.click('text=Add a value')
|
2022-01-28 09:42:31 +01:00
|
|
|
await page.click('text=Select a column')
|
2022-02-02 08:05:02 +01:00
|
|
|
await page.click('button >> text="Email"')
|
2022-01-28 09:42:31 +01:00
|
|
|
await page.click('[aria-label="Insert a variable"]')
|
2022-02-02 08:05:02 +01:00
|
|
|
await page.click('button >> text="Email" >> nth=1')
|
2022-01-28 09:42:31 +01:00
|
|
|
|
|
|
|
await page.click('text=Add a value')
|
|
|
|
await page.click('text=Select a column')
|
|
|
|
await page.click('text=First name')
|
|
|
|
await page.fill(
|
|
|
|
'input[placeholder="Type a value..."] >> nth = 1',
|
|
|
|
'Georges'
|
|
|
|
)
|
|
|
|
|
|
|
|
await page.click('text=Preview')
|
|
|
|
await typebotViewer(page)
|
|
|
|
.locator('input[placeholder="Type your email..."]')
|
|
|
|
.fill('georges@gmail.com')
|
2022-10-02 10:34:13 +02:00
|
|
|
await Promise.all([
|
|
|
|
page.waitForResponse(
|
|
|
|
(resp) =>
|
|
|
|
resp
|
|
|
|
.request()
|
|
|
|
.url()
|
|
|
|
.includes(
|
|
|
|
'/api/integrations/google-sheets/spreadsheets/1k_pIDw3YHl9tlZusbBVSBRY0PeRPd2H6t4Nj7rwnOtM/sheets/0'
|
|
|
|
) &&
|
|
|
|
resp.status() === 200 &&
|
|
|
|
resp.request().method() === 'POST'
|
|
|
|
),
|
|
|
|
typebotViewer(page)
|
|
|
|
.locator('input[placeholder="Type your email..."]')
|
|
|
|
.press('Enter'),
|
|
|
|
])
|
2022-01-28 09:42:31 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
test('Update row should work', async ({ page }) => {
|
2022-03-18 12:30:42 +01:00
|
|
|
const typebotId = cuid()
|
2022-01-28 09:42:31 +01:00
|
|
|
await importTypebotInDatabase(
|
|
|
|
path.join(
|
|
|
|
__dirname,
|
|
|
|
'../../fixtures/typebots/integrations/googleSheets.json'
|
|
|
|
),
|
|
|
|
{
|
|
|
|
id: typebotId,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
await page.goto(`/typebots/${typebotId}/edit`)
|
|
|
|
await fillInSpreadsheetInfo(page)
|
|
|
|
await page.click('text=Select an operation')
|
|
|
|
await page.click('text=Update a row')
|
|
|
|
|
2022-02-02 08:05:02 +01:00
|
|
|
await page.click('text=Add a value')
|
2022-01-28 09:42:31 +01:00
|
|
|
await page.click('text=Select a column')
|
2022-02-02 08:05:02 +01:00
|
|
|
await page.click('button >> text="Email"')
|
2022-01-28 09:42:31 +01:00
|
|
|
await page.click('[aria-label="Insert a variable"]')
|
2022-02-02 08:05:02 +01:00
|
|
|
await page.click('button >> text="Email" >> nth=1')
|
2022-01-28 09:42:31 +01:00
|
|
|
|
2022-02-02 08:05:02 +01:00
|
|
|
await page.click('text=Add a value')
|
2022-01-28 09:42:31 +01:00
|
|
|
await page.click('text=Select a column')
|
|
|
|
await page.click('text=Last name')
|
|
|
|
await page.fill(
|
|
|
|
'input[placeholder="Type a value..."] >> nth = 1',
|
|
|
|
'Last name'
|
|
|
|
)
|
|
|
|
|
|
|
|
await page.click('text=Preview')
|
|
|
|
await typebotViewer(page)
|
|
|
|
.locator('input[placeholder="Type your email..."]')
|
|
|
|
.fill('test@test.com')
|
2022-10-02 10:34:13 +02:00
|
|
|
await Promise.all([
|
|
|
|
page.waitForResponse(
|
|
|
|
(resp) =>
|
|
|
|
resp
|
|
|
|
.request()
|
|
|
|
.url()
|
|
|
|
.includes(
|
|
|
|
'/api/integrations/google-sheets/spreadsheets/1k_pIDw3YHl9tlZusbBVSBRY0PeRPd2H6t4Nj7rwnOtM/sheets/0'
|
|
|
|
) &&
|
|
|
|
resp.status() === 200 &&
|
|
|
|
resp.request().method() === 'PATCH'
|
|
|
|
),
|
|
|
|
typebotViewer(page)
|
|
|
|
.locator('input[placeholder="Type your email..."]')
|
|
|
|
.press('Enter'),
|
|
|
|
])
|
2022-01-28 09:42:31 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
test('Get row should work', async ({ page }) => {
|
2022-03-18 12:30:42 +01:00
|
|
|
const typebotId = cuid()
|
2022-01-28 09:42:31 +01:00
|
|
|
await importTypebotInDatabase(
|
|
|
|
path.join(
|
|
|
|
__dirname,
|
|
|
|
'../../fixtures/typebots/integrations/googleSheetsGet.json'
|
|
|
|
),
|
|
|
|
{
|
|
|
|
id: typebotId,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
await page.goto(`/typebots/${typebotId}/edit`)
|
|
|
|
await fillInSpreadsheetInfo(page)
|
|
|
|
await page.click('text=Select an operation')
|
|
|
|
await page.click('text=Get data from sheet')
|
|
|
|
|
|
|
|
await page.click('text=Select a column')
|
2022-02-02 08:05:02 +01:00
|
|
|
await page.click('button >> text="Email"')
|
2022-01-28 09:42:31 +01:00
|
|
|
await page.click('[aria-label="Insert a variable"]')
|
2022-02-02 08:05:02 +01:00
|
|
|
await page.click('button >> text="Email" >> nth=1')
|
2022-01-28 09:42:31 +01:00
|
|
|
|
2022-02-02 08:05:02 +01:00
|
|
|
await page.click('text=Add a value')
|
2022-01-28 09:42:31 +01:00
|
|
|
await page.click('text=Select a column')
|
|
|
|
await page.click('text="First name"')
|
|
|
|
await createNewVar(page, 'First name')
|
|
|
|
|
|
|
|
await page.click('text=Add a value')
|
|
|
|
await page.click('text=Select a column')
|
|
|
|
await page.click('text="Last name"')
|
|
|
|
await createNewVar(page, 'Last name')
|
|
|
|
|
|
|
|
await page.click('text=Preview')
|
|
|
|
await typebotViewer(page)
|
|
|
|
.locator('input[placeholder="Type your email..."]')
|
|
|
|
.fill('test2@test.com')
|
|
|
|
await typebotViewer(page)
|
|
|
|
.locator('input[placeholder="Type your email..."]')
|
|
|
|
.press('Enter')
|
|
|
|
await expect(
|
|
|
|
typebotViewer(page).locator('text=Your name is: John Smith')
|
2022-02-04 19:00:08 +01:00
|
|
|
).toBeVisible({ timeout: 30000 })
|
2022-01-28 09:42:31 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
const fillInSpreadsheetInfo = async (page: Page) => {
|
|
|
|
await page.click('text=Configure...')
|
|
|
|
await page.click('text=Select an account')
|
2022-04-20 10:05:33 -07:00
|
|
|
await page.click('text=pro-user@email.com')
|
2022-01-28 09:42:31 +01:00
|
|
|
|
|
|
|
await page.fill('input[placeholder="Search for spreadsheet"]', 'CR')
|
|
|
|
await page.click('text=CRM')
|
|
|
|
|
|
|
|
await page.fill('input[placeholder="Select the sheet"]', 'Sh')
|
|
|
|
await page.click('text=Sheet1')
|
|
|
|
}
|
|
|
|
|
|
|
|
const createNewVar = async (page: Page, name: string) => {
|
|
|
|
await page.fill('input[placeholder="Select a variable"] >> nth=-1', name)
|
|
|
|
await page.click(`text=Create "${name}"`)
|
|
|
|
}
|