|
| 1 | +jest.mock("danger", () => jest.fn()) |
| 2 | +import danger from 'danger' |
| 3 | +const dm = danger as any; |
| 4 | + |
| 5 | +import { localizedStrings } from '../org/allPRs' |
| 6 | + |
| 7 | +beforeEach(() => { |
| 8 | + dm.addedLines = "" |
| 9 | + dm.message = jest.fn().mockReturnValue(true); |
| 10 | + |
| 11 | + dm.danger = { |
| 12 | + git: { |
| 13 | + diffForFile: async (_filename) => { |
| 14 | + return { added: dm.addedLines } |
| 15 | + }, |
| 16 | + modified_files: [ |
| 17 | + "file1.swift", |
| 18 | + "file2.swift" |
| 19 | + ], |
| 20 | + }, |
| 21 | + github: { |
| 22 | + pr: { |
| 23 | + additions: 200, |
| 24 | + deletions: 10 |
| 25 | + }, |
| 26 | + thisPR: { |
| 27 | + repo: "iOS" |
| 28 | + }, |
| 29 | + }, |
| 30 | + } |
| 31 | +}) |
| 32 | + |
| 33 | +describe("Localized Strings checks", () => { |
| 34 | + it("does not message with no changes", async () => { |
| 35 | + dm.danger.git.modified_files = [] |
| 36 | + |
| 37 | + await localizedStrings() |
| 38 | + |
| 39 | + expect(dm.message).not.toHaveBeenCalled() |
| 40 | + }) |
| 41 | + |
| 42 | + it("does not message with no diff", async () => { |
| 43 | + dm.danger.git.diffForFile = async (_filename) => {} |
| 44 | + |
| 45 | + await localizedStrings() |
| 46 | + |
| 47 | + expect(dm.message).not.toHaveBeenCalled() |
| 48 | + }) |
| 49 | + |
| 50 | + it("does not message with no additions", async () => { |
| 51 | + await localizedStrings() |
| 52 | + |
| 53 | + expect(dm.message).not.toHaveBeenCalled() |
| 54 | + }) |
| 55 | + |
| 56 | + it("does not message with added code that doesn't contain NSLocalizedString", async () => { |
| 57 | + dm.addedLines = ` |
| 58 | ++ fileprivate struct Constants { |
| 59 | ++ static let databaseName = "Database" |
| 60 | ++ } |
| 61 | ++ |
| 62 | + ` |
| 63 | + |
| 64 | + await localizedStrings() |
| 65 | + |
| 66 | + expect(dm.message).not.toHaveBeenCalled() |
| 67 | + }) |
| 68 | + |
| 69 | + it("does not message with added code that mentions NSLocalizedString but doesn't call it", async () => { |
| 70 | + dm.addedLines = ` |
| 71 | ++ // We're not using NSLocalizedString here. |
| 72 | + ` |
| 73 | + |
| 74 | + await localizedStrings() |
| 75 | + |
| 76 | + expect(dm.message).not.toHaveBeenCalled() |
| 77 | + }) |
| 78 | + |
| 79 | + it("messages with added code that contains NSLocalizedString call, including iOS Localization guidelines URL when run for iOS repo", async () => { |
| 80 | + dm.danger.github.thisPR.repo = "iOS" |
| 81 | + dm.addedLines = ` |
| 82 | ++ let title = NSLocalizedString("title", comment: "Title") |
| 83 | + ` |
| 84 | + |
| 85 | + await localizedStrings() |
| 86 | + |
| 87 | + expect(dm.message).toHaveBeenCalledWith("You seem to be updating localized strings. Make sure that you request translations and include translated strings before you ship your change. See [Localization Guidelines](https://app.asana.com/0/0/1185863667140706/f) for more information.") |
| 88 | + }) |
| 89 | + |
| 90 | + it("messages with added code that contains NSLocalizedString call, including macOS Localization guidelines URL when run for macos-browser repo", async () => { |
| 91 | + dm.danger.github.thisPR.repo = "macos-browser" |
| 92 | + dm.addedLines = ` |
| 93 | ++ let title = NSLocalizedString("title", comment: "Title") |
| 94 | + ` |
| 95 | + |
| 96 | + await localizedStrings() |
| 97 | + |
| 98 | + expect(dm.message).toHaveBeenCalledWith("You seem to be updating localized strings. Make sure that you request translations and include translated strings before you ship your change. See [Localization Guidelines](https://app.asana.com/0/0/1206727265537758/f) for more information.") |
| 99 | + }) |
| 100 | + |
| 101 | + it("messages with UserText.swift-style added code, including iOS Localization guidelines URL when run for iOS repo", async () => { |
| 102 | + dm.danger.github.thisPR.repo = "iOS" |
| 103 | + dm.addedLines = ` |
| 104 | ++ static let mainMenuAppCheckforUpdates = NSLocalizedString("main-menu.app.check-for-updates", value: "Check for Updates!", comment: "Main Menu DuckDuckGo item") |
| 105 | + ` |
| 106 | + |
| 107 | + await localizedStrings() |
| 108 | + |
| 109 | + expect(dm.message).toHaveBeenCalledWith("You seem to be updating localized strings. Make sure that you request translations and include translated strings before you ship your change. See [Localization Guidelines](https://app.asana.com/0/0/1185863667140706/f) for more information.") |
| 110 | + }) |
| 111 | + |
| 112 | + it("messages with UserText.swift-style added code, including macOS Localization guidelines URL when run for macos-browser repo", async () => { |
| 113 | + dm.danger.github.thisPR.repo = "macos-browser" |
| 114 | + dm.addedLines = ` |
| 115 | ++ static let mainMenuAppCheckforUpdates = NSLocalizedString("main-menu.app.check-for-updates", value: "Check for Updates!", comment: "Main Menu DuckDuckGo item") |
| 116 | + ` |
| 117 | + |
| 118 | + await localizedStrings() |
| 119 | + |
| 120 | + expect(dm.message).toHaveBeenCalledWith("You seem to be updating localized strings. Make sure that you request translations and include translated strings before you ship your change. See [Localization Guidelines](https://app.asana.com/0/0/1206727265537758/f) for more information.") |
| 121 | + }) |
| 122 | +}) |
0 commit comments