Skip to content

Commit

Permalink
fix(test): update snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonrybczak committed Jan 8, 2024
1 parent 053028a commit 9d20955
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,38 @@ exports[`should edit template 1`] = `
- First value
+ Second value
@@ -515,12 +515,8 @@
80,
- 108,
- 97,
- 99,
- 101,
- 104,
+ 114,
111,
- 108,
- 100,
+ 106,
101,
- 114,
+ 99,
+ 116,
78,"
`;
exports[`should edit template 2`] = `
"Snapshot Diff:
- First value
+ Second value
@@ -12,3 +12,3 @@
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
- moduleName:@\\"PlaceholderName\\"
+ moduleName:@\\"ProjectName\\"
initialProperties:nil];"
`;
exports[`should edit template 2`] = `
exports[`should edit template 3`] = `
"Snapshot Diff:
- First value
+ Second value
Expand All @@ -40,22 +64,22 @@ exports[`should edit template 2`] = `
</resources>"
`;
exports[`should edit template 3`] = `
exports[`should edit template 4`] = `
"Snapshot Diff:
- First value
+ Second value
@@ -9,5 +9,5 @@
\\"/android/android-java/com/.DS_Store\\",
@@ -8,5 +8,5 @@
\\"/android/android-java/com\\",
- \\"/android/android-java/com/placeholdername\\",
- \\"/android/android-java/com/placeholdername/MainActivity.java\\",
- \\"/android/android-java/com/placeholdername/PlaceholderName.java\\",
+ \\"/android/android-java/com/projectname\\",
+ \\"/android/android-java/com/projectname/MainActivity.java\\",
+ \\"/android/android-java/com/projectname/ProjectName.java\\",
\\"/android/android-kotlin\\",
@@ -16,14 +16,14 @@
\\"/android/android-kotlin/com/.DS_Store\\",
@@ -14,14 +14,14 @@
\\"/android/android-kotlin/com\\",
- \\"/android/android-kotlin/com/placeholdername\\",
- \\"/android/android-kotlin/com/placeholdername/MainActivity.kt\\",
- \\"/android/android-kotlin/com/placeholdername/PlaceholderName.kt\\",
Expand All @@ -80,3 +104,27 @@ exports[`should edit template 3`] = `
+ \\"/ios/ProjectNameTests/.gitkeep\\",
\\"/node_modules\\","
`;
exports[`should edit template with custom title 1`] = `
"Snapshot Diff:
- First value
+ Second value
@@ -515,12 +515,8 @@
80,
- 108,
- 97,
- 99,
- 101,
- 104,
+ 114,
111,
- 108,
- 100,
+ 106,
101,
- 114,
+ 99,
+ 116,
78,"
`;
52 changes: 52 additions & 0 deletions packages/cli/src/commands/init/__tests__/editTemplate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,28 @@ test('should edit template', async () => {
const transformedTree = walk(testPath).map((e) => e.replace(testPath, ''));
const fixtureTree = walk(FIXTURE_DIR).map((e) => e.replace(FIXTURE_DIR, ''));

const oldJavaFile = fs.readFileSync(
path.resolve(
FIXTURE_DIR,
'android',
'android-java',
'com',
PLACEHOLDER_NAME.toLowerCase(),
'MainActivity.java',
),
);

const newJavaFile = fs.readFileSync(
path.resolve(
testPath,
'android',
'android-java',
'com',
PROJECT_NAME.toLowerCase(),
'MainActivity.java',
),
);

const oldXmlFile = fs.readFileSync(
path.resolve(FIXTURE_DIR, 'android', 'strings.xml'),
'utf8',
Expand All @@ -73,6 +95,10 @@ test('should edit template', async () => {
'utf8',
);

expect(
snapshotDiff(oldJavaFile, newJavaFile, {contextLines: 1}),
).toMatchSnapshot();

expect(snapshotDiff(oldCFile, newCFile, {contextLines: 1})).toMatchSnapshot();
expect(
snapshotDiff(oldXmlFile, newXmlFile, {contextLines: 1}),
Expand All @@ -93,11 +119,37 @@ test('should edit template with custom title', async () => {
projectTitle: PROJECT_TITLE,
});

const oldJavaFile = fs.readFileSync(
path.resolve(
FIXTURE_DIR,
'android',
'android-java',
'com',
PLACEHOLDER_NAME.toLowerCase(),
'MainActivity.java',
),
);

const newJavaFile = fs.readFileSync(
path.resolve(
testPath,
'android',
'android-java',
'com',
PROJECT_NAME.toLowerCase(),
'MainActivity.java',
),
);

const replacedFile = fs.readFileSync(
path.resolve(testPath, 'android', 'strings.xml'),
'utf8',
);

expect(
snapshotDiff(oldJavaFile, newJavaFile, {contextLines: 1}),
).toMatchSnapshot();

expect(replacedFile).toContain(
`<string name="app_name">${PROJECT_TITLE}</string>`,
);
Expand Down

0 comments on commit 9d20955

Please sign in to comment.