๐Ÿ“ฆ ionic-team / trapeze

๐Ÿ“„ ios.strings.test.ts ยท 100 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100import { copy } from '@ionic/utils-fs';
import { StringsFile } from '@trapezedev/project';
import { join } from 'path';
import { temporaryDirectory } from 'tempy';

import { Context, loadContext } from '../../src/ctx';
import { IosStringsOperation, Operation } from '../../src/definitions';
import Op from '../../src/operations/ios/strings';

describe('op: ios.strings', () => {
  let dir: string;
  let ctx: Context;

  beforeEach(async () => {
    dir = temporaryDirectory();

    await copy('../common/test/fixtures/ios-and-android', dir);

    ctx = await loadContext(dir);
    ctx.args.quiet = true;
  });

  it('should set ios.strings', async () => {
    const op: IosStringsOperation = {
      value: [
        {
          file: 'App/Localizable.strings',
          set: {
            'Insert Element': 'Insert Element 2'
          },
        },
      ],
    };

    await Op(ctx, op as Operation);

    const file = ctx.project.vfs.get<StringsFile>(
      join(ctx.project.config.ios?.path ?? '', 'App', 'Localizable.strings'),
    );
    expect(file?.getData()?.generate()).toEqual(`
/* Insert Element menu item */

"Insert Element" = "Insert Element 2";

/* Error string used for unknown error types. */

"ErrorString_1" = "An unknown error occurred.";
`.trim());
  });

  it('should set ios.strings from json', async () => {
    const op: IosStringsOperation = {
      value: [
        {
          file: 'App/Localizable.strings',
          setFromJson: '../common/test/fixtures/strings.json'
        },
      ],
    };

    await Op(ctx, op as Operation);

    const file = ctx.project.vfs.get<StringsFile>(
      join(ctx.project.config.ios?.path ?? '', 'App', 'Localizable.strings'),
    );
    expect(file?.getData()?.generate()).toEqual(`
/* Insert Element menu item */

"Insert Element" = "New3";

/* Error string used for unknown error types. */

"ErrorString_1" = "New4";
`.trim());
  });

  it('should create new strings file if one does not exist', async () => {
    const op: IosStringsOperation = {
      value: [
        {
          file: 'App/path/to/New.strings',
          setFromJson: '../common/test/fixtures/strings.json'
        },
      ],
    };

    await Op(ctx, op as Operation);

    const file = ctx.project.vfs.get<StringsFile>(
      join(ctx.project.config.ios?.path ?? '', 'App', 'path', 'to', 'New.strings'),
    );
    const generated = file?.getData()?.generate();
    expect(generated).toEqual(`
"Insert Element" = "New3";

"ErrorString_1" = "New4";
`.trim());
  });
});