-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New TestControl API, rename testControl.ts to testSetup
New API entries in testSetup.ts: * initTestProject to create new, empty project * addCustomField to add a custom field to a project * addLexEntry to add a lexical entry to a project * getProjectJson for help with logging or expect()ing project config * changePassword API moved from testControl.ts to testSetup.ts Also added some examples in example.spec.ts showing how to use the testSetup API. Each example is in a `test.skip` block so that they will not actually run by default.
- Loading branch information
Showing
6 changed files
with
206 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,38 @@ | ||
import type { APIRequestContext } from '@playwright/test'; | ||
import { expect } from '@playwright/test'; | ||
import constants from './testConstants.json'; | ||
import { testControl } from './utils/jsonrpc'; | ||
import type { UserTab } from './utils/fixtures'; | ||
import { test } from './utils/fixtures'; | ||
import { addCustomField, addLexEntry, initTestProject } from './utils/testSetup'; | ||
|
||
test('API call', async ({ request }: { request: APIRequestContext }) => { | ||
const result = await testControl(request, 'check_test_api'); | ||
expect(result).toBeDefined(); | ||
expect(result).toHaveProperty('api_is_working'); | ||
expect(result.api_is_working).toBeTruthy(); | ||
test.skip('Reset project', async ({ request }) => { | ||
await initTestProject(request, | ||
constants.testProjectCode, | ||
constants.testProjectName, | ||
constants.adminUsername, | ||
); | ||
}); | ||
|
||
test('Reset project', async ({ request, adminTab }: { request: APIRequestContext, adminTab: UserTab }) => { | ||
const result = await testControl(request, 'init_test_project', [ | ||
test.skip('Reset project and add test data', async ({ request }) => { | ||
await initTestProject(request, | ||
constants.testProjectCode, | ||
constants.testProjectName, | ||
constants.adminUsername, | ||
]); | ||
await adminTab.goto('/app/projects'); | ||
await expect(adminTab.locator(`[data-ng-repeat="project in visibleProjects"] a:has-text("${constants.testProjectName}")`)).toBeVisible(); | ||
// await adminTab.screenshot({ path: 'post-login.png' }); | ||
constants.managerUsername, | ||
); | ||
const customFieldName = await addCustomField(request, | ||
constants.testProjectCode, | ||
'CustomField', | ||
'entry', | ||
'MultiString', | ||
{inputSystems: ['th']} | ||
); | ||
// Lexical entry from testConstants.json with no changes | ||
await addLexEntry(request, constants.testProjectCode, constants.testEntry1); | ||
// Example of adding data in the custom field | ||
const data = { | ||
...constants.testEntry2, | ||
customFields: { | ||
[customFieldName]: { th: { value: 'contents of custom field' } } | ||
} | ||
}; | ||
// The [customFieldName] syntax is how you can assign a property without knowing it at compile-time | ||
// console.log(data); // Uncomment this to see the data you're adding | ||
await addLexEntry(request, constants.testProjectCode, data); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"buildOnSave": false, | ||
"compileOnSave": false, | ||
"compilerOptions": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { testControl } from './jsonrpc'; | ||
import { APIRequestContext } from '@playwright/test'; | ||
|
||
type CustomFieldType = | ||
'MultiString' | | ||
'ReferenceAtom' | | ||
'ReferenceCollection' | | ||
'OwningAtom' | ||
// TODO: Add more (look at LfMerge custom field code to find out what they can be) | ||
; | ||
|
||
type LfFieldType = | ||
'fields' | | ||
'multitext' | | ||
'multiparagraph' | | ||
'optionlist' | | ||
'multioptionlist' | | ||
'pictures' | ||
; | ||
|
||
export function initTestProject(request: APIRequestContext, | ||
projectCode: string, | ||
projectName: string, | ||
ownerUsername: string, | ||
memberUsernames: string[] = []) | ||
{ | ||
return testControl(request, 'init_test_project', [projectCode, projectName, ownerUsername, memberUsernames]); | ||
} | ||
|
||
export function addCustomField(request: APIRequestContext, | ||
projectCode: string, | ||
fieldName: string, | ||
parentField: 'entry' | 'senses' | 'examples', | ||
fieldType: CustomFieldType = 'MultiString', | ||
extraOptions: any = null) { | ||
return testControl(request, 'add_custom_field', [projectCode, fieldName, parentField, fieldType, extraOptions]); | ||
} | ||
|
||
export function getProjectJson(request: APIRequestContext, | ||
projectCode: string) { | ||
return testControl(request, 'get_project_json', [projectCode]); | ||
} | ||
|
||
export function changePassword(request: APIRequestContext, username: string, password: string) { | ||
return testControl(request, 'change_password', [username, password]); | ||
} | ||
|
||
export function addLexEntry(request: APIRequestContext, projectCode: string, data: any) { | ||
if (data.id == null) data.id = ''; | ||
return testControl(request, 'add_lexical_entry', [projectCode, data]); | ||
} |