Skip to content

Commit 24cd0cb

Browse files
authored
feat: support notion style embedded database view (#182)
* chore: set databbase id * chore: support display document based embeded database views * chore: filter views * chore: create embedded view * fix: embedded database view * refactor: rename DatabaseContextState * chore: do not show extra when parent is database * chore: linked database base sidebar prefix * chore: add tests * chore: remove unused folder-view api endpoint * chore: fix retry , add tests * chore: select view after creating * chore: clippy * chore: fix test
1 parent 6d040f8 commit 24cd0cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1530
-494
lines changed

cypress/e2e/editor/blocks/unsupported_block.cy.ts

Lines changed: 82 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { AuthTestUtils } from '../../../support/auth-utils';
22
import { waitForReactUpdate } from '../../../support/selectors';
33
import { generateRandomEmail } from '../../../support/test-config';
44

5+
// This test requires __TEST_DOC__ which is only exposed in dev mode
6+
// Tests will be skipped in CI where production builds are used
57
describe('Unsupported Block Display', () => {
68
const authUtils = new AuthTestUtils();
79
const testEmail = generateRandomEmail();
@@ -57,51 +59,60 @@ describe('Unsupported Block Display', () => {
5759
waitForReactUpdate(500);
5860
});
5961

62+
// Helper to check if test utilities are available
63+
const getTestUtilities = () => {
64+
return cy.window().then((win) => {
65+
const testWindow = win as Window & {
66+
__TEST_DOC__?: {
67+
getMap: (key: string) => unknown;
68+
transact: (fn: () => void) => void;
69+
};
70+
Y?: {
71+
Map: new () => Map<string, unknown>;
72+
Text: new () => unknown;
73+
Array: new <T>() => { push: (items: T[]) => void };
74+
};
75+
};
76+
77+
return {
78+
doc: testWindow.__TEST_DOC__,
79+
Y: testWindow.Y,
80+
available: !!(testWindow.__TEST_DOC__ && testWindow.Y),
81+
};
82+
});
83+
};
84+
6085
describe('Unsupported Block Rendering', () => {
61-
it('should display unsupported block message for unknown block types', () => {
86+
it('should display unsupported block message for unknown block types', function () {
6287
// Wait for editor to be ready
6388
waitForReactUpdate(500);
6489

65-
// Insert an unsupported block type via the exposed Yjs document
66-
cy.window().then((win) => {
67-
const testWindow = win as Window & {
68-
__TEST_DOC__?: {
69-
getMap: (key: string) => unknown;
70-
transact: (fn: () => void) => void;
71-
};
72-
Y?: {
73-
Map: new () => Map<string, unknown>;
74-
Text: new () => unknown;
75-
Array: new <T>() => { push: (items: T[]) => void };
76-
};
77-
};
90+
getTestUtilities().then((utils) => {
91+
if (!utils.available) {
92+
cy.log('⚠️ Test utilities not available (expected in CI/production builds) - skipping');
93+
this.skip();
7894

79-
const doc = testWindow.__TEST_DOC__;
80-
const Y = testWindow.Y;
81-
82-
if (!doc || !Y) {
83-
throw new Error('Test utilities not found. Ensure app is running in dev mode.');
95+
return;
8496
}
8597

98+
const { doc, Y } = utils;
99+
86100
// Get the document structure
87-
// Structure: doc.getMap('data').get('document') -> { blocks, meta, page_id }
88-
const sharedRoot = doc.getMap('data') as Map<string, unknown>;
101+
const sharedRoot = doc!.getMap('data') as Map<string, unknown>;
89102
const document = sharedRoot.get('document') as Map<string, unknown>;
90103
const blocks = document.get('blocks') as Map<string, unknown>;
91104
const meta = document.get('meta') as Map<string, unknown>;
92105
const pageId = document.get('page_id') as string;
93106
const childrenMap = meta.get('children_map') as Map<string, unknown>;
94107
const textMap = meta.get('text_map') as Map<string, unknown>;
95108

96-
// Generate a unique block ID
97109
const blockId = `test_unsupported_${Date.now()}`;
98110

99-
// Insert an unsupported block type
100-
doc.transact(() => {
101-
const block = new Y.Map();
111+
doc!.transact(() => {
112+
const block = new Y!.Map();
102113

103114
block.set('id', blockId);
104-
block.set('ty', 'future_block_type_not_yet_implemented'); // Unknown block type
115+
block.set('ty', 'future_block_type_not_yet_implemented');
105116
block.set('children', blockId);
106117
block.set('external_id', blockId);
107118
block.set('external_type', 'text');
@@ -110,63 +121,45 @@ describe('Unsupported Block Display', () => {
110121

111122
(blocks as Map<string, unknown>).set(blockId, block);
112123

113-
// Add to page children
114124
const pageChildren = childrenMap.get(pageId) as { push: (items: string[]) => void };
115125

116126
if (pageChildren) {
117127
pageChildren.push([blockId]);
118128
}
119129

120-
// Create empty text for the block
121-
const blockText = new Y.Text();
130+
const blockText = new Y!.Text();
122131

123132
(textMap as Map<string, unknown>).set(blockId, blockText);
124133

125-
// Create empty children array
126-
const blockChildren = new Y.Array<string>();
134+
const blockChildren = new Y!.Array<string>();
127135

128136
(childrenMap as Map<string, unknown>).set(blockId, blockChildren);
129137
});
130-
});
131138

132-
waitForReactUpdate(1000);
139+
waitForReactUpdate(1000);
133140

134-
// Verify the unsupported block component is rendered
135-
cy.get('[data-testid="unsupported-block"]').should('exist');
136-
cy.get('[data-testid="unsupported-block"]').should('be.visible');
137-
138-
// Verify it shows the correct message
139-
cy.get('[data-testid="unsupported-block"]')
140-
.should('contain.text', 'not supported yet')
141-
.and('contain.text', 'future_block_type_not_yet_implemented');
141+
cy.get('[data-testid="unsupported-block"]').should('exist');
142+
cy.get('[data-testid="unsupported-block"]').should('be.visible');
143+
cy.get('[data-testid="unsupported-block"]')
144+
.should('contain.text', 'not supported yet')
145+
.and('contain.text', 'future_block_type_not_yet_implemented');
146+
});
142147
});
143148

144-
it('should display warning icon and block type name', () => {
145-
// Insert an unsupported block with a specific type name
149+
it('should display warning icon and block type name', function () {
146150
const testBlockType = 'my_custom_unknown_block';
147151

148-
cy.window().then((win) => {
149-
const testWindow = win as Window & {
150-
__TEST_DOC__?: {
151-
getMap: (key: string) => unknown;
152-
transact: (fn: () => void) => void;
153-
};
154-
Y?: {
155-
Map: new () => Map<string, unknown>;
156-
Text: new () => unknown;
157-
Array: new <T>() => { push: (items: T[]) => void };
158-
};
159-
};
160-
161-
const doc = testWindow.__TEST_DOC__;
162-
const Y = testWindow.Y;
152+
getTestUtilities().then((utils) => {
153+
if (!utils.available) {
154+
cy.log('⚠️ Test utilities not available (expected in CI/production builds) - skipping');
155+
this.skip();
163156

164-
if (!doc || !Y) {
165-
throw new Error('Test utilities not found. Ensure app is running in dev mode.');
157+
return;
166158
}
167159

168-
// Structure: doc.getMap('data').get('document') -> { blocks, meta, page_id }
169-
const sharedRoot = doc.getMap('data') as Map<string, unknown>;
160+
const { doc, Y } = utils;
161+
162+
const sharedRoot = doc!.getMap('data') as Map<string, unknown>;
170163
const document = sharedRoot.get('document') as Map<string, unknown>;
171164
const blocks = document.get('blocks') as Map<string, unknown>;
172165
const meta = document.get('meta') as Map<string, unknown>;
@@ -176,8 +169,8 @@ describe('Unsupported Block Display', () => {
176169

177170
const blockId = `test_${Date.now()}`;
178171

179-
doc.transact(() => {
180-
const block = new Y.Map();
172+
doc!.transact(() => {
173+
const block = new Y!.Map();
181174

182175
block.set('id', blockId);
183176
block.set('ty', testBlockType);
@@ -195,51 +188,37 @@ describe('Unsupported Block Display', () => {
195188
pageChildren.push([blockId]);
196189
}
197190

198-
const blockText = new Y.Text();
191+
const blockText = new Y!.Text();
199192

200193
(textMap as Map<string, unknown>).set(blockId, blockText);
201194

202-
const blockChildren = new Y.Array<string>();
195+
const blockChildren = new Y!.Array<string>();
203196

204197
(childrenMap as Map<string, unknown>).set(blockId, blockChildren);
205198
});
206-
});
207199

208-
waitForReactUpdate(1000);
200+
waitForReactUpdate(1000);
209201

210-
// Verify the unsupported block shows the type name
211-
cy.get('[data-testid="unsupported-block"]')
212-
.should('be.visible')
213-
.and('contain.text', testBlockType);
202+
cy.get('[data-testid="unsupported-block"]')
203+
.should('be.visible')
204+
.and('contain.text', testBlockType);
214205

215-
// Verify it has the warning styling (contains an SVG icon)
216-
cy.get('[data-testid="unsupported-block"] svg').should('exist');
206+
cy.get('[data-testid="unsupported-block"] svg').should('exist');
207+
});
217208
});
218209

219-
it('should be non-editable', () => {
220-
// Insert an unsupported block
221-
cy.window().then((win) => {
222-
const testWindow = win as Window & {
223-
__TEST_DOC__?: {
224-
getMap: (key: string) => unknown;
225-
transact: (fn: () => void) => void;
226-
};
227-
Y?: {
228-
Map: new () => Map<string, unknown>;
229-
Text: new () => unknown;
230-
Array: new <T>() => { push: (items: T[]) => void };
231-
};
232-
};
233-
234-
const doc = testWindow.__TEST_DOC__;
235-
const Y = testWindow.Y;
210+
it('should be non-editable', function () {
211+
getTestUtilities().then((utils) => {
212+
if (!utils.available) {
213+
cy.log('⚠️ Test utilities not available (expected in CI/production builds) - skipping');
214+
this.skip();
236215

237-
if (!doc || !Y) {
238-
throw new Error('Test utilities not found.');
216+
return;
239217
}
240218

241-
// Structure: doc.getMap('data').get('document') -> { blocks, meta, page_id }
242-
const sharedRoot = doc.getMap('data') as Map<string, unknown>;
219+
const { doc, Y } = utils;
220+
221+
const sharedRoot = doc!.getMap('data') as Map<string, unknown>;
243222
const document = sharedRoot.get('document') as Map<string, unknown>;
244223
const blocks = document.get('blocks') as Map<string, unknown>;
245224
const meta = document.get('meta') as Map<string, unknown>;
@@ -249,8 +228,8 @@ describe('Unsupported Block Display', () => {
249228

250229
const blockId = `test_readonly_${Date.now()}`;
251230

252-
doc.transact(() => {
253-
const block = new Y.Map();
231+
doc!.transact(() => {
232+
const block = new Y!.Map();
254233

255234
block.set('id', blockId);
256235
block.set('ty', 'readonly_test_block');
@@ -268,21 +247,20 @@ describe('Unsupported Block Display', () => {
268247
pageChildren.push([blockId]);
269248
}
270249

271-
const blockText = new Y.Text();
250+
const blockText = new Y!.Text();
272251

273252
(textMap as Map<string, unknown>).set(blockId, blockText);
274253

275-
const blockChildren = new Y.Array<string>();
254+
const blockChildren = new Y!.Array<string>();
276255

277256
(childrenMap as Map<string, unknown>).set(blockId, blockChildren);
278257
});
279-
});
280258

281-
waitForReactUpdate(1000);
259+
waitForReactUpdate(1000);
282260

283-
// Verify the unsupported block has contentEditable=false
284-
cy.get('[data-testid="unsupported-block"]')
285-
.should('have.attr', 'contenteditable', 'false');
261+
cy.get('[data-testid="unsupported-block"]')
262+
.should('have.attr', 'contenteditable', 'false');
263+
});
286264
});
287265
});
288266
});

0 commit comments

Comments
 (0)