1import { IOSConfig } from '@expo/config-plugins';
2import { fs, vol } from 'memfs';
3import * as path from 'path';
4
5import { setNotificationSounds } from '../withNotificationsIOS';
6import { getDirFromFS } from './withNotificationsAndroid-test';
7
8jest.mock('fs');
9
10const fsReal = jest.requireActual('fs') as typeof fs;
11
12const LIST_OF_GENERATED_FILES = [
13  'assets/notificationSound.wav',
14  'ios/testproject/notificationSound.wav',
15  'ios/testproject.xcodeproj/project.pbxproj',
16  'ios/testproject/AppDelegate.m',
17];
18
19const soundPath = path.resolve(__dirname, './fixtures/cat.wav');
20
21const projectRoot = '/app';
22
23describe('iOS notifications configuration', () => {
24  beforeAll(async () => {
25    const sound = fsReal.readFileSync(soundPath);
26    vol.fromJSON({ 'ios/testproject/AppDelegate.m': '' }, projectRoot);
27    vol.mkdirpSync('/app/assets');
28    vol.mkdirpSync('/app/ios/testproject.xcodeproj/');
29    vol.writeFileSync('/app/assets/notificationSound.wav', sound);
30    vol.writeFileSync(
31      '/app/ios/testproject.xcodeproj/project.pbxproj',
32      fsReal.readFileSync(path.join(__dirname, 'fixtures/project.pbxproj'), 'utf-8')
33    );
34  });
35
36  afterAll(() => {
37    jest.unmock('fs');
38    vol.reset();
39  });
40
41  it('writes all the asset files (sounds and images) as expected', async () => {
42    const project = IOSConfig.XcodeUtils.getPbxproj(projectRoot);
43    // TODO: test pbxproj result via snapshot
44    setNotificationSounds(projectRoot, {
45      sounds: ['/app/assets/notificationSound.wav'],
46      project,
47      projectName: 'testproject',
48    });
49
50    const after = getDirFromFS(vol.toJSON(), projectRoot);
51    expect(Object.keys(after).sort()).toEqual(LIST_OF_GENERATED_FILES.sort());
52  });
53});
54