Skip to content

Commit

Permalink
Add unit tests to BookmarksSortMode enum
Browse files Browse the repository at this point in the history
  • Loading branch information
jotaemepereira committed Jul 19, 2024
1 parent c34d7af commit 9cf9fe3
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
6 changes: 6 additions & 0 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2539,6 +2539,8 @@
BBDFDC5D2B2B8E2100F62D90 /* DataBrokerProtectionExternalWaitlistPixels.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBDFDC592B2B8A0900F62D90 /* DataBrokerProtectionExternalWaitlistPixels.swift */; };
BBFB727F2C48047C0088884C /* SortBookmarksViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBFB727E2C48047C0088884C /* SortBookmarksViewModel.swift */; };
BBFB72802C48047C0088884C /* SortBookmarksViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBFB727E2C48047C0088884C /* SortBookmarksViewModel.swift */; };
BBFF355D2C4AF26200DA3289 /* BookmarksSortModeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBFF355C2C4AF26200DA3289 /* BookmarksSortModeTests.swift */; };
BBFF355E2C4AF26200DA3289 /* BookmarksSortModeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBFF355C2C4AF26200DA3289 /* BookmarksSortModeTests.swift */; };
BD384AC92BBC821A00EF3735 /* vpn-dark-mode.json in Resources */ = {isa = PBXBuildFile; fileRef = BD384AC82BBC821100EF3735 /* vpn-dark-mode.json */; };
BD384ACA2BBC821A00EF3735 /* vpn-light-mode.json in Resources */ = {isa = PBXBuildFile; fileRef = BD384AC72BBC821100EF3735 /* vpn-light-mode.json */; };
BD384ACB2BBC821B00EF3735 /* vpn-dark-mode.json in Resources */ = {isa = PBXBuildFile; fileRef = BD384AC82BBC821100EF3735 /* vpn-dark-mode.json */; };
Expand Down Expand Up @@ -4216,6 +4218,7 @@
BBB881872C4029BA001247C6 /* BookmarkListTreeControllerSearchDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkListTreeControllerSearchDataSource.swift; sourceTree = "<group>"; };
BBDFDC592B2B8A0900F62D90 /* DataBrokerProtectionExternalWaitlistPixels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataBrokerProtectionExternalWaitlistPixels.swift; sourceTree = "<group>"; };
BBFB727E2C48047C0088884C /* SortBookmarksViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SortBookmarksViewModel.swift; sourceTree = "<group>"; };
BBFF355C2C4AF26200DA3289 /* BookmarksSortModeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarksSortModeTests.swift; sourceTree = "<group>"; };
BD384AC72BBC821100EF3735 /* vpn-light-mode.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "vpn-light-mode.json"; sourceTree = "<group>"; };
BD384AC82BBC821100EF3735 /* vpn-dark-mode.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "vpn-dark-mode.json"; sourceTree = "<group>"; };
BDA7647B2BC497BE00D0400C /* DefaultVPNLocationFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DefaultVPNLocationFormatter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6657,6 +6660,7 @@
9F26060D2B85E17D00819292 /* AddEditBookmarkDialogCoordinatorViewModelTests.swift */,
9F0FFFB32BCCAE37007C87DD /* BookmarkAllTabsDialogCoordinatorViewModelTests.swift */,
9FA5A0A82BC900FC00153786 /* BookmarkAllTabsDialogViewModelTests.swift */,
BBFF355C2C4AF26200DA3289 /* BookmarksSortModeTests.swift */,
);
path = ViewModels;
sourceTree = "<group>";
Expand Down Expand Up @@ -10855,6 +10859,7 @@
3706FE49293F661700E42796 /* BookmarkNodePathTests.swift in Sources */,
1DE03425298BC7F000CAB3D7 /* InternalUserDeciderStoreMock.swift in Sources */,
3706FE4A293F661700E42796 /* BookmarkManagedObjectTests.swift in Sources */,
BBFF355E2C4AF26200DA3289 /* BookmarksSortModeTests.swift in Sources */,
EEC8EB402982CD550065AA39 /* JSAlertViewModelTests.swift in Sources */,
BDA764922BC4E57200D0400C /* MockVPNLocationFormatter.swift in Sources */,
3706FE4B293F661700E42796 /* BookmarksHTMLImporterTests.swift in Sources */,
Expand Down Expand Up @@ -12236,6 +12241,7 @@
37CD54BB27F25A4000F1F7B9 /* DownloadsPreferencesTests.swift in Sources */,
4BE344EE2B2376DF003FC223 /* VPNFeedbackFormViewModelTests.swift in Sources */,
9F872D9D2B9058D000138637 /* Bookmarks+TabTests.swift in Sources */,
BBFF355D2C4AF26200DA3289 /* BookmarksSortModeTests.swift in Sources */,
9F3910622B68C35600CB5112 /* DownloadsTabExtensionTests.swift in Sources */,
4B9DB0562A983B55000927DB /* MockNotificationService.swift in Sources */,
4B02199C25E063DE00ED7DEA /* FireproofDomainsTests.swift in Sources */,
Expand Down
103 changes: 103 additions & 0 deletions UnitTests/Bookmarks/ViewModels/BookmarksSortModeTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//

Check failure on line 1 in UnitTests/Bookmarks/ViewModels/BookmarksSortModeTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Header comments should be consistent with project patterns (file_header)
// SortBookmarksViewModelTests.swift
//
// Copyright © 2024 DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import XCTest
@testable import DuckDuckGo_Privacy_Browser

class BookmarksSortModeTests: XCTestCase {

func testTitle() {
XCTAssertEqual(BookmarksSortMode.manual.title, UserText.bookmarksSortManual)
XCTAssertEqual(BookmarksSortMode.nameAscending.title, UserText.bookmarksSortByNameAscending)
XCTAssertEqual(BookmarksSortMode.nameDescending.title, UserText.bookmarksSortByNameDescending)
}

func testAction() {
XCTAssertEqual(BookmarksSortMode.manual.action, #selector(BookmarkSortMenuItemSelectors.manualSort(_:)))
XCTAssertEqual(BookmarksSortMode.nameAscending.action, #selector(BookmarkSortMenuItemSelectors.sortByNameAscending(_:)))
XCTAssertEqual(BookmarksSortMode.nameDescending.action, #selector(BookmarkSortMenuItemSelectors.sortByNameDescending(_:)))
}

func testShouldHighlightButton() {
XCTAssertFalse(BookmarksSortMode.manual.shouldHighlightButton)
XCTAssertTrue(BookmarksSortMode.nameAscending.shouldHighlightButton)
XCTAssertTrue(BookmarksSortMode.nameDescending.shouldHighlightButton)
}

func testMenuForManual() {
let manualMenu = BookmarksSortMode.manual.menu

XCTAssertEqual(manualMenu.items.count, 5)

XCTAssertEqual(manualMenu.items[0].title, UserText.bookmarksSortManual)
XCTAssertEqual(manualMenu.items[0].state, .on)

XCTAssertEqual(manualMenu.items[1].title, UserText.bookmarksSortByName)
XCTAssertEqual(manualMenu.items[1].state, .off)

XCTAssert(manualMenu.items[2].isSeparatorItem)

XCTAssertEqual(manualMenu.items[3].title, UserText.bookmarksSortByNameAscending)
XCTAssertEqual(manualMenu.items[3].state, .off)
XCTAssertNil(manualMenu.items[3].action)

XCTAssertEqual(manualMenu.items[4].title, UserText.bookmarksSortByNameDescending)
XCTAssertEqual(manualMenu.items[4].state, .off)
XCTAssertNil(manualMenu.items[4].action)
}

func testMenuForNameAscending() {
let ascendingMenu = BookmarksSortMode.nameAscending.menu

XCTAssertEqual(ascendingMenu.items.count, 5)

XCTAssertEqual(ascendingMenu.items[0].title, UserText.bookmarksSortManual)
XCTAssertEqual(ascendingMenu.items[0].state, .off)

XCTAssertEqual(ascendingMenu.items[1].title, UserText.bookmarksSortByName)
XCTAssertEqual(ascendingMenu.items[1].state, .on)

XCTAssert(ascendingMenu.items[2].isSeparatorItem)

XCTAssertEqual(ascendingMenu.items[3].title, UserText.bookmarksSortByNameAscending)
XCTAssertEqual(ascendingMenu.items[3].state, .on)

XCTAssertEqual(ascendingMenu.items[4].title, UserText.bookmarksSortByNameDescending)
XCTAssertEqual(ascendingMenu.items[4].state, .off)
}

func testMenuForNameDescending() {
let descendingMenu = BookmarksSortMode.nameDescending.menu

XCTAssertEqual(descendingMenu.items.count, 5)

XCTAssertEqual(descendingMenu.items[0].title, UserText.bookmarksSortManual)
XCTAssertEqual(descendingMenu.items[0].state, .off)

XCTAssertEqual(descendingMenu.items[1].title, UserText.bookmarksSortByName)
XCTAssertEqual(descendingMenu.items[1].state, .on)

XCTAssert(descendingMenu.items[2].isSeparatorItem)

XCTAssertEqual(descendingMenu.items[3].title, UserText.bookmarksSortByNameAscending)
XCTAssertEqual(descendingMenu.items[3].state, .off)

XCTAssertEqual(descendingMenu.items[4].title, UserText.bookmarksSortByNameDescending)
XCTAssertEqual(descendingMenu.items[4].state, .on)
}
}

0 comments on commit 9cf9fe3

Please sign in to comment.