Skip to content

Commit 7177086

Browse files
authored
Merge pull request #4 from DilanGoodwin/sortingNotes
2 parents f39b825 + 93d64ae commit 7177086

8 files changed

Lines changed: 48 additions & 23 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ On click handler for the note view creates dialog window for editing previous no
2222
# ToDos
2323

2424
## Main Application
25-
- [ ] Sorting notes based on creation time
26-
- [ ] Sorting notes based on last edited time
25+
- [x] Sorting notes based on creation time
26+
- [x] Sorting notes based on last edited time
2727
- [ ] Deleting notes
2828
- [ ] Viewing deleted notes
2929
- [ ] Restoring deleted notes
3030

3131
## Widget
32-
- [ ] Selection of note to view
32+
- [ ] Selection of note to view

app/src/androidTest/java/com/learning/simplenotetakingapplication/f_notetaking/data/NoteRepositoryTestingImplementation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class NoteRepositoryUiTestingImplementation(notes: List<Note>) : NoteRepository
2121
currentList.add(
2222
Note(
2323
content = note.content,
24-
timeStamp = System.currentTimeMillis(),
24+
creationTime = System.currentTimeMillis(),
2525
uid = currentList.size
2626
)
2727
)

app/src/androidTest/java/com/learning/simplenotetakingapplication/f_notetaking/presentation/NoteListUITesting.kt

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ class NoteListUITesting {
3333

3434
private lateinit var noteUseCases: NoteUseCases
3535
private val notes: List<Note> = listOf(
36-
Note(content = "Note1", timeStamp = 1740056347421, uid = 0),
37-
Note(content = "Note2", timeStamp = 1740056372073, uid = 1),
38-
Note(content = "Note3", timeStamp = 1740056372073, uid = 2)
36+
Note(content = "Note1", creationTime = 1740056347421, uid = 0),
37+
Note(content = "Note2", creationTime = 1740056372073, uid = 1),
38+
Note(content = "Note3", creationTime = 1740056372073, uid = 2)
3939
)
4040

4141
@get:Rule
@@ -48,6 +48,15 @@ class NoteListUITesting {
4848
composeTestRule.onNodeWithTag(testTag = TestTagCloseDialog).performClick()
4949
}
5050

51+
private fun editNote(originalContent: String, newContent: String) {
52+
composeTestRule.onNodeWithText(text = originalContent).performClick()
53+
composeTestRule.onNodeWithTag(testTag = TestTagSelectDialogTextField).performClick()
54+
.performTextClearance()
55+
composeTestRule.onNodeWithTag(testTag = TestTagSelectDialogTextField).performClick()
56+
.performTextInput(text = newContent)
57+
composeTestRule.onNodeWithTag(testTag = TestTagCloseDialog).performClick()
58+
}
59+
5160
private fun changeSortType(sortType: SortType) {
5261
composeTestRule.onNodeWithTag(testTag = TestTagChangeSortType).performClick()
5362
composeTestRule.onNodeWithText(text = sortType.toString().lowercase()).performClick()
@@ -124,13 +133,8 @@ class NoteListUITesting {
124133
@Test
125134
fun editNote() = runTest {
126135
val changedNoteText = "Something"
136+
editNote(originalContent = "Node1", newContent = changedNoteText)
127137

128-
composeTestRule.onNodeWithText("Note1").performClick()
129-
composeTestRule.onNodeWithTag(testTag = TestTagSelectDialogTextField).performClick()
130-
.performTextClearance()
131-
composeTestRule.onNodeWithTag(testTag = TestTagSelectDialogTextField).performClick()
132-
.performTextInput(text = changedNoteText)
133-
composeTestRule.onNodeWithTag(testTag = TestTagCloseDialog).performClick()
134138
composeTestRule.onNodeWithText(text = changedNoteText).assertExists()
135139
}
136140

@@ -147,11 +151,23 @@ class NoteListUITesting {
147151
}
148152

149153
@Test
150-
fun checkSortingNotesTimeStamp() {
151-
changeSortType(SortType.TIMESTAMP)
154+
fun checkSortingNotesCreationTime() {
155+
changeSortType(SortType.CREATION_TIME)
152156

153-
val sortedNotes = notes.sortedBy { it.timeStamp }
157+
val sortedNotes = notes.sortedBy { it.creationTime }
158+
159+
for (i in sortedNotes.indices) {
160+
composeTestRule.onNodeWithTag(testTag = TestTagNotesListColumns).onChildAt(index = i)
161+
.assertTextContains(value = sortedNotes[i].content)
162+
}
163+
}
164+
165+
@Test
166+
fun checkSortingNotesUpdatedTime() {
167+
changeSortType(SortType.UPDATED_TIME)
154168

169+
val sortedNotes = notes.sortedBy { it.updatedTime }
170+
155171
for (i in sortedNotes.indices) {
156172
composeTestRule.onNodeWithTag(testTag = TestTagNotesListColumns).onChildAt(index = i)
157173
.assertTextContains(value = sortedNotes[i].content)
@@ -160,7 +176,8 @@ class NoteListUITesting {
160176

161177
@Test
162178
fun checkChangingSortingNotes() {
163-
checkSortingNotesTimeStamp()
179+
checkSortingNotesCreationTime()
180+
checkSortingNotesUpdatedTime()
164181
checkSortingNotesContent()
165182
}
166183
}

app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/model/Note.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import androidx.room.PrimaryKey
1414
@Entity
1515
data class Note(
1616
var content: String = "",
17-
var timeStamp: Long = 0,
17+
var creationTime: Long = 0,
18+
var updatedTime: Long = 0,
1819
@PrimaryKey(autoGenerate = true) val uid: Int? = null
1920
)

app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/use_case/GetNotes.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class GetNotes(private val repository: NoteRepository) {
2424
when (sortType) {
2525
SortType.ID -> notes.sortedBy { it.uid }
2626
SortType.CONTENT -> notes.sortedBy { it.content.lowercase() }
27-
SortType.TIMESTAMP -> notes.sortedBy { it.timeStamp }
27+
SortType.CREATION_TIME -> notes.sortedBy { it.creationTime }
28+
SortType.UPDATED_TIME -> notes.sortedBy { it.updatedTime }
2829
}
2930
}
3031
}

app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/domain/util/SortType.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ package com.learning.simplenotetakingapplication.f_notetaking.domain.util
33
enum class SortType {
44
ID,
55
CONTENT,
6-
TIMESTAMP
6+
CREATION_TIME,
7+
UPDATED_TIME
78
}

app/src/main/java/com/learning/simplenotetakingapplication/f_notetaking/presentation/notelist/NoteListViewModel.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ class NoteListViewModel(private val noteUseCases: NoteUseCases) : ViewModel() {
4242
is NoteListEvent.UpdateSortType -> _sortType.value = event.sortType
4343
NoteListEvent.SaveNote -> {
4444
if (_state.value.newNoteContent.isBlank()) return
45+
if (_state.value.currentNote.creationTime == 0.toLong()) {
46+
_state.value.currentNote.creationTime = System.currentTimeMillis()
47+
}
48+
49+
_state.value.currentNote.updatedTime = System.currentTimeMillis()
4550
_state.value.currentNote.content = _state.value.newNoteContent
46-
_state.value.currentNote.timeStamp = System.currentTimeMillis()
4751
viewModelScope.launch { noteUseCases.upsertNote(_state.value.currentNote) }
4852
onEvent(NoteListEvent.SetNote(note = Note()))
4953
}

app/src/test/java/com/learning/simplenotetakingapplication/f_notetaking/domain/use_case/NoteUseCasesTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ class NoteUseCasesTest {
6666

6767
@Test
6868
fun gettingNotesOrderedTimeStamp() = runTest {
69-
val listNotes = flattenNotesFlowToList(noteUseCases.getNotes(sortType = SortType.TIMESTAMP))
70-
assertEquals("", notes.sortedBy { it.timeStamp }, listNotes)
69+
val listNotes =
70+
flattenNotesFlowToList(noteUseCases.getNotes(sortType = SortType.CREATION_TIME))
71+
assertEquals("", notes.sortedBy { it.creationTime }, listNotes)
7172
}
7273

7374
@Test

0 commit comments

Comments
 (0)