Skip to content

Commit

Permalink
tests added for fetching localizations, generating files and writing …
Browse files Browse the repository at this point in the history
…them to disk
  • Loading branch information
andrewlloyd100 committed Aug 7, 2019
1 parent 397adc8 commit f06ed8a
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 2 deletions.
9 changes: 9 additions & 0 deletions TranslationsGeneratorTests/Translations.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// Translations.swift
// TranslationsGeneratorTests
//
// Created by Andrew Lloyd on 07/08/2019.
// Copyright © 2019 Nodes. All rights reserved.
//

import Foundation
35 changes: 33 additions & 2 deletions TranslationsGeneratorTests/TranslationsGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,45 @@ class TranslationsGeneratorTests: XCTestCase {

//This is using the Taxa api endpoints, to test with your application
//modify values accordingly
lazy var settings = GeneratorSettings.init(plistPath: nil, keys: (appID: "63z7NtttDqbYeo51eOxGezBjKzizsKhknRBc", appKey: "245T83h3auiVMGnOaRQ3N7Yagto8oEkD2VvO"), outputPath: "", flatTranslations: false, availableFromObjC: false, standalone: true, authorization: nil, extraHeaders: nil, jsonPath: "", jsonLocaleIdentifier: nil)
lazy var settings = GeneratorSettings.init(plistPath: nil, keys: (appID: "5dSr0geJis6PSTpABBR6zfwGbGZDJ2rJZW90", appKey: "XRiVQholofzxvsqxSfWsS3u8769OYszgrNck"), outputPath: "/Users/andrewlloydnodes/nstack-translations-generator/TranslationsGeneratorTests", flatTranslations: false, availableFromObjC: false, standalone: true, authorization: nil, extraHeaders: nil, jsonPath: "", jsonLocaleIdentifier: nil)


func testGenerate() throws {
func testGenerateLocalizations() throws {
XCTAssertNotNil(settings)
let dSettings = try settings.downloaderSettings()
XCTAssertNotNil(dSettings)
let localisations = try Downloader.localizationsWithDownloaderSettings(dSettings)
XCTAssertNotNil(localisations)
}

func testGetTranslationData() throws {
XCTAssertNotNil(settings)
let dSettings = try settings.downloaderSettings()
XCTAssertNotNil(dSettings)
let localisations = try Downloader.localizationsWithDownloaderSettings(dSettings)

let locale = localisations?.first
XCTAssertNotNil(locale)
let dData = try Downloader.dataWithDownloaderSettings(dSettings, localization: locale!)
XCTAssertNotNil(dData)
}

//If you want to run this test, make sure Translations.swift is empty,
//once run succesfully it will create a swift file with a required dependency
//that this project does not have (TranslationManager)
func testWriteData() throws {

XCTAssertNotNil(settings)
let dSettings = try settings.downloaderSettings()
XCTAssertNotNil(dSettings)
let localisations = try Downloader.localizationsWithDownloaderSettings(dSettings)

let locale = localisations?.first
XCTAssertNotNil(locale)
let dData = try Downloader.dataWithDownloaderSettings(dSettings, localization: locale!)
XCTAssertNotNil(dData)

let code = try Generator.writeDataToDisk(dData!, settings, localeId: "en-GB")
XCTAssert(code.count > 0)
}
}
30 changes: 30 additions & 0 deletions TranslationsGeneratorTests/Translations_da-DK.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"data" : {
"default" : {
"keyys" : "ffw",
"successKey" : "Success"
},
"oneMoreSection" : {
"soManyKeys" : "AndValues",
"test1" : "<p>test<\/p>\r\n",
"test2" : "__test2"
},
"otherSection" : {
"otherString" : "Haha"
}
},
"meta" : {
"language" : {
"direction" : "LRM",
"id" : 11,
"is_best_fit" : false,
"is_default" : false,
"locale" : "en-GB",
"name" : "English (UK)"
},
"platform" : {
"id" : 24,
"slug" : "mobile"
}
}
}
30 changes: 30 additions & 0 deletions TranslationsGeneratorTests/Translations_en-GB.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"data" : {
"default" : {
"keyys" : "ffw",
"successKey" : "Success"
},
"oneMoreSection" : {
"soManyKeys" : "AndValues",
"test1" : "<p>test<\/p>\r\n",
"test2" : "__test2"
},
"otherSection" : {
"otherString" : "Haha"
}
},
"meta" : {
"language" : {
"direction" : "LRM",
"id" : 11,
"is_best_fit" : false,
"is_default" : false,
"locale" : "en-GB",
"name" : "English (UK)"
},
"platform" : {
"id" : 24,
"slug" : "mobile"
}
}
}

0 comments on commit f06ed8a

Please sign in to comment.