Skip to content

Commit

Permalink
CC-6787: T16478825 resolve failed testcase ensuring correct sdk used …
Browse files Browse the repository at this point in the history
…with folderlinks

(cherry picked from commit 4a80bd4)
  • Loading branch information
dg-mega committed Jun 7, 2024
1 parent 503405f commit f9ab6c9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class SetVideoPlayerItemMetadataCommandTests: XCTestCase {
node: MockNode(handle: 1),
fileManager: FileManager(),
sdk: MockSdk(),
nodeAssetManager: NodeAssetsManager()
nodeAssetManager: NodeAssetsManager(sdk: MockSdk())
)

await sut.execute()
Expand Down
10 changes: 7 additions & 3 deletions iMEGA/Cloud drive/Cells/NodeCollectionViewCell+Additions.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import MEGADesignToken
import MEGADomain
import MEGASdk
import MEGASDKRepo
import UIKit

Expand All @@ -17,16 +18,19 @@ extension NodeCollectionViewCell {
.forEach { $0?.alpha = 1 }
}

@objc func createViewModel(node: MEGANode?, isFromSharedItem: Bool) -> NodeCollectionViewCellViewModel {
@objc func createViewModel(node: MEGANode?, isFromSharedItem: Bool, sdk: MEGASdk) -> NodeCollectionViewCellViewModel {
NodeCollectionViewCellViewModel(
node: node?.toNodeEntity(),
isFromSharedItem: isFromSharedItem,
nodeUseCase: NodeUseCase(
nodeDataRepository: NodeDataRepository.newRepo,
nodeValidationRepository: NodeValidationRepository.newRepo,
nodeRepository: NodeRepository.newRepo),
thumbnailUseCase: ThumbnailUseCase(repository: ThumbnailRepository.newRepo),
nodeIconUseCase: NodeIconUseCase(nodeIconRepo: NodeAssetsManager.shared))
thumbnailUseCase: ThumbnailUseCase(repository: ThumbnailRepository(
sdk: sdk,
fileManager: .default,
nodeProvider: DefaultMEGANodeProvider(sdk: sdk))),
nodeIconUseCase: NodeIconUseCase(nodeIconRepo: NodeAssetsManager(sdk: sdk)))
}

@objc func bind(viewModel: NodeCollectionViewCellViewModel) {
Expand Down
6 changes: 3 additions & 3 deletions iMEGA/Cloud drive/Cells/NodeCollectionViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ - (void)configureCellForNode:(MEGANode *)node allowedMultipleSelection:(BOOL)mul
self.node = node;
self.delegate = delegate;

[self bindWithViewModel:[self createViewModelWithNode:node isFromSharedItem:isFromSharedItem]];
[self bindWithViewModel:[self createViewModelWithNode:node isFromSharedItem:isFromSharedItem sdk:sdk]];

if (node.isTakenDown) {
self.nameLabel.attributedText = [node attributedTakenDownName];
Expand Down Expand Up @@ -102,7 +102,7 @@ - (void)configureCellForNode:(MEGANode *)node allowedMultipleSelection:(BOOL)mul

- (void)configureCellForOfflineItem:(NSDictionary *)item itemPath:(NSString *)pathForItem allowedMultipleSelection:(BOOL)multipleSelection sdk:(nonnull MEGASdk *)sdk delegate:(id<NodeCollectionViewCellDelegate> _Nullable)delegate {

[self bindWithViewModel:[self createViewModelWithNode:nil isFromSharedItem:NO]];
[self bindWithViewModel:[self createViewModelWithNode:nil isFromSharedItem:NO sdk: sdk]];

self.favouriteView.hidden = self.linkView.hidden = self.versionedView.hidden = self.topNodeIconsView.hidden = YES;
self.labelView.hidden = self.downloadedImageView.hidden = self.downloadedView.hidden = YES;
Expand Down Expand Up @@ -182,7 +182,7 @@ - (void)configureCellForOfflineItem:(NSDictionary *)item itemPath:(NSString *)pa
}

- (void)configureCellForFolderLinkNode:(MEGANode *)node allowedMultipleSelection:(BOOL)multipleSelection sdk:(nonnull MEGASdk *)sdk delegate:(id<NodeCollectionViewCellDelegate> _Nullable)delegate {
[self configureCellForNode:node allowedMultipleSelection:multipleSelection isFromSharedItem:NO sdk:sdk delegate:delegate];
[self configureCellForNode:node allowedMultipleSelection:multipleSelection isFromSharedItem:YES sdk:sdk delegate:delegate];

if (self.downloadedImageView != nil) {
if ([node isFile] && [MEGAStore.shareInstance offlineNodeWithNode:node] != nil) {
Expand Down
17 changes: 12 additions & 5 deletions iMEGA/Utils/NodeAssetsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import MEGARepo
import MEGASDKRepo

@objc final class NodeAssetsManager: NSObject {
@objc static var shared = NodeAssetsManager()
@objc static var shared = NodeAssetsManager(sdk: .shared)

private let sdk: MEGASdk

init(sdk: MEGASdk) {
self.sdk = sdk
}

@objc func icon(for node: MEGANode) -> UIImage {
switch node.type {
Expand Down Expand Up @@ -81,9 +87,10 @@ enum FileExtensionType: String {

extension NodeAssetsManager: NodeIconRepositoryProtocol {
func iconData(for node: MEGADomain.NodeEntity) -> Data {
let sdk = MEGASdk.shared
guard let megaNode = node.toMEGANode(in: sdk) else { return Data() }

return icon(for: megaNode).pngData() ?? Data()
guard let megaNode = node.toMEGANode(in: sdk),
let icon = icon(for: megaNode).pngData() else {
return Data()
}
return icon
}
}

0 comments on commit f9ab6c9

Please sign in to comment.