Search in sources :

Example 21 with NotePosition

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

the class StructureTest method testCutNoteUnderFoldedThenPaste.

@Test
public void testCutNoteUnderFoldedThenPaste() throws IOException {
    Book book = shelfTestUtils.setupBook("notebook", "" + "description\n" + "\n" + "* Note 1\n" + "** Note 1.1\n" + "*** Note 1.1.1\n");
    /* Cut & paste hidden 1.1.1 */
    shelf.toggleFoldedState(shelf.getNote("Note 1.1").getId());
    shelf.cut(book.getId(), shelf.getNote("Note 1.1.1").getId());
    Note n = shelf.getNote("Note 1");
    shelf.paste(n.getPosition().getBookId(), n.getId(), Place.UNDER);
    assertEquals("description\n" + "\n" + "* Note 1\n" + "** Note 1.1\n" + "** Note 1.1.1\n", shelf.getBookContent("notebook", BookName.Format.ORG));
    NotePosition n1 = shelf.getNote("Note 1").getPosition();
    NotePosition n11 = shelf.getNote("Note 1.1").getPosition();
    NotePosition n111 = shelf.getNote("Note 1.1.1").getPosition();
    assertEquals(0, n1.getFoldedUnderId());
    assertEquals(0, n11.getFoldedUnderId());
    assertEquals(0, n111.getFoldedUnderId());
}
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 22 with NotePosition

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

the class StructureTest method testDemote.

@Test
public void testDemote() throws IOException {
    Book book = shelfTestUtils.setupBook("notebook", "" + "description\n" + "\n" + "* Note 1\n" + "** Note 1.1\n" + "* Note 2\n");
    /* Demote 2. */
    assertEquals(1, shelf.demote(book.getId(), shelf.getNote("Note 2").getId()));
    assertEquals("description\n" + "\n" + "* Note 1\n" + "** Note 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 n2 = shelf.getNote("Note 2").getPosition();
    assertEquals(2, n1.getDescendantsCount());
    assertEquals(0, n11.getDescendantsCount());
    assertEquals(0, n2.getDescendantsCount());
    assertEquals(1, n1.getLevel());
    assertEquals(2, n11.getLevel());
    assertEquals(2, n2.getLevel());
    assertTrue(n1.getLft() < n11.getLft());
    assertTrue(n11.getLft() < n11.getRgt());
    assertTrue(n11.getRgt() < n2.getLft());
    assertTrue(n2.getLft() < n2.getRgt());
    assertTrue(n2.getRgt() < n1.getRgt());
}
Also used : Book(com.orgzly.android.Book) NotePosition(com.orgzly.android.NotePosition) OrgzlyTest(com.orgzly.android.OrgzlyTest) Test(org.junit.Test)

Aggregations

NotePosition (com.orgzly.android.NotePosition)22 OrgzlyTest (com.orgzly.android.OrgzlyTest)13 Test (org.junit.Test)13 Book (com.orgzly.android.Book)11 Note (com.orgzly.android.Note)11 Cursor (android.database.Cursor)6 ContentValues (android.content.ContentValues)5 NotePlace (com.orgzly.android.ui.NotePlace)4 SuppressLint (android.annotation.SuppressLint)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 Uri (android.net.Uri)1 DbNote (com.orgzly.android.provider.models.DbNote)1 SqliteQueryBuilder (com.orgzly.android.query.sql.SqliteQueryBuilder)1 OrgFile (com.orgzly.org.OrgFile)1 OrgHead (com.orgzly.org.OrgHead)1 OrgProperties (com.orgzly.org.OrgProperties)1 OrgNestedSetParserListener (com.orgzly.org.parser.OrgNestedSetParserListener)1 OrgNodeInSet (com.orgzly.org.parser.OrgNodeInSet)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1