<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import XCTest
@testable import Client
import Shared

class MenuTests: XCTestCase {

    override func setUp() {
        super.setUp()
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }

    func appState(ui: UIState) -> AppState {
        let prefs = MockProfilePrefs()
        prefs.setString("http://mozilla.com", forKey: HomePageConstants.HomePageURLPrefKey)
        return AppState(ui: ui, prefs: prefs)
    }

    func testMenuConfigurationForBrowser() {
        var tabState = TabState(isPrivate: false, desktopSite: false, isBookmarked: false, url: NSURL(string: "http://mozilla.com")!, title: "Mozilla", favicon: nil)
        var browserConfiguration = AppMenuConfiguration(appState: appState(.Tab(tabState: tabState)))
        XCTAssertEqual(browserConfiguration.menuItems.count, 7)
        XCTAssertEqual(browserConfiguration.menuItems[0].title, AppMenuConfiguration.FindInPageTitleString)
        XCTAssertEqual(browserConfiguration.menuItems[1].title, AppMenuConfiguration.ViewDesktopSiteTitleString)
        XCTAssertEqual(browserConfiguration.menuItems[2].title, AppMenuConfiguration.OpenHomePageTitleString)
        XCTAssertEqual(browserConfiguration.menuItems[3].title, AppMenuConfiguration.NewTabTitleString)
        XCTAssertEqual(browserConfiguration.menuItems[4].title, AppMenuConfiguration.NewPrivateTabTitleString)
        XCTAssertEqual(browserConfiguration.menuItems[5].title, AppMenuConfiguration.AddBookmarkTitleString)
        XCTAssertEqual(browserConfiguration.menuItems[6].title, AppMenuConfiguration.SettingsTitleString)

        XCTAssertNotNil(browserConfiguration.menuToolbarItems)
        XCTAssertEqual(browserConfiguration.menuToolbarItems!.count, 4)
        XCTAssertEqual(browserConfiguration.menuToolbarItems![0].title, AppMenuConfiguration.TopSitesTitleString)
        XCTAssertEqual(browserConfiguration.menuToolbarItems![1].title, AppMenuConfiguration.BookmarksTitleString)
        XCTAssertEqual(browserConfiguration.menuToolbarItems![2].title, AppMenuConfiguration.HistoryTitleString)
        XCTAssertEqual(browserConfiguration.menuToolbarItems![3].title, AppMenuConfiguration.ReadingListTitleString)


        tabState = TabState(isPrivate: true, desktopSite: true, isBookmarked: true, url: NSURL(string: "http://mozilla.com")!, title: "Mozilla", favicon: nil)
        browserConfiguration = AppMenuConfiguration(appState: appState(.Tab(tabState: tabState)))
        XCTAssertEqual(browserConfiguration.menuItems.count, 7)
        XCTAssertEqual(browserConfiguration.menuItems[0].title, AppMenuConfiguration.FindInPageTitleString)
        XCTAssertEqual(browserConfiguration.menuItems[1].title, AppMenuConfiguration.ViewMobileSiteTitleString)
        XCTAssertEqual(browserConfiguration.menuItems[2].title, AppMenuConfiguration.OpenHomePageTitleString)
        XCTAssertEqual(browserConfiguration.menuItems[3].title, AppMenuConfiguration.NewTabTitleString)
        XCTAssertEqual(browserConfiguration.menuItems[4].title, AppMenuConfiguration.NewPrivateTabTitleString)
        XCTAssertEqual(browserConfiguration.menuItems[5].title, AppMenuConfiguration.RemoveBookmarkTitleString)
        XCTAssertEqual(browserConfiguration.menuItems[6].title, AppMenuConfiguration.SettingsTitleString)


        XCTAssertNotNil(browserConfiguration.menuToolbarItems)
        XCTAssertEqual(browserConfiguration.menuToolbarItems!.count, 4)
        XCTAssertEqual(browserConfiguration.menuToolbarItems![0].title, AppMenuConfiguration.TopSitesTitleString)
        XCTAssertEqual(browserConfiguration.menuToolbarItems![1].title, AppMenuConfiguration.BookmarksTitleString)
        XCTAssertEqual(browserConfiguration.menuToolbarItems![2].title, AppMenuConfiguration.HistoryTitleString)
        XCTAssertEqual(browserConfiguration.menuToolbarItems![3].title, AppMenuConfiguration.ReadingListTitleString)
    }

    func testMenuConfigurationForHomePanels() {
        let homePanelState = HomePanelState(isPrivate: false, selectedIndex: 0)
        let homePanelConfiguration = AppMenuConfiguration(appState: appState(.HomePanels(homePanelState: homePanelState)))
        XCTAssertEqual(homePanelConfiguration.menuItems.count, 3)
        XCTAssertEqual(homePanelConfiguration.menuItems[0].title, AppMenuConfiguration.NewTabTitleString)
        XCTAssertEqual(homePanelConfiguration.menuItems[1].title, AppMenuConfiguration.NewPrivateTabTitleString)
        XCTAssertEqual(homePanelConfiguration.menuItems[2].title, AppMenuConfiguration.SettingsTitleString)

        XCTAssertNil(homePanelConfiguration.menuToolbarItems)
    }

    func testMenuConfigurationForTabTray() {
        let tabTrayState = TabTrayState(isPrivate: false)
        let tabTrayConfiguration = AppMenuConfiguration(appState: appState(.TabTray(tabTrayState: tabTrayState)))
        XCTAssertEqual(tabTrayConfiguration.menuItems.count, 4)
        XCTAssertEqual(tabTrayConfiguration.menuItems[0].title, AppMenuConfiguration.NewTabTitleString)
        XCTAssertEqual(tabTrayConfiguration.menuItems[1].title, AppMenuConfiguration.NewPrivateTabTitleString)<commit_msg>Bug 1274617 – Fix up Menu Tests. (#1844)<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import XCTest
@testable import Client
import Shared

class MenuTests: XCTestCase {

    override func setUp() {
        super.setUp()
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }

    func appState(ui: UIState) -> AppState {
        let prefs = MockProfilePrefs()
        prefs.setString("http://mozilla.com", forKey: HomePageConstants.HomePageURLPrefKey)
        return AppState(ui: ui, prefs: prefs)
    }

    func testMenuConfigurationForBrowser() {
        var tabState = TabState(isPrivate: false, desktopSite: false, isBookmarked: false, url: NSURL(string: "http://mozilla.com")!, title: "Mozilla", favicon: nil)
        var browserConfiguration = AppMenuConfiguration(appState: appState(.Tab(tabState: tabState)))
        XCTAssertEqual(browserConfiguration.menuItems.count, 7)
        XCTAssertEqual(browserConfiguration.menuItems[0].title, AppMenuConfiguration.FindInPageTitleString)
        XCTAssertEqual(browserConfiguration.menuItems[1].title, AppMenuConfiguration.ViewDesktopSiteTitleString)
        XCTAssertEqual(browserConfiguration.menuItems[2].title, AppMenuConfiguration.OpenHomePageTitleString)
        XCTAssertEqual(browserConfiguration.menuItems[3].title, AppMenuConfiguration.NewTabTitleString)
        XCTAssertEqual(browserConfiguration.menuItems[4].title, AppMenuConfiguration.NewPrivateTabTitleString)
        XCTAssertEqual(browserConfiguration.menuItems[5].title, AppMenuConfiguration.AddBookmarkTitleString)
        XCTAssertEqual(browserConfiguration.menuItems[6].title, AppMenuConfiguration.SettingsTitleString)

        XCTAssertNotNil(browserConfiguration.menuToolbarItems)
        XCTAssertEqual(browserConfiguration.menuToolbarItems!.count, 4)
        XCTAssertEqual(browserConfiguration.menuToolbarItems![0].title, AppMenuConfiguration.TopSitesTitleString)
        XCTAssertEqual(browserConfiguration.menuToolbarItems![1].title, AppMenuConfiguration.BookmarksTitleString)
        XCTAssertEqual(browserConfiguration.menuToolbarItems![2].title, AppMenuConfiguration.HistoryTitleString)
        XCTAssertEqual(browserConfiguration.menuToolbarItems![3].title, AppMenuConfiguration.ReadingListTitleString)


        tabState = TabState(isPrivate: true, desktopSite: true, isBookmarked: true, url: NSURL(string: "http://mozilla.com")!, title: "Mozilla", favicon: nil)
        browserConfiguration = AppMenuConfiguration(appState: appState(.Tab(tabState: tabState)))
        XCTAssertEqual(browserConfiguration.menuItems.count, 7)
        XCTAssertEqual(browserConfiguration.menuItems[0].title, AppMenuConfiguration.FindInPageTitleString)
        XCTAssertEqual(browserConfiguration.menuItems[1].title, AppMenuConfiguration.ViewMobileSiteTitleString)
        XCTAssertEqual(browserConfiguration.menuItems[2].title, AppMenuConfiguration.OpenHomePageTitleString)
        XCTAssertEqual(browserConfiguration.menuItems[3].title, AppMenuConfiguration.NewTabTitleString)
        XCTAssertEqual(browserConfiguration.menuItems[4].title, AppMenuConfiguration.NewPrivateTabTitleString)
        XCTAssertEqual(browserConfiguration.menuItems[5].title, AppMenuConfiguration.RemoveBookmarkTitleString)
        XCTAssertEqual(browserConfiguration.menuItems[6].title, AppMenuConfiguration.SettingsTitleString)


        XCTAssertNotNil(browserConfiguration.menuToolbarItems)
        XCTAssertEqual(browserConfiguration.menuToolbarItems!.count, 4)
        XCTAssertEqual(browserConfiguration.menuToolbarItems![0].title, AppMenuConfiguration.TopSitesTitleString)
        XCTAssertEqual(browserConfiguration.menuToolbarItems![1].title, AppMenuConfiguration.BookmarksTitleString)
        XCTAssertEqual(browserConfiguration.menuToolbarItems![2].title, AppMenuConfiguration.HistoryTitleString)
        XCTAssertEqual(browserConfiguration.menuToolbarItems![3].title, AppMenuConfiguration.ReadingListTitleString)
    }

    func testMenuConfigurationForHomePanels() {
        let homePanelState = HomePanelState(isPrivate: false, selectedIndex: 0)
        let homePanelConfiguration = AppMenuConfiguration(appState: appState(.HomePanels(homePanelState: homePanelState)))
        XCTAssertEqual(homePanelConfiguration.menuItems.count, 4)
        XCTAssertEqual(homePanelConfiguration.menuItems[0].title, AppMenuConfiguration.NewTabTitleString)
        XCTAssertEqual(homePanelConfiguration.menuItems[1].title, AppMenuConfiguration.NewPrivateTabTitleString)
        XCTAssertEqual(homePanelConfiguration.menuItems[2].title, AppMenuConfiguration.OpenHomePageTitleString)
        XCTAssertEqual(homePanelConfiguration.menuItems[3].title, AppMenuConfiguration.SettingsTitleString)

        XCTAssertNil(homePanelConfiguration.menuToolbarItems)
    }

    func testMenuConfigurationForTabTray() {
        let tabTrayState = TabTrayState(isPrivate: false)
        let tabTrayConfiguration = AppMenuConfiguration(appState: appState(.TabTray(tabTrayState: tabTrayState)))
        XCTAssertEqual(tabTrayConfiguration.menuItems.count, 4)
        XCTAssertEqual(tabTrayConfiguration.menuItems[0].title, AppMenuConfiguration.NewTabTitleString)
        XCTAssertEqual(tabTrayConfiguration.menuItems[1].title, AppMenuConfiguration.NewPrivateTabTitleString)
{'fraction_non_alphanumeric': 0.0821636119803308, 'fraction_numerical': 0.007867679928475637, 'mean_word_length': 5.348467650397276, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2821701', 'n_tokens_mistral': 2971, 'n_tokens_neox': 2903, 'n_words': 482}