1import { applyNameSettingsGradle, sanitizeNameForGradle } from '../Name';
2
3const mockSettingsGradle = `rootProject.name = 'My-Co0l �� Pet_Project!'
4
5apply from: '../node_modules/react-native-unimodules/gradle.groovy'
6includeUnimodulesProjects()
7
8apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle");
9applyNativeModulesSettingsGradle(settings)
10
11include ':app'
12`;
13
14const badName = `��/\\:<>"?*|$F0g.`;
15const badNameCleaned = `��$F0g.`;
16
17describe(sanitizeNameForGradle, () => {
18  it('removes invalid characters', () => {
19    expect(sanitizeNameForGradle(badName)).toBe(badNameCleaned);
20  });
21});
22describe(applyNameSettingsGradle, () => {
23  it('replaces name in settings', () => {
24    const modified = applyNameSettingsGradle({ name: badName }, mockSettingsGradle);
25    expect(modified.includes(`rootProject.name = '${badNameCleaned}'\n`)).toBe(true);
26  });
27  it('replaces name in settings with odd linting', () => {
28    // No spaces and double quotes are supported too right now.
29    const modified = applyNameSettingsGradle(
30      { name: badName },
31      `rootProject.name="My-Co0l �� Pet_Project!"`
32    );
33    // Replaces with expected linting
34    expect(modified).toBe(`rootProject.name = '${badNameCleaned}'`);
35  });
36  it('escapes single quotes in name', () => {
37    const modified = applyNameSettingsGradle({ name: "Nora's" }, `rootProject.name="Replace me"`);
38    expect(modified).toBe(`rootProject.name = 'Nora\\'s'`);
39  });
40});
41