Search in sources :

Example 21 with Note

use of com.orgzly.android.Note in project orgzly-android by orgzly.

the class ShelfTest method testNewBook.

@Test
public void testNewBook() throws IOException {
    shelf.createBook("booky");
    /* Make sure root node is created. */
    Note note = shelf.getNote(1);
    assertEquals(1, note.getPosition().getLft());
    assertEquals(2, note.getPosition().getRgt());
    assertEquals(0, note.getPosition().getLevel());
    assertNotNull(note.getHead());
    assertEquals("", note.getHead().getTitle());
}
Also used : Note(com.orgzly.android.Note) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Example 22 with Note

use of com.orgzly.android.Note in project orgzly-android by orgzly.

the class Provider method insertRootNote.

private long insertRootNote(SQLiteDatabase db, long bookId) {
    Note rootNote = Note.newRootNote(bookId);
    ContentValues values = new ContentValues();
    NotesClient.toContentValues(values, rootNote);
    replaceTimestampRangeStringsWithIds(db, values);
    return db.insertOrThrow(DbNote.TABLE, null, values);
}
Also used : ContentValues(android.content.ContentValues) Note(com.orgzly.android.Note) DbNote(com.orgzly.android.provider.models.DbNote)

Example 23 with Note

use of com.orgzly.android.Note in project orgzly-android by orgzly.

the class StructureTest method testCut.

@Test
public void testCut() {
    Book book = shelfTestUtils.setupBook("notebook", "" + "description\n" + "* Note #1.\n" + "* Note #2.\n" + "** Note #3.\n" + "** Note #4.\n" + "*** Note #5.\n" + "**** Note #6.\n" + "** Note #7.\n" + "* Note #8.\n" + "**** Note #9.\n" + "** Note #10.\n" + "");
    Set<Long> ids = new HashSet<>();
    ids.add(1L);
    ids.add(2L);
    shelf.cut(book.getId(), ids);
    assertEquals("There should be less notes in the book", 8, NotesClient.getCount(context, book.getId()));
    Cursor cursor = NotesClient.getCursorForBook(context, book.getName());
    try {
        Note note;
        OrgHead head;
        cursor.moveToFirst();
        note = NotesClient.fromCursor(cursor);
        head = note.getHead();
        assertEquals("Title for book should match", "Note #2.", head.getTitle());
        assertEquals("Level for book should match", 1, note.getPosition().getLevel());
        cursor.moveToNext();
        note = NotesClient.fromCursor(cursor);
        head = note.getHead();
        assertEquals("Title for book should match", "Note #4.", head.getTitle());
        assertEquals("Level for book should match", 2, note.getPosition().getLevel());
        cursor.moveToNext();
        note = NotesClient.fromCursor(cursor);
        head = note.getHead();
        assertEquals("Title for book should match", "Note #5.", head.getTitle());
        assertEquals("Level for book should match", 3, note.getPosition().getLevel());
    } finally {
        cursor.close();
    }
}
Also used : Book(com.orgzly.android.Book) OrgHead(com.orgzly.org.OrgHead) Note(com.orgzly.android.Note) Cursor(android.database.Cursor) HashSet(java.util.HashSet) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Example 24 with Note

use of com.orgzly.android.Note in project orgzly-android by orgzly.

the class StructureTest method testPromote2.

@Test
public void testPromote2() throws IOException {
    Book book = shelfTestUtils.setupBook("notebook", "" + "description\n" + "\n" + "* Note 1\n" + "** Note 1.1\n" + "*** Note 1.1.1\n" + "** Note 1.2\n" + "* Note 2\n");
    Note note = shelf.getNote("Note 1.1.1");
    /* Promote 1.1.1 twice. */
    assertEquals(1, shelf.promote(book.getId(), note.getId()));
    assertEquals(1, shelf.promote(book.getId(), note.getId()));
    assertEquals("description\n" + "\n" + "* Note 1\n" + "** Note 1.1\n" + "** Note 1.2\n" + "* Note 1.1.1\n" + "* Note 2\n", shelf.getBookContent("notebook", BookName.Format.ORG));
    NotePosition n1 = shelf.getNote("Note 1").getPosition();
    NotePosition n11 = shelf.getNote("Note 1.1").getPosition();
    NotePosition n12 = shelf.getNote("Note 1.2").getPosition();
    NotePosition n111 = shelf.getNote("Note 1.1.1").getPosition();
    NotePosition n2 = shelf.getNote("Note 2").getPosition();
    assertEquals(2, n1.getDescendantsCount());
    assertEquals(0, n11.getDescendantsCount());
    assertEquals(0, n12.getDescendantsCount());
    assertEquals(0, n111.getDescendantsCount());
    assertEquals(0, n2.getDescendantsCount());
    assertEquals(1, n1.getLevel());
    assertEquals(2, n11.getLevel());
    assertEquals(2, n12.getLevel());
    assertEquals(1, n111.getLevel());
    assertEquals(1, n2.getLevel());
    assertTrue(n1.getLft() < n11.getLft());
    assertTrue(n11.getLft() < n11.getRgt());
    assertTrue(n11.getRgt() < n12.getLft());
    assertTrue(n12.getLft() < n12.getRgt());
    assertTrue(n12.getRgt() < n1.getRgt());
    assertTrue(n1.getRgt() < n111.getLft());
    assertTrue(n111.getLft() < n111.getRgt());
    assertTrue(n111.getRgt() < n2.getLft());
    assertTrue(n2.getLft() < n2.getRgt());
}
Also used : Book(com.orgzly.android.Book) NotePosition(com.orgzly.android.NotePosition) Note(com.orgzly.android.Note) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Example 25 with Note

use of com.orgzly.android.Note in project orgzly-android by orgzly.

the class StructureTest method testNewNoteAbove.

@Test
public void testNewNoteAbove() throws IOException {
    Book book = shelfTestUtils.setupBook("notebook", "description\n" + "* Note 1\n" + // ** Note 1.0
    "** Note 1.1\n" + "*** Note 1.1.1\n" + "** Note 1.2\n");
    NotePosition note1, note11, note111, note12, note10;
    /* Create new note above Note 1.1. */
    Note n = new Note();
    n.getPosition().setBookId(book.getId());
    n.getHead().setTitle("Note 1.0");
    NotePlace target = new NotePlace(book.getId(), shelf.getNote("Note 1.1").getId(), Place.ABOVE);
    shelf.createNote(n, target);
    note1 = shelf.getNote("Note 1").getPosition();
    note10 = shelf.getNote("Note 1.0").getPosition();
    note11 = shelf.getNote("Note 1.1").getPosition();
    note111 = shelf.getNote("Note 1.1.1").getPosition();
    note12 = shelf.getNote("Note 1.2").getPosition();
    assertTrue(note1.getLft() < note10.getLft());
    assertTrue(note10.getLft() < note10.getRgt());
    assertTrue(note10.getRgt() < note11.getLft());
    assertTrue(note11.getLft() < note111.getLft());
    assertTrue(note111.getLft() < note111.getRgt());
    assertTrue(note111.getRgt() < note11.getRgt());
    assertTrue(note11.getRgt() < note12.getLft());
    assertTrue(note12.getLft() < note12.getRgt());
    assertTrue(note12.getRgt() < note1.getRgt());
}
Also used : Book(com.orgzly.android.Book) NotePosition(com.orgzly.android.NotePosition) Note(com.orgzly.android.Note) NotePlace(com.orgzly.android.ui.NotePlace) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Aggregations

Note (com.orgzly.android.Note)29 OrgzlyTest (com.orgzly.android.OrgzlyTest)21 Test (org.junit.Test)21 Book (com.orgzly.android.Book)18 NotePosition (com.orgzly.android.NotePosition)11 NotePlace (com.orgzly.android.ui.NotePlace)4 OrgHead (com.orgzly.org.OrgHead)4 DbNote (com.orgzly.android.provider.models.DbNote)3 Intent (android.content.Intent)2 Cursor (android.database.Cursor)2 AppIntent (com.orgzly.android.AppIntent)2 Shelf (com.orgzly.android.Shelf)2 ContentValues (android.content.ContentValues)1 OrgProperties (com.orgzly.org.OrgProperties)1 OrgRange (com.orgzly.org.datetime.OrgRange)1 HashSet (java.util.HashSet)1