Skip to content

Commit

Permalink
[MS] Create default workspaces and files in dev and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Max-7 committed Jan 23, 2025
1 parent 0973246 commit c7cea23
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 10 deletions.
1 change: 1 addition & 0 deletions client/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ PARSEC_APP_BMS_USE_MOCK="false"
PARSEC_APP_BMS_MOCKED_FUNCTIONS=""
PARSEC_APP_BMS_FAIL_FUNCTIONS=""
PARSEC_APP_CREATE_DEFAULT_WORKSPACES="true"
PARSEC_APP_CLEAR_CACHE="true"
1 change: 1 addition & 0 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,4 @@ ionic cap add ios
| `PARSEC_APP_BMS_MOCKED_FUNCTIONS ` | `function1;function2;...` | Comma-separated list of functions from the BMS API to mock | Only for development purposes! |
| `PARSEC_APP_BMS_FAIL_FUNCTIONS ` | `function1;function2;...` | Comma-separated list of functions from the BMS API that should fail if mocked | Only for development purposes! |
| `PARSEC_APP_CREATE_DEFAULT_WORKSPACES` | `boolean` | Create default workspaces when initializing the app | Only for development purposes! |
| `PARSEC_APP_CLEAR_CACHE` | `boolean` | Clear the cache | Only for development purposes! |
5 changes: 5 additions & 0 deletions client/src/services/storageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ export class StorageManager {
async retrieveBmsAccess(): Promise<BmsAccessData | undefined> {
return await this.internalStore.get(StorageManager.STORED_BMS_ACCESS_KEY);
}

async clearAll(): Promise<void> {
window.electronAPI.log('warn', 'Clearing all cache');
await this.internalStore.clear();
}
}

class StorageManagerInstance {
Expand Down
56 changes: 52 additions & 4 deletions client/src/views/layouts/DevLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,22 @@ import { inject, onMounted, ref } from 'vue';
import { IonPage, IonRouterOutlet } from '@ionic/vue';
import { InjectionProvider, InjectionProviderKey } from '@/services/injectionProvider';
import { EventDistributor } from '@/services/eventDistributor';
import { AccessStrategy, createWorkspace, getLoggedInDevices, listAvailableDevices, login } from '@/parsec';
import {
AccessStrategy,
closeFile,
createWorkspace,
getLoggedInDevices,
listAvailableDevices,
login,
openFile,
startWorkspace,
writeFile,
} from '@/parsec';
import { getConnectionHandle, navigateTo, Routes } from '@/router';
import { StorageManagerKey, StorageManager } from '@/services/storageManager';

const injectionProvider: InjectionProvider = inject(InjectionProviderKey)!;
const storageManager: StorageManager = inject(StorageManagerKey)!;
const initialized = ref(false);
const DEV_DEFAULT_HANDLE = 1;

Expand Down Expand Up @@ -64,12 +76,48 @@ onMounted(async () => {
window.electronAPI.log('info', `Logged in as ${device.humanHandle.label}`);
}

if (import.meta.env.PARSEC_APP_CLEAR_CACHE === 'true') {
await storageManager.clearAll();
}
if (import.meta.env.PARSEC_APP_CREATE_DEFAULT_WORKSPACES === 'true') {
await createWorkspace('The Copper Coronet');
await createWorkspace('Trademeet');
await createWorkspace("Watcher's Keep");
await populate();
}

initialized.value = true;
});

async function populate(): Promise<void> {
// Avoid importing files if unnecessary
const mockFiles = (await import('@/parsec/mock_files')).MockFiles;

window.electronAPI.log('debug', 'Creating mock workspaces and files');
for (const workspaceName of ['The Copper Coronet', 'Trademeet', "Watcher's Keep"]) {
const wkResult = await createWorkspace(workspaceName);
if (!wkResult.ok) {
window.electronAPI.log('error', `Could not create dev workspace ${workspaceName}`);
continue;
}
const startWkResult = await startWorkspace(wkResult.value);
if (!startWkResult.ok) {
window.electronAPI.log('error', `Could not start dev workspace ${workspaceName}`);
continue;
}
for (const fileType in mockFiles) {
console.log(workspaceName, fileType);
const fileName = `document_${fileType}.${fileType.toLocaleLowerCase()}`;
const openResult = await openFile(startWkResult.value, `/${fileName}`, { write: true, truncate: true, create: true });

if (!openResult.ok) {
window.electronAPI.log('error', `Could not open file ${fileName}`);
continue;
}
const writeResult = await writeFile(startWkResult.value, openResult.value, 0, mockFiles[fileType as keyof typeof mockFiles]);
if (!writeResult.ok) {
window.electronAPI.log('error', `Failed to write file ${fileName}`);
continue;
}
await closeFile(startWkResult.value, openResult.value);
}
}
}
</script>
Binary file added client/tests/e2e/data/imports/audio.mp3
Binary file not shown.
31 changes: 31 additions & 0 deletions client/tests/e2e/data/imports/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Parsec Cloud (https://parsec.cloud) Copyright (c) BUSL-1.1 2016-present Scille SAS

import argparse
import sys
import pathlib

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"-i", "--input", type=pathlib.Path, required=True, help="File to convert to Uint8Array"
)
parser.add_argument("--name", type=str, required=True, help="Name of the variable")
parser.add_argument("-o", "--output", default=sys.stdout, help="Where to put the result")
args = parser.parse_args()
content = args.input.read_bytes()
array = ",".join([str(c) for c in content])
result = f"""
// Parsec Cloud (https://parsec.cloud) Copyright (c) BUSL-1.1 2016-present Scille SAS
/*
Generated automatically with {sys.argv[0]}
*/
export const {args.name} = new Uint8Array([{array}]);
"""

if args.output is sys.stdout:
print(result)
else:
with open(args.output, "w+") as fd:
fd.write(result)
Binary file added client/tests/e2e/data/imports/document.docx
Binary file not shown.
Binary file added client/tests/e2e/data/imports/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/tests/e2e/data/imports/pdfDocument.pdf
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions client/tests/e2e/data/imports/text.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A simple text file
Binary file added client/tests/e2e/data/imports/video.mp4
Binary file not shown.
13 changes: 12 additions & 1 deletion client/tests/e2e/helpers/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,18 @@ export const msTest = base.extend<{
await expect(workspaces.locator('.folder-container').locator('.no-files')).toBeVisible();
// Also create a folder here when available
const dropZone = workspaces.locator('.folder-container').locator('.drop-zone').nth(0);
await dragAndDropFile(workspaces, dropZone, [path.join(testInfo.config.rootDir, 'data', 'imports', 'hell_yeah.png')]);
await dragAndDropFile(workspaces, dropZone, [
path.join(testInfo.config.rootDir, 'data', 'imports', 'image.png'),
path.join(testInfo.config.rootDir, 'data', 'imports', 'document.docx'),
path.join(testInfo.config.rootDir, 'data', 'imports', 'pdfDocument.pdf'),
path.join(testInfo.config.rootDir, 'data', 'imports', 'video.mp4'),
path.join(testInfo.config.rootDir, 'data', 'imports', 'audio.mp3'),
path.join(testInfo.config.rootDir, 'data', 'imports', 'spreadsheet.xlsx'),
path.join(testInfo.config.rootDir, 'data', 'imports', 'text.txt'),
path.join(testInfo.config.rootDir, 'data', 'imports', 'code.py'),
]);
// Hide the import menu
await workspaces.locator('.upload-menu').locator('.menu-header-icons').locator('ion-icon').nth(1).click();
use(workspaces);
},

Expand Down
9 changes: 4 additions & 5 deletions client/tests/e2e/specs/user_greet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ msTest('Greet user process', async ({ usersPage, secondTab }) => {
await expect(greetModal).toHaveWizardStepper(['Host code', 'Guest code', 'Contact details'], 0);
await expect(greetTitle).toHaveText('Share your code');
await expect(greetSubtitle).toHaveText('Give the code below to the guest.');
const greetCode = await greetContent.locator('.host-code').locator('.code').textContent() ?? '';
const greetCode = (await greetContent.locator('.host-code').locator('.code').textContent()) ?? '';
expect(greetCode).toMatch(/^[A-Z0-9]{4}$/);

// Check the enter code page from the joiner and select the code
Expand All @@ -62,7 +62,7 @@ msTest('Greet user process', async ({ usersPage, secondTab }) => {
// Check the provide code page from the joiner and retrieve the code
await expect(joinTitle).toHaveText('Share your code');
await expect(joinModal).toHaveWizardStepper(['Host code', 'Guest code', 'Contact details', 'Authentication'], 1);
const joinCode = await joinContent.locator('.guest-code').locator('.code').textContent() ?? '';
const joinCode = (await joinContent.locator('.guest-code').locator('.code').textContent()) ?? '';
expect(joinCode).toMatch(/^[A-Z0-9]{4}$/);

// Check the enter code page from the greeter and select the code
Expand All @@ -82,9 +82,7 @@ msTest('Greet user process', async ({ usersPage, secondTab }) => {
await expect(joinModal).toHaveWizardStepper(['Host code', 'Guest code', 'Contact details', 'Authentication'], 2);
await expect(joinNextButton).toHaveDisabledAttribute();
await fillIonInput(joinModal.locator('#get-user-info').locator('ion-input').nth(0), 'Gordon Freeman');
await expect(joinModal.locator('#get-user-info').locator('ion-input').nth(1).locator('input')).toHaveValue(
'[email protected]',
);
await expect(joinModal.locator('#get-user-info').locator('ion-input').nth(1).locator('input')).toHaveValue('[email protected]');
await joinNextButton.click();
await expect(joinNextButton).toBeHidden();
await expect(joinModal.locator('.spinner-container')).toBeVisible();
Expand Down Expand Up @@ -166,6 +164,7 @@ msTest('Greet user process', async ({ usersPage, secondTab }) => {
// const choices = userGreetModal.locator('.modal-content').locator('.code:visible');
// await choices.nth(0).click();

// eslint-disable-next-line max-len
// await expect(userGreetModal.page()).toShowToast('You did not select the correct code. Please restart the onboarding process.', 'Error');
// await expect(title).toHaveText('Onboard a new user');
// });
Expand Down

0 comments on commit c7cea23

Please sign in to comment.