mirror of https://github.com/Budibase/budibase.git
45 changed files with 1930 additions and 237 deletions
@ -1,61 +1,194 @@ |
|||
require("../../tests/utilities/dbConfig"); |
|||
const { |
|||
generateAppID, |
|||
getDevelopmentAppID, |
|||
getProdAppID, |
|||
isDevAppID, |
|||
isProdAppID, |
|||
getPlatformUrl, |
|||
getScopedConfig |
|||
} = require("../utils") |
|||
const tenancy = require("../../tenancy"); |
|||
const { Configs, DEFAULT_TENANT_ID } = require("../../constants"); |
|||
const env = require("../../environment") |
|||
|
|||
function getID() { |
|||
const appId = generateAppID() |
|||
const split = appId.split("_") |
|||
const uuid = split[split.length - 1] |
|||
const devAppId = `app_dev_${uuid}` |
|||
return { appId, devAppId, split, uuid } |
|||
} |
|||
describe("utils", () => { |
|||
describe("app ID manipulation", () => { |
|||
|
|||
describe("app ID manipulation", () => { |
|||
it("should be able to generate a new app ID", () => { |
|||
expect(generateAppID().startsWith("app_")).toEqual(true) |
|||
}) |
|||
function getID() { |
|||
const appId = generateAppID() |
|||
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", () => { |
|||
const { appId, uuid } = getID() |
|||
expect(getDevelopmentAppID(appId)).toEqual(`app_dev_${uuid}`) |
|||
it("should be able to generate a new app ID", () => { |
|||
expect(generateAppID().startsWith("app_")).toEqual(true) |
|||
}) |
|||
|
|||
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 { devAppId, uuid } = getID() |
|||
expect(getDevelopmentAppID(devAppId)).toEqual(`app_dev_${uuid}`) |
|||
}) |
|||
const DB_URL = "http://dburl.com" |
|||
const DEFAULT_URL = "http://localhost:10000" |
|||
const ENV_URL = "http://env.com" |
|||
|
|||
it("should be able to convert a development ID to a production", () => { |
|||
const { devAppId, uuid } = getID() |
|||
expect(getProdAppID(devAppId)).toEqual(`app_${uuid}`) |
|||
const setDbPlatformUrl = async () => { |
|||
const db = tenancy.getGlobalDB() |
|||
db.put({ |
|||
_id: "config_settings", |
|||
type: Configs.SETTINGS, |
|||
config: { |
|||
platformUrl: DB_URL |
|||
} |
|||
}) |
|||
} |
|||
|
|||
it("should be able to convert a production ID to production", () => { |
|||
const { appId, uuid } = getID() |
|||
expect(getProdAppID(appId)).toEqual(`app_${uuid}`) |
|||
const clearSettingsConfig = async () => { |
|||
await tenancy.doInTenant(DEFAULT_TENANT_ID, async () => { |
|||
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", () => { |
|||
const { devAppId } = getID() |
|||
expect(isDevAppID(devAppId)).toEqual(true) |
|||
}) |
|||
beforeEach(async () => { |
|||
env._set("SELF_HOST", 1) |
|||
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", () => { |
|||
const { appId } = getID() |
|||
expect(isDevAppID(appId)).toEqual(false) |
|||
it("gets the platform url from the database", async () => { |
|||
await tenancy.doInTenant(null, async () => { |
|||
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() |
|||
expect(isProdAppID(appId)).toEqual(true) |
|||
|
|||
describe("cloud", () => { |
|||
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", () => { |
|||
const { devAppId } = getID() |
|||
expect(isProdAppID(devAppId)).toEqual(false) |
|||
it("returns the platform url without an existing config", async () => { |
|||
await tenancy.doInTenant(DEFAULT_TENANT_ID, async () => { |
|||
const db = tenancy.getGlobalDB() |
|||
const config = await getScopedConfig(db, { type: Configs.SETTINGS }) |
|||
expect(config.platformUrl).toBe(DEFAULT_URL) |
|||
}) |
|||
}) |
|||
}) |
|||
}) |
|||
}) |
|||
|
|||
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
Loading…
Reference in new issue