Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/node_modules
*.tgz
/test-results
/docs
/docs
src/.DS_Store
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@
"author": "Umut Ay Bora",
"license": "MIT",
"dependencies": {
"@civitas-cerebrum/test-coverage": "^0.0.8"
"@civitas-cerebrum/test-coverage": "^0.0.9"
}
}
12 changes: 12 additions & 0 deletions src/repo/ElementRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ export class ElementRepository {
return (page.platform ?? 'web') === 'web';
}

/**
* Returns the platform string for the given page, or `'web'` if not specified.
* @param pageName The name of the page block in the JSON repository.
* @returns The platform string (e.g. `'web'`, `'android'`, `'ios'`).
* @throws Error if the page is not found.
*/
public getPagePlatform(pageName: string): string {
const page = this.findPage(pageName);
if (!page) throw new Error(`ElementRepository: Page '${pageName}' not found.`);
return page.platform ?? 'web';
}

/**
* Updates the default timeout for all subsequent element retrievals.
* @param timeout The new timeout in milliseconds.
Expand Down
36 changes: 36 additions & 0 deletions tests/element-repository.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,42 @@ test.describe('setDefaultTimeout', () => {
});
});

// ===========================================================================
// getPagePlatform
// ===========================================================================

test.describe('getPagePlatform', () => {
test('returns "web" when platform is not specified', () => {
const repo = new ElementRepository(webMockData);
expect(repo.getPagePlatform('TestPage')).toBe('web');
});

test('returns explicit platform when set', () => {
const repo = new ElementRepository(multiPlatformMockData);
expect(repo.getPagePlatform('LoginPage')).toBe('web');
expect(repo.getPagePlatform('LoginPageAndroid')).toBe('android');
expect(repo.getPagePlatform('LoginPageIOS')).toBe('ios');
});

test('returns custom platform string as-is', () => {
const repo = new ElementRepository({
pages: [
{ name: 'DesktopPage', platform: 'macos', elements: [] },
{ name: 'WinPage', platform: 'windows', elements: [] },
],
});
expect(repo.getPagePlatform('DesktopPage')).toBe('macos');
expect(repo.getPagePlatform('WinPage')).toBe('windows');
});

test('throws when page is not found', () => {
const repo = new ElementRepository(webMockData);
expect(() => repo.getPagePlatform('NonExistentPage')).toThrow(
"ElementRepository: Page 'NonExistentPage' not found."
);
});
});

// ===========================================================================
// get — platform branch
// ===========================================================================
Expand Down
Loading