-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show shortcuts for enabled features only (#3193)
Task/Issue URL: https://app.asana.com/0/72649045549333/1207977496450580/f Tech Design URL: CC: **Description**: Some features are available conditionally. These should not be visible on NTP and in settings. **Steps to test this PR**: 1. Enable New Tab Page sections in Debug menu. 2. Reorder shortcuts and enable/disable as you see fit. 3. Change shortcuts visibility in `NewTabPageShortcutsSettingsModel.swift` 4. Make sure only allowed shortcuts are visible. 5. Reorder and enable/disable once again. 6. Verify the order and settings are preserved. 7. Re-enable all shortcuts in `NewTabPageShortcutsSettingsModel.swift`. 8. Verify all shortcuts are visible.
- Loading branch information
Showing
4 changed files
with
170 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
DuckDuckGoTests/NewTabPageShortcutsSettingsStorageTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// | ||
// NewTabPageShortcutsSettingsStorageTests.swift | ||
// DuckDuckGo | ||
// | ||
// 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 | ||
|
||
final class NewTabPageSettingsModelTests: XCTestCase { | ||
|
||
private let storage = StorageMock(itemsOrder: SettingsItemMock.allCases) | ||
|
||
func testFiltersSettingsUsingProvidedFilter() { | ||
let sut = createSUT { item in | ||
item != .two | ||
} | ||
|
||
XCTAssertFalse(sut.enabledItems.contains(.two)) | ||
} | ||
|
||
func testMovingReordersFullSet() { | ||
let sut = createSUT { item in | ||
item != .two | ||
} | ||
|
||
sut.moveItems(from: IndexSet(integer: 0), to: 1) | ||
|
||
XCTAssertEqual(storage.itemsOrder, [.two, .one, .three]) | ||
} | ||
|
||
func testMovingItemToEndWhenNoFilter() { | ||
let sut = createSUT() | ||
|
||
sut.moveItems(from: IndexSet(integer: 0), to: 3) | ||
|
||
XCTAssertEqual(storage.itemsOrder, [.two, .three, .one]) | ||
} | ||
|
||
func testMovingItemToEndWhenFiltered() { | ||
let sut = createSUT { item in | ||
item != .two | ||
} | ||
|
||
sut.moveItems(from: IndexSet(integer: 0), to: 2) | ||
|
||
XCTAssertEqual(storage.itemsOrder, [.two, .three, .one]) | ||
} | ||
|
||
func testMovingToStartWhenFiltered() { | ||
let sut = createSUT { item in | ||
item != .one | ||
} | ||
|
||
sut.moveItems(from: IndexSet(integer: 1), to: 0) | ||
|
||
XCTAssertEqual(storage.itemsOrder, [.one, .three, .two]) | ||
} | ||
|
||
func testItemsSettingsAreFiltered() { | ||
let sut = createSUT { item in | ||
item != .one | ||
} | ||
|
||
XCTAssertEqual(sut.itemsSettings.map(\.item), [.two, .three]) | ||
} | ||
|
||
func testEnabledItemsAreFiltered() { | ||
let sut = createSUT { item in | ||
item != .one | ||
} | ||
|
||
XCTAssertEqual(sut.enabledItems, [.two, .three]) | ||
} | ||
|
||
private func createSUT(filter: @escaping (SettingsItemMock) -> Bool = { _ in true }) -> NewTabPageSettingsModel<SettingsItemMock, StorageMock> { | ||
NewTabPageSettingsModel(settingsStorage: storage, visibilityFilter: filter) | ||
} | ||
} | ||
|
||
private final class StorageMock: NewTabPageSettingsStorage { | ||
var itemsOrder: [SettingsItemMock] | ||
|
||
init(itemsOrder: [SettingsItemMock]) { | ||
self.itemsOrder = itemsOrder | ||
} | ||
|
||
func isEnabled(_ item: SettingsItemMock) -> Bool { | ||
return true | ||
} | ||
|
||
func setItem(_ item: SettingsItemMock, enabled: Bool) { | ||
|
||
} | ||
|
||
func moveItems(_ fromOffsets: IndexSet, toOffset: Int) { | ||
itemsOrder.move(fromOffsets: fromOffsets, toOffset: toOffset) | ||
} | ||
|
||
func save() { | ||
} | ||
} | ||
|
||
private enum SettingsItemMock: CaseIterable, NewTabPageSettingsStorageItem { | ||
case one | ||
case two | ||
case three | ||
} |