forked from tsai/budibase
63 changed files with 2230 additions and 932 deletions
@ -1,61 +1,194 @@ |
|||||
|
require("../../tests/utilities/dbConfig"); |
||||
const { |
const { |
||||
generateAppID, |
generateAppID, |
||||
getDevelopmentAppID, |
getDevelopmentAppID, |
||||
getProdAppID, |
getProdAppID, |
||||
isDevAppID, |
isDevAppID, |
||||
isProdAppID, |
isProdAppID, |
||||
|
getPlatformUrl, |
||||
|
getScopedConfig |
||||
} = require("../utils") |
} = require("../utils") |
||||
|
const tenancy = require("../../tenancy"); |
||||
|
const { Configs, DEFAULT_TENANT_ID } = require("../../constants"); |
||||
|
const env = require("../../environment") |
||||
|
|
||||
function getID() { |
describe("utils", () => { |
||||
const appId = generateAppID() |
describe("app ID manipulation", () => { |
||||
const split = appId.split("_") |
|
||||
const uuid = split[split.length - 1] |
|
||||
const devAppId = `app_dev_${uuid}` |
|
||||
return { appId, devAppId, split, uuid } |
|
||||
} |
|
||||
|
|
||||
describe("app ID manipulation", () => { |
function getID() { |
||||
it("should be able to generate a new app ID", () => { |
const appId = generateAppID() |
||||
expect(generateAppID().startsWith("app_")).toEqual(true) |
const split = appId.split("_") |
||||
}) |
const uuid = split[split.length - 1] |
||||
|
const devAppId = `app_dev_${uuid}` |
||||
|
return { appId, devAppId, split, uuid } |
||||
|
} |
||||
|
|
||||
it("should be able to convert a production app ID to development", () => { |
it("should be able to generate a new app ID", () => { |
||||
const { appId, uuid } = getID() |
expect(generateAppID().startsWith("app_")).toEqual(true) |
||||
expect(getDevelopmentAppID(appId)).toEqual(`app_dev_${uuid}`) |
}) |
||||
|
|
||||
|
it("should be able to convert a production app ID to development", () => { |
||||
|
const { appId, uuid } = getID() |
||||
|
expect(getDevelopmentAppID(appId)).toEqual(`app_dev_${uuid}`) |
||||
|
}) |
||||
|
|
||||
|
it("should be able to convert a development app ID to development", () => { |
||||
|
const { devAppId, uuid } = getID() |
||||
|
expect(getDevelopmentAppID(devAppId)).toEqual(`app_dev_${uuid}`) |
||||
|
}) |
||||
|
|
||||
|
it("should be able to convert a development ID to a production", () => { |
||||
|
const { devAppId, uuid } = getID() |
||||
|
expect(getProdAppID(devAppId)).toEqual(`app_${uuid}`) |
||||
|
}) |
||||
|
|
||||
|
it("should be able to convert a production ID to production", () => { |
||||
|
const { appId, uuid } = getID() |
||||
|
expect(getProdAppID(appId)).toEqual(`app_${uuid}`) |
||||
|
}) |
||||
|
|
||||
|
it("should be able to confirm dev app ID is development", () => { |
||||
|
const { devAppId } = getID() |
||||
|
expect(isDevAppID(devAppId)).toEqual(true) |
||||
|
}) |
||||
|
|
||||
|
it("should be able to confirm prod app ID is not development", () => { |
||||
|
const { appId } = getID() |
||||
|
expect(isDevAppID(appId)).toEqual(false) |
||||
|
}) |
||||
|
|
||||
|
it("should be able to confirm prod app ID is prod", () => { |
||||
|
const { appId } = getID() |
||||
|
expect(isProdAppID(appId)).toEqual(true) |
||||
|
}) |
||||
|
|
||||
|
it("should be able to confirm dev app ID is not prod", () => { |
||||
|
const { devAppId } = getID() |
||||
|
expect(isProdAppID(devAppId)).toEqual(false) |
||||
|
}) |
||||
}) |
}) |
||||
|
}) |
||||
|
|
||||
it("should be able to convert a development app ID to development", () => { |
const DB_URL = "http://dburl.com" |
||||
const { devAppId, uuid } = getID() |
const DEFAULT_URL = "http://localhost:10000" |
||||
expect(getDevelopmentAppID(devAppId)).toEqual(`app_dev_${uuid}`) |
const ENV_URL = "http://env.com" |
||||
}) |
|
||||
|
|
||||
it("should be able to convert a development ID to a production", () => { |
const setDbPlatformUrl = async () => { |
||||
const { devAppId, uuid } = getID() |
const db = tenancy.getGlobalDB() |
||||
expect(getProdAppID(devAppId)).toEqual(`app_${uuid}`) |
db.put({ |
||||
|
_id: "config_settings", |
||||
|
type: Configs.SETTINGS, |
||||
|
config: { |
||||
|
platformUrl: DB_URL |
||||
|
} |
||||
}) |
}) |
||||
|
} |
||||
|
|
||||
it("should be able to convert a production ID to production", () => { |
const clearSettingsConfig = async () => { |
||||
const { appId, uuid } = getID() |
await tenancy.doInTenant(DEFAULT_TENANT_ID, async () => { |
||||
expect(getProdAppID(appId)).toEqual(`app_${uuid}`) |
const db = tenancy.getGlobalDB() |
||||
|
try { |
||||
|
const config = await db.get("config_settings") |
||||
|
await db.remove("config_settings", config._rev) |
||||
|
} catch (e) { |
||||
|
if (e.status !== 404) { |
||||
|
throw e |
||||
|
} |
||||
|
} |
||||
}) |
}) |
||||
|
} |
||||
|
|
||||
|
describe("getPlatformUrl", () => { |
||||
|
describe("self host", () => { |
||||
|
|
||||
it("should be able to confirm dev app ID is development", () => { |
beforeEach(async () => { |
||||
const { devAppId } = getID() |
env._set("SELF_HOST", 1) |
||||
expect(isDevAppID(devAppId)).toEqual(true) |
await clearSettingsConfig() |
||||
}) |
}) |
||||
|
|
||||
|
it("gets the default url", async () => { |
||||
|
await tenancy.doInTenant(null, async () => { |
||||
|
const url = await getPlatformUrl() |
||||
|
expect(url).toBe(DEFAULT_URL) |
||||
|
}) |
||||
|
}) |
||||
|
|
||||
|
it("gets the platform url from the environment", async () => { |
||||
|
await tenancy.doInTenant(null, async () => { |
||||
|
env._set("PLATFORM_URL", ENV_URL) |
||||
|
const url = await getPlatformUrl() |
||||
|
expect(url).toBe(ENV_URL) |
||||
|
}) |
||||
|
}) |
||||
|
|
||||
it("should be able to confirm prod app ID is not development", () => { |
it("gets the platform url from the database", async () => { |
||||
const { appId } = getID() |
await tenancy.doInTenant(null, async () => { |
||||
expect(isDevAppID(appId)).toEqual(false) |
await setDbPlatformUrl() |
||||
|
const url = await getPlatformUrl() |
||||
|
expect(url).toBe(DB_URL) |
||||
|
}) |
||||
|
}) |
||||
}) |
}) |
||||
|
|
||||
it("should be able to confirm prod app ID is prod", () => { |
|
||||
const { appId } = getID() |
describe("cloud", () => { |
||||
expect(isProdAppID(appId)).toEqual(true) |
const TENANT_AWARE_URL = "http://default.env.com" |
||||
|
|
||||
|
beforeEach(async () => { |
||||
|
env._set("SELF_HOSTED", 0) |
||||
|
env._set("MULTI_TENANCY", 1) |
||||
|
env._set("PLATFORM_URL", ENV_URL) |
||||
|
await clearSettingsConfig() |
||||
|
}) |
||||
|
|
||||
|
it("gets the platform url from the environment without tenancy", async () => { |
||||
|
await tenancy.doInTenant(DEFAULT_TENANT_ID, async () => { |
||||
|
const url = await getPlatformUrl({ tenantAware: false }) |
||||
|
expect(url).toBe(ENV_URL) |
||||
|
}) |
||||
|
}) |
||||
|
|
||||
|
it("gets the platform url from the environment with tenancy", async () => { |
||||
|
await tenancy.doInTenant(DEFAULT_TENANT_ID, async () => { |
||||
|
const url = await getPlatformUrl() |
||||
|
expect(url).toBe(TENANT_AWARE_URL) |
||||
|
}) |
||||
|
}) |
||||
|
|
||||
|
it("never gets the platform url from the database", async () => { |
||||
|
await tenancy.doInTenant(DEFAULT_TENANT_ID, async () => { |
||||
|
await setDbPlatformUrl() |
||||
|
const url = await getPlatformUrl() |
||||
|
expect(url).toBe(TENANT_AWARE_URL) |
||||
|
}) |
||||
|
}) |
||||
}) |
}) |
||||
|
}) |
||||
|
|
||||
|
describe("getScopedConfig", () => { |
||||
|
describe("settings config", () => { |
||||
|
|
||||
|
beforeEach(async () => { |
||||
|
env._set("SELF_HOSTED", 1) |
||||
|
env._set("PLATFORM_URL", "") |
||||
|
await clearSettingsConfig() |
||||
|
}) |
||||
|
|
||||
|
it("returns the platform url with an existing config", async () => { |
||||
|
await tenancy.doInTenant(DEFAULT_TENANT_ID, async () => { |
||||
|
await setDbPlatformUrl() |
||||
|
const db = tenancy.getGlobalDB() |
||||
|
const config = await getScopedConfig(db, { type: Configs.SETTINGS }) |
||||
|
expect(config.platformUrl).toBe(DB_URL) |
||||
|
}) |
||||
|
}) |
||||
|
|
||||
it("should be able to confirm dev app ID is not prod", () => { |
it("returns the platform url without an existing config", async () => { |
||||
const { devAppId } = getID() |
await tenancy.doInTenant(DEFAULT_TENANT_ID, async () => { |
||||
expect(isProdAppID(devAppId)).toEqual(false) |
const db = tenancy.getGlobalDB() |
||||
|
const config = await getScopedConfig(db, { type: Configs.SETTINGS }) |
||||
|
expect(config.platformUrl).toBe(DEFAULT_URL) |
||||
|
}) |
||||
|
}) |
||||
}) |
}) |
||||
}) |
}) |
||||
|
|||||
@ -0,0 +1,68 @@ |
|||||
|
<script> |
||||
|
import "@spectrum-css/fieldgroup/dist/index-vars.css" |
||||
|
import "@spectrum-css/radio/dist/index-vars.css" |
||||
|
import { createEventDispatcher } from "svelte" |
||||
|
|
||||
|
export let direction = "vertical" |
||||
|
export let value = [] |
||||
|
export let options = [] |
||||
|
export let error = null |
||||
|
export let disabled = false |
||||
|
export let getOptionLabel = option => option |
||||
|
export let getOptionValue = option => option |
||||
|
|
||||
|
const dispatch = createEventDispatcher() |
||||
|
const onChange = e => { |
||||
|
let tempValue = value |
||||
|
let isChecked = e.target.checked |
||||
|
if (!tempValue.includes(e.target.value) && isChecked) { |
||||
|
tempValue.push(e.target.value) |
||||
|
} |
||||
|
value = tempValue |
||||
|
dispatch( |
||||
|
"change", |
||||
|
tempValue.filter(val => val !== e.target.value || isChecked) |
||||
|
) |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<div class={`spectrum-FieldGroup spectrum-FieldGroup--${direction}`}> |
||||
|
{#if options && Array.isArray(options)} |
||||
|
{#each options as option} |
||||
|
<div |
||||
|
title={getOptionLabel(option)} |
||||
|
class="spectrum-Checkbox spectrum-FieldGroup-item" |
||||
|
class:is-invalid={!!error} |
||||
|
> |
||||
|
<label |
||||
|
class="spectrum-Checkbox spectrum-Checkbox--sizeM spectrum-FieldGroup-item" |
||||
|
> |
||||
|
<input |
||||
|
on:change={onChange} |
||||
|
value={getOptionValue(option)} |
||||
|
type="checkbox" |
||||
|
class="spectrum-Checkbox-input" |
||||
|
{disabled} |
||||
|
checked={value.includes(getOptionValue(option))} |
||||
|
/> |
||||
|
<span class="spectrum-Checkbox-box"> |
||||
|
<svg |
||||
|
class="spectrum-Icon spectrum-UIIcon-Checkmark100 spectrum-Checkbox-checkmark" |
||||
|
focusable="false" |
||||
|
aria-hidden="true" |
||||
|
> |
||||
|
<use xlink:href="#spectrum-css-icon-Checkmark100" /> |
||||
|
</svg> |
||||
|
</span> |
||||
|
<span class="spectrum-Checkbox-label">{getOptionLabel(option)}</span> |
||||
|
</label> |
||||
|
</div> |
||||
|
{/each} |
||||
|
{/if} |
||||
|
</div> |
||||
|
|
||||
|
<style> |
||||
|
.spectrum-Checkbox-input { |
||||
|
opacity: 0; |
||||
|
} |
||||
|
</style> |
||||
@ -1,11 +1,15 @@ |
|||||
{ |
{ |
||||
"baseUrl": "http://localhost:4100", |
"baseUrl": "http://localhost:4100", |
||||
"video": false, |
"video": true, |
||||
"projectId": "bmbemn", |
"projectId": "bmbemn", |
||||
"env": { |
"env": { |
||||
"PORT": "4100", |
"PORT": "4100", |
||||
"WORKER_PORT": "4200", |
"WORKER_PORT": "4200", |
||||
"JWT_SECRET": "test", |
"JWT_SECRET": "test", |
||||
"HOST_IP": "" |
"HOST_IP": "" |
||||
|
}, |
||||
|
"retries": { |
||||
|
"runMode": 2, |
||||
|
"openMode": 0 |
||||
} |
} |
||||
} |
} |
||||
|
|||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,81 @@ |
|||||
|
import filterTests from "../../../support/filterTests" |
||||
|
|
||||
|
filterTests(["all"], () => { |
||||
|
context("IT Ticketing System Template Functionality", () => { |
||||
|
const templateName = "IT Ticketing System" |
||||
|
const templateNameParsed = templateName.toLowerCase().replace(/\s+/g, '-') |
||||
|
|
||||
|
before(() => { |
||||
|
cy.login() |
||||
|
cy.deleteApp(templateName) |
||||
|
cy.visit(`${Cypress.config().baseUrl}/builder`, { |
||||
|
onBeforeLoad(win) { |
||||
|
cy.stub(win, 'open') |
||||
|
} |
||||
|
}) |
||||
|
cy.wait(2000) |
||||
|
cy.templateNavigation() |
||||
|
}) |
||||
|
|
||||
|
it("should create and publish app with IT Ticketing System template", () => { |
||||
|
// Select IT Ticketing System template
|
||||
|
cy.get(".template-thumbnail-text") |
||||
|
.contains(templateName).parentsUntil(".template-grid").within(() => { |
||||
|
cy.get(".spectrum-Button").contains("Use template").click({ force: true }) |
||||
|
}) |
||||
|
|
||||
|
// Confirm URL matches template name
|
||||
|
const appUrl = cy.get(".app-server") |
||||
|
appUrl.invoke('text').then(appUrlText => { |
||||
|
expect(appUrlText).to.equal(`${Cypress.config().baseUrl}/app/` + templateNameParsed) |
||||
|
}) |
||||
|
|
||||
|
// Create App
|
||||
|
cy.get(".spectrum-Dialog-grid").within(() => { |
||||
|
cy.get(".spectrum-Button").contains("Create app").click({ force: true }) |
||||
|
}) |
||||
|
|
||||
|
// Publish App
|
||||
|
cy.wait(2000) // Wait for app to generate
|
||||
|
cy.get(".toprightnav").contains("Publish").click({ force: true }) |
||||
|
cy.get(".spectrum-Dialog-grid").within(() => { |
||||
|
cy.get(".spectrum-Button").contains("Publish").click({ force: true }) |
||||
|
}) |
||||
|
|
||||
|
// Verify Published app
|
||||
|
cy.wait(2000) // Wait for App to publish and modal to appear
|
||||
|
cy.get(".spectrum-Dialog-grid").within(() => { |
||||
|
cy.get(".spectrum-Button").contains("View App").click({ force: true }) |
||||
|
cy.window().its('open').should('be.calledOnce') |
||||
|
}) |
||||
|
}) |
||||
|
|
||||
|
xit("should filter tickets by status", () => { |
||||
|
// Visit published app
|
||||
|
cy.visit(`${Cypress.config().baseUrl}/app/` + templateNameParsed) |
||||
|
cy.wait(1000) |
||||
|
|
||||
|
// Tickets section
|
||||
|
cy.get(".links").contains("Tickets").click({ force: true }) |
||||
|
cy.wait(1000) |
||||
|
|
||||
|
// Filter by stage - Confirm table updates
|
||||
|
cy.get(".spectrum-Picker").contains("Filter by status").click({ force: true }) |
||||
|
cy.get(".spectrum-Menu").find('li').its('length').then(len => { |
||||
|
for (let i = 1; i < len; i++) { |
||||
|
cy.get(".spectrum-Menu-item").eq(i).click() |
||||
|
const stage = cy.get(".spectrum-Picker-label") |
||||
|
stage.invoke('text').then(stageText => { |
||||
|
if (stageText == "In progress" || stageText == "On hold" || stageText == "Triaged") { |
||||
|
cy.get(".placeholder").should('contain', 'No rows found') |
||||
|
} |
||||
|
else { |
||||
|
cy.get(".spectrum-Table-row").should('contain', stageText) |
||||
|
} |
||||
|
cy.get(".spectrum-Picker").contains(stageText).click({ force: true }) |
||||
|
}) |
||||
|
} |
||||
|
}) |
||||
|
}) |
||||
|
}) |
||||
|
}) |
||||
@ -0,0 +1,13 @@ |
|||||
|
// createApp test
|
||||
|
export const CREATE_APP_BUTTON = '[data-cy="create-app-btn"]' |
||||
|
export const TEMPLATE_CATEGORY_FILTER = ".template-category-filters" |
||||
|
export const TEMPLATE_CATEGORY = ".template-categories" |
||||
|
export const APP_TABLE = ".appTable" |
||||
|
export const SPECTRUM_BUTTON_TEMPLATE = ".spectrum-Button" |
||||
|
export const TEMPLATE_CATEGORY_ACTIONGROUP = ".template-category" |
||||
|
export const TEMPLATE_CATEGORY_FILTER_ACTIONBUTTON = |
||||
|
".template-category-filters .spectrum-ActionButton" |
||||
|
export const SPECTRUM_MODAL = ".spectrum-Modal" |
||||
|
export const APP_NAME_INPUT = "input" // we need to update this with atribute cy-data
|
||||
|
export const SPECTRUM_BUTTON_GROUP = ".spectrum-ButtonGroup" |
||||
|
export const SPECTRUM_MODAL_INPUT = ".spectrum-Modal input" |
||||
File diff suppressed because it is too large
File diff suppressed because it is too large
Loading…
Reference in new issue