(core) updates from grist-core

This commit is contained in:
Paul Fitzpatrick
2024-10-01 11:54:40 -04:00
19 changed files with 116 additions and 250 deletions

View File

@@ -637,7 +637,7 @@ async function copyAndCheck(
}
}
function createDummyTextArea() {
export function createDummyTextArea() {
const textarea = document.createElement('textarea');
textarea.style.position = "absolute";
textarea.style.top = "0";
@@ -647,7 +647,7 @@ function createDummyTextArea() {
window.document.body.appendChild(textarea);
}
function removeDummyTextArea() {
export function removeDummyTextArea() {
const textarea = document.getElementById('dummyText');
if (textarea) {
window.document.body.removeChild(textarea);

View File

@@ -0,0 +1,59 @@
/**
* Test for copying Grist data with headers.
*/
import {assert, driver, Key} from 'mocha-webdriver';
import * as gu from 'test/nbrowser/gristUtils';
import {setupTestSuite} from 'test/nbrowser/testUtils';
import {createDummyTextArea, removeDummyTextArea} from 'test/nbrowser/CopyPaste';
describe("CopyWithHeaders", function() {
this.timeout(90000);
const cleanup = setupTestSuite();
const clipboard = gu.getLockableClipboard();
afterEach(() => gu.checkForErrors());
gu.bigScreen();
after(async function() {
await driver.executeScript(removeDummyTextArea);
});
it('should copy headers', async function() {
const session = await gu.session().teamSite.login();
await session.tempDoc(cleanup, 'Hello.grist');
await driver.executeScript(createDummyTextArea);
await clipboard.lockAndPerform(async (cb) => {
// Select all
await gu.sendKeys(Key.chord(Key.CONTROL, 'a'));
await gu.rightClick(gu.getCell({rowNum: 1, col: 'A'}));
await driver.findContent('.grist-floating-menu li', 'Copy with headers').click();
await pasteAndCheck(cb, ["A", "B", "C", "D", "E"], 5);
});
await clipboard.lockAndPerform(async (cb) => {
// Select a single cell.
await gu.getCell({rowNum: 2, col: 'D'}).click();
await gu.rightClick(gu.getCell({rowNum: 2, col: 'D'}));
await driver.findContent('.grist-floating-menu li', 'Copy with headers').click();
await pasteAndCheck(cb, ["D"], 2);
});
});
});
async function pasteAndCheck(cb: gu.IClipboard, headers: string[], rows: number) {
// Paste into the dummy textarea.
await driver.find('#dummyText').click();
await gu.waitAppFocus(false);
await cb.paste();
const textarea = await driver.find('#dummyText');
const text = await textarea.getAttribute('value');
const lines = text.split('\n');
const regex = new RegExp(`^${headers.join('\\s+')}$`);
assert.match(lines[0], regex);
assert.equal(lines.length, rows);
await textarea.clear();
}

View File

@@ -98,7 +98,6 @@ describe('HomeIntro', function() {
assert.isTrue(await driver.find('.test-intro-cards').isDisplayed());
assert.isTrue(await driver.find('.test-intro-video-tour').isDisplayed());
assert.isTrue(await driver.find('.test-intro-tutorial').isDisplayed());
assert.isTrue(await driver.find('.test-intro-create-doc').isDisplayed());
assert.isTrue(await driver.find('.test-intro-import-doc').isDisplayed());
assert.isTrue(await driver.find('.test-intro-templates').isDisplayed());

View File

@@ -1,146 +0,0 @@
import {Organization} from 'app/gen-server/entity/Organization';
import {fixSiteProducts} from 'app/gen-server/lib/Housekeeper';
import {TestServer} from 'test/gen-server/apiUtils';
import * as testUtils from 'test/server/testUtils';
import {assert} from 'chai';
import sinon from "sinon";
import {getDefaultProductNames} from 'app/gen-server/entity/Product';
const email = 'chimpy@getgrist.com';
const profile = {email, name: email};
const org = 'single-org';
describe('fixSiteProducts', function() {
this.timeout(6000);
let oldEnv: testUtils.EnvironmentSnapshot;
let server: TestServer;
before(async function() {
oldEnv = new testUtils.EnvironmentSnapshot();
// By default we will simulate 'core' deployment that has 'Free' team site as default product.
process.env.GRIST_TEST_SERVER_DEPLOYMENT_TYPE = 'core';
process.env.GRIST_DEFAULT_PRODUCT = 'Free';
server = new TestServer(this);
await server.start();
});
after(async function() {
oldEnv.restore();
await server.stop();
});
it('fix should be deleted after 2024-10-01', async function() {
const now = new Date();
const remove_date = new Date('2024-10-01');
assert.isTrue(now < remove_date, 'This test and a fix method should be deleted after 2024-10-01');
});
it('fixes sites that where created with a wrong product', async function() {
const db = server.dbManager;
const user = await db.getUserByLogin(email, {profile}) as any;
const getOrg = (id: number) => db.connection.manager.findOne(
Organization,
{where: {id}, relations: ['billingAccount', 'billingAccount.product']});
const productOrg = (id: number) => getOrg(id)?.then(org => org?.billingAccount?.product?.name);
const freeOrg = db.unwrapQueryResult(await db.addOrg(user, {
name: org,
domain: org,
}, {
setUserAsOwner: false,
useNewPlan: true,
product: 'teamFree',
}));
const teamOrg = db.unwrapQueryResult(await db.addOrg(user, {
name: 'fix-team-org',
domain: 'fix-team-org',
}, {
setUserAsOwner: false,
useNewPlan: true,
product: 'team',
}));
// Make sure it is created with teamFree product.
assert.equal(await productOrg(freeOrg.id), 'teamFree');
// Run the fixer.
assert.isTrue(await fixSiteProducts({
db,
deploymentType: server.server.getDeploymentType(),
}));
// Make sure we fixed the product is on Free product.
assert.equal(await productOrg(freeOrg.id), 'Free');
// Make sure the other org is still on team product.
assert.equal(await productOrg(teamOrg.id), 'team');
});
it("doesn't run when on saas deployment", async function() {
process.env.GRIST_TEST_SERVER_DEPLOYMENT_TYPE = 'saas';
// Stub it in the server. Notice that we assume some knowledge about how the server is implemented - that it won't
// cache this value (nor any other component) and always read it when needed. Otherwise we would need to recreate
// the server each time.
const sandbox = sinon.createSandbox();
sandbox.stub(server.server, 'getDeploymentType').returns('saas');
assert.equal(server.server.getDeploymentType(), 'saas');
assert.isFalse(await fixSiteProducts({
db: server.dbManager,
deploymentType: server.server.getDeploymentType(),
}));
sandbox.restore();
});
it("doesn't run when default product is not set", async function() {
// Make sure we are in 'core'.
assert.equal(server.server.getDeploymentType(), 'core');
// But only when Free product is the default one.
process.env.GRIST_DEFAULT_PRODUCT = 'teamFree';
assert.equal(getDefaultProductNames().teamInitial, 'teamFree'); // sanity check that Grist sees it.
assert.isFalse(await fixSiteProducts({
db: server.dbManager,
deploymentType: server.server.getDeploymentType(),
}));
process.env.GRIST_DEFAULT_PRODUCT = 'team';
assert.equal(getDefaultProductNames().teamInitial, 'team');
assert.isFalse(await fixSiteProducts({
db: server.dbManager,
deploymentType: server.server.getDeploymentType(),
}));
delete process.env.GRIST_DEFAULT_PRODUCT;
assert.equal(getDefaultProductNames().teamInitial, 'stub');
const db = server.dbManager;
const user = await db.getUserByLogin(email, {profile});
const org = db.unwrapQueryResult(await db.addOrg(user, {
name: 'sanity-check-org',
domain: 'sanity-check-org',
}, {
setUserAsOwner: false,
useNewPlan: true,
product: 'teamFree',
}));
const getOrg = (id: number) => db.connection.manager.findOne(Organization,
{where: {id}, relations: ['billingAccount', 'billingAccount.product']});
const productOrg = (id: number) => getOrg(id)?.then(org => org?.billingAccount?.product?.name);
assert.equal(await productOrg(org.id), 'teamFree');
assert.isFalse(await fixSiteProducts({
db: server.dbManager,
deploymentType: server.server.getDeploymentType(),
}));
assert.equal(await productOrg(org.id), 'teamFree');
});
});