diff --git a/NativeAppTemplate/UI/Shop List/ShopListView.swift b/NativeAppTemplate/UI/Shop List/ShopListView.swift index 57f6979..a66bcdd 100644 --- a/NativeAppTemplate/UI/Shop List/ShopListView.swift +++ b/NativeAppTemplate/UI/Shop List/ShopListView.swift @@ -129,9 +129,19 @@ private extension ShopListView { } } } - .navigationTitle(String.shops) .navigationBarTitleDisplayMode(.inline) .toolbar { + ToolbarItem(placement: .principal) { + VStack(spacing: 0) { + Text(String.shops) + .font(.uiHeadline) + if !viewModel.accountName.isEmpty { + Text(viewModel.accountName) + .font(.uiCaption) + .foregroundStyle(.secondary) + } + } + } if viewModel.leftInShopSlots > 0 { ToolbarItem(placement: .navigationBarTrailing) { Button { diff --git a/NativeAppTemplate/UI/Shop List/ShopListViewModel.swift b/NativeAppTemplate/UI/Shop List/ShopListViewModel.swift index 4b6d59f..4ddce6a 100644 --- a/NativeAppTemplate/UI/Shop List/ShopListViewModel.swift +++ b/NativeAppTemplate/UI/Shop List/ShopListViewModel.swift @@ -35,6 +35,10 @@ final class ShopListViewModel { limitCount - createdShopsCount } + var accountName: String { + sessionController.shopkeeper?.accountName ?? "" + } + var shouldPopToRootView: Bool { sessionController.shouldPopToRootView } diff --git a/NativeAppTemplateTests/UI/Shop List/ShopListViewModelTest.swift b/NativeAppTemplateTests/UI/Shop List/ShopListViewModelTest.swift index d28436a..14b631a 100644 --- a/NativeAppTemplateTests/UI/Shop List/ShopListViewModelTest.swift +++ b/NativeAppTemplateTests/UI/Shop List/ShopListViewModelTest.swift @@ -46,6 +46,47 @@ struct ShopListViewModelTest { #expect(viewModel.leftInShopSlots == 3) } + @Test("Account name from shopkeeper") + func accountName() { + sessionController.shopkeeper = Shopkeeper(dictionary: [ + "id": "1", + "account_id": "1", + "personal_account_id": "1", + "account_owner_id": "1", + "account_name": "Account1", + "email": "email@example.com", + "name": "John Smith", + "time_zone": "Tokyo", + "uid": "email@example.com", + "token": "token", + "client": "client", + "expiry": "123456789" + ]) + + let viewModel = ShopListViewModel( + sessionController: sessionController, + shopRepository: shopRepository, + tabViewModel: tabViewModel, + mainTab: mainTab + ) + + #expect(viewModel.accountName == "Account1") + } + + @Test("Account name when no shopkeeper") + func accountNameEmpty() { + sessionController.shopkeeper = nil + + let viewModel = ShopListViewModel( + sessionController: sessionController, + shopRepository: shopRepository, + tabViewModel: tabViewModel, + mainTab: mainTab + ) + + #expect(viewModel.accountName == "") + } + @Test("Should pop to root view", arguments: [false, true]) func shouldPopToRootView(shouldPopToRootView: Bool) { sessionController.shouldPopToRootView = shouldPopToRootView