Nathan.fooo 32bd0ffca2
feat: migrate flowy-database (#2373)
* feat: add flowy-database2

* chore: config type option data

* chore: impl type option

* feat: config group

* fix: group compile

* feat: add sort

* chore: setting

* chore: insert with specific type

* chore: custom group

* chore: rename any map

* chore: use group setting

* chore: update

* chore: open database event

* chore: update database editor

* chore: update

* chore: update view editor

* chore: update

* chore: update view editor

* chore: sort feat

* chore: update handler

* chore: update

* chore: config handler event

* feat: impl handlers

* feat: impl handlers

* chore: layout setting

* feat: impl handlers

* chore: remove flowy-folder ref

* chore: integrate flowy-database2

* feat: get cell

* chore: create database with data

* chore: create view

* chore: fix dart compile

* fix: some bugs

* chore: update

* chore: merge develop

* chore: fix warning

* chore: integrate rocksdb

* fix: rocksdb compile errros

* fix: update cell

* chore: update the bundle identifier

* fix: create row

* fix: switch to field

* fix: duplicate grid

* test: migrate tests

* test: migrate tests

* test: update test

* test: migrate tests

* chore: add patch
2023-04-28 14:08:53 +08:00

87 lines
2.4 KiB
Rust

use collab_database::fields::Field;
use collab_database::views::DatabaseLayout;
use flowy_database2::entities::FieldType;
use flowy_database2::services::setting::CalendarLayoutSetting;
use crate::database::database_editor::DatabaseEditorTest;
pub enum LayoutScript {
AssertCalendarLayoutSetting { expected: CalendarLayoutSetting },
GetCalendarEvents,
}
pub struct DatabaseLayoutTest {
database_test: DatabaseEditorTest,
}
impl DatabaseLayoutTest {
pub async fn new_calendar() -> Self {
let database_test = DatabaseEditorTest::new_calendar().await;
Self { database_test }
}
pub async fn run_scripts(&mut self, scripts: Vec<LayoutScript>) {
for script in scripts {
self.run_script(script).await;
}
}
pub async fn get_first_date_field(&self) -> Field {
self.database_test.get_first_field(FieldType::DateTime)
}
pub async fn run_script(&mut self, script: LayoutScript) {
match script {
LayoutScript::AssertCalendarLayoutSetting { expected } => {
let view_id = self.database_test.view_id.clone();
let layout_ty = DatabaseLayout::Calendar;
let calendar_setting = self
.database_test
.editor
.get_layout_setting(&view_id, layout_ty)
.await
.unwrap()
.calendar
.unwrap();
assert_eq!(calendar_setting.layout_ty, expected.layout_ty);
assert_eq!(
calendar_setting.first_day_of_week,
expected.first_day_of_week
);
assert_eq!(calendar_setting.show_weekends, expected.show_weekends);
},
LayoutScript::GetCalendarEvents => {
let events = self
.database_test
.editor
.get_all_calendar_events(&self.database_test.view_id)
.await;
assert_eq!(events.len(), 5);
for (index, event) in events.into_iter().enumerate() {
if index == 0 {
assert_eq!(event.title, "A");
assert_eq!(event.timestamp, 1678090778);
}
if index == 1 {
assert_eq!(event.title, "B");
assert_eq!(event.timestamp, 1677917978);
}
if index == 2 {
assert_eq!(event.title, "C");
assert_eq!(event.timestamp, 1679213978);
}
if index == 4 {
assert_eq!(event.title, "E");
assert_eq!(event.timestamp, 1678695578);
}
}
},
}
}
}