Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ On click handler for the note view creates dialog window for editing previous no
# ToDos

## Main Application
- [ ] Sorting notes based on creation time
- [ ] Sorting notes based on last edited time
- [x] Sorting notes based on creation time
- [x] Sorting notes based on last edited time
- [ ] Deleting notes
- [ ] Viewing deleted notes
- [ ] Restoring deleted notes

## Widget
- [ ] Selection of note to view
- [ ] Selection of note to view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class NoteRepositoryUiTestingImplementation(notes: List<Note>) : NoteRepository
currentList.add(
Note(
content = note.content,
timeStamp = System.currentTimeMillis(),
creationTime = System.currentTimeMillis(),
uid = currentList.size
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class NoteListUITesting {

private lateinit var noteUseCases: NoteUseCases
private val notes: List<Note> = listOf(
Note(content = "Note1", timeStamp = 1740056347421, uid = 0),
Note(content = "Note2", timeStamp = 1740056372073, uid = 1),
Note(content = "Note3", timeStamp = 1740056372073, uid = 2)
Note(content = "Note1", creationTime = 1740056347421, uid = 0),
Note(content = "Note2", creationTime = 1740056372073, uid = 1),
Note(content = "Note3", creationTime = 1740056372073, uid = 2)
)

@get:Rule
Expand All @@ -48,6 +48,15 @@ class NoteListUITesting {
composeTestRule.onNodeWithTag(testTag = TestTagCloseDialog).performClick()
}

private fun editNote(originalContent: String, newContent: String) {
composeTestRule.onNodeWithText(text = originalContent).performClick()
composeTestRule.onNodeWithTag(testTag = TestTagSelectDialogTextField).performClick()
.performTextClearance()
composeTestRule.onNodeWithTag(testTag = TestTagSelectDialogTextField).performClick()
.performTextInput(text = newContent)
composeTestRule.onNodeWithTag(testTag = TestTagCloseDialog).performClick()
}

private fun changeSortType(sortType: SortType) {
composeTestRule.onNodeWithTag(testTag = TestTagChangeSortType).performClick()
composeTestRule.onNodeWithText(text = sortType.toString().lowercase()).performClick()
Expand Down Expand Up @@ -124,13 +133,8 @@ class NoteListUITesting {
@Test
fun editNote() = runTest {
val changedNoteText = "Something"
editNote(originalContent = "Node1", newContent = changedNoteText)

composeTestRule.onNodeWithText("Note1").performClick()
composeTestRule.onNodeWithTag(testTag = TestTagSelectDialogTextField).performClick()
.performTextClearance()
composeTestRule.onNodeWithTag(testTag = TestTagSelectDialogTextField).performClick()
.performTextInput(text = changedNoteText)
composeTestRule.onNodeWithTag(testTag = TestTagCloseDialog).performClick()
composeTestRule.onNodeWithText(text = changedNoteText).assertExists()
}

Expand All @@ -147,11 +151,23 @@ class NoteListUITesting {
}

@Test
fun checkSortingNotesTimeStamp() {
changeSortType(SortType.TIMESTAMP)
fun checkSortingNotesCreationTime() {
changeSortType(SortType.CREATION_TIME)

val sortedNotes = notes.sortedBy { it.timeStamp }
val sortedNotes = notes.sortedBy { it.creationTime }

for (i in sortedNotes.indices) {
composeTestRule.onNodeWithTag(testTag = TestTagNotesListColumns).onChildAt(index = i)
.assertTextContains(value = sortedNotes[i].content)
}
}

@Test
fun checkSortingNotesUpdatedTime() {
changeSortType(SortType.UPDATED_TIME)

val sortedNotes = notes.sortedBy { it.updatedTime }

for (i in sortedNotes.indices) {
composeTestRule.onNodeWithTag(testTag = TestTagNotesListColumns).onChildAt(index = i)
.assertTextContains(value = sortedNotes[i].content)
Expand All @@ -160,7 +176,8 @@ class NoteListUITesting {

@Test
fun checkChangingSortingNotes() {
checkSortingNotesTimeStamp()
checkSortingNotesCreationTime()
checkSortingNotesUpdatedTime()
checkSortingNotesContent()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.room.PrimaryKey
@Entity
data class Note(
var content: String = "",
var timeStamp: Long = 0,
var creationTime: Long = 0,
var updatedTime: Long = 0,
@PrimaryKey(autoGenerate = true) val uid: Int? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class GetNotes(private val repository: NoteRepository) {
when (sortType) {
SortType.ID -> notes.sortedBy { it.uid }
SortType.CONTENT -> notes.sortedBy { it.content.lowercase() }
SortType.TIMESTAMP -> notes.sortedBy { it.timeStamp }
SortType.CREATION_TIME -> notes.sortedBy { it.creationTime }
SortType.UPDATED_TIME -> notes.sortedBy { it.updatedTime }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package com.learning.simplenotetakingapplication.f_notetaking.domain.util
enum class SortType {
ID,
CONTENT,
TIMESTAMP
CREATION_TIME,
UPDATED_TIME
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ class NoteListViewModel(private val noteUseCases: NoteUseCases) : ViewModel() {
is NoteListEvent.UpdateSortType -> _sortType.value = event.sortType
NoteListEvent.SaveNote -> {
if (_state.value.newNoteContent.isBlank()) return
if (_state.value.currentNote.creationTime == 0.toLong()) {
_state.value.currentNote.creationTime = System.currentTimeMillis()
}

_state.value.currentNote.updatedTime = System.currentTimeMillis()
_state.value.currentNote.content = _state.value.newNoteContent
_state.value.currentNote.timeStamp = System.currentTimeMillis()
viewModelScope.launch { noteUseCases.upsertNote(_state.value.currentNote) }
onEvent(NoteListEvent.SetNote(note = Note()))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ class NoteUseCasesTest {

@Test
fun gettingNotesOrderedTimeStamp() = runTest {
val listNotes = flattenNotesFlowToList(noteUseCases.getNotes(sortType = SortType.TIMESTAMP))
assertEquals("", notes.sortedBy { it.timeStamp }, listNotes)
val listNotes =
flattenNotesFlowToList(noteUseCases.getNotes(sortType = SortType.CREATION_TIME))
assertEquals("", notes.sortedBy { it.creationTime }, listNotes)
}

@Test
Expand Down