Skip to content

Commit

Permalink
Adapt unit tests and functional tests to the library translation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
monsieurswag committed May 14, 2024
1 parent 5559c14 commit 4c9f4e3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
12 changes: 6 additions & 6 deletions backend/app_tests/api/test_api_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ def test_import_frameworks(self, test):
).json()["content"]
lib_detail_response = json.loads(lib_detail_response)["framework"]

# Asserts that the library is not already imported
# Asserts that the library is not already loaded
assert (
Framework.objects.all().count() == 0
), "libraries are already imported in the database"
), "libraries are already loaded in the database"
EndpointTestsQueries.Auth.get_object(
test.client,
"Frameworks",
Expand All @@ -88,7 +88,7 @@ def test_import_frameworks(self, test):
else 0
), "Frameworks are not correctly imported in the database"

# Uses the API endpoint to assert that the library was properly imported
# Uses the API endpoint to assert that the library was properly loaded
EndpointTestsQueries.Auth.get_object(
test.client,
"Frameworks",
Expand Down Expand Up @@ -132,10 +132,10 @@ def test_import_risk_matrix(self, test):
).json()["content"]
lib_detail_response = json.loads(lib_detail_response)["risk_matrix"][0]

# Asserts that the library is not already imported
# Asserts that the library is not already loaded
assert (
RiskMatrix.objects.all().count() == 0
), "libraries are already imported in the database"
), "libraries are already loaded in the database"
EndpointTestsQueries.Auth.get_object(
test.client, "Risk matrices", user_group=test.user_group
)
Expand All @@ -152,7 +152,7 @@ def test_import_risk_matrix(self, test):
else 0
), "Risk matrices are not correctly imported in the database"

# Uses the API endpoint to assert that the library was properly imported
# Uses the API endpoint to assert that the library was properly loaded
EndpointTestsQueries.Auth.get_object(
test.client,
"Risk matrices",
Expand Down
20 changes: 10 additions & 10 deletions frontend/tests/functional/detailed/libraries.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '../../utils/test-utils.js';

test.describe.configure({ mode: 'serial' });
test('every libraries can be imported', async ({ logedPage, librariesPage, page }) => {
test('every libraries can be loaded', async ({ logedPage, librariesPage, page }) => {
test.slow();
await librariesPage.goto();
await librariesPage.hasUrl();
Expand Down Expand Up @@ -38,23 +38,23 @@ test('every libraries can be deleted', async ({ logedPage, librariesPage, page }
await librariesPage.hasUrl();

await expect(
librariesPage.tab('Imported libraries'),
'There is no imported libraries to delete'
librariesPage.tab('Loaded libraries'),
'There is no loaded libraries to delete'
).toBeVisible();
if (
(await librariesPage.tab('Imported libraries').isVisible()) &&
(await librariesPage.tab('Imported libraries').getAttribute('aria-selected')) === 'false'
(await librariesPage.tab('Loaded libraries').isVisible()) &&
(await librariesPage.tab('Loaded libraries').getAttribute('aria-selected')) === 'false'
) {
await librariesPage.tab('Imported libraries').click();
expect(librariesPage.tab('Imported libraries').getAttribute('aria-selected')).toBeTruthy();
await librariesPage.tab('Loaded libraries').click();
expect(librariesPage.tab('Loaded libraries').getAttribute('aria-selected')).toBeTruthy();
}

let previousRemainingLibrary = '';
let nextRemainingLibrary = '';
let count = 0;
do {
await page.reload(); // this is a workaround to try to fix the issue with delete button not being visible with dependencies in CI
if (await librariesPage.tab('Imported libraries').isVisible()) {
if (await librariesPage.tab('Loaded libraries').isVisible()) {
previousRemainingLibrary = nextRemainingLibrary;
nextRemainingLibrary = await page.locator('tbody tr td:nth-child(1)').nth(count)?.innerText();
expect(
Expand All @@ -75,7 +75,7 @@ test('every libraries can be deleted', async ({ logedPage, librariesPage, page }
timeout: 15000
}
);
if (await page.getByText(' You currently have no imported libraries.').isHidden()) {
if (await page.getByText(' You currently have no loaded libraries.').isHidden()) {
await expect(librariesPage.getRow(nextRemainingLibrary)).not.toBeVisible();
} else {
break;
Expand All @@ -87,6 +87,6 @@ test('every libraries can be deleted', async ({ logedPage, librariesPage, page }
}
} while (
nextRemainingLibrary ||
(await page.getByText(' You currently have no imported libraries.').isHidden())
(await page.getByText(' You currently have no loaded libraries.').isHidden())
);
});
16 changes: 8 additions & 8 deletions frontend/tests/utils/page-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export class PageContent extends BasePage {

async importLibrary(ref: string, urn?: string, language = 'English') {
if (
(await this.tab('Imported libraries').isVisible()) &&
(await this.tab('Imported libraries').getAttribute('aria-selected')) === 'true'
(await this.tab('Loaded libraries').isVisible()) &&
(await this.tab('Loaded libraries').getAttribute('aria-selected')) === 'true'
) {
if (await this.getRow(ref).isHidden()) {
await this.tab('Libraries store').click();
Expand All @@ -77,19 +77,19 @@ export class PageContent extends BasePage {
return;
}
}
// If the library is not visible, it might have already been imported
// If the library is not visible, it might have already been loaded
if (await this.getRow(ref).isHidden()) {
await this.tab('Imported libraries').click();
expect(this.tab('Imported libraries').getAttribute('aria-selected')).toBeTruthy();
await this.tab('Loaded libraries').click();
expect(this.tab('Loaded libraries').getAttribute('aria-selected')).toBeTruthy();
expect(this.getRow(ref)).toBeVisible();
return;
}
await this.importItemButton(ref, language === 'any' ? undefined : language).click();
await this.isToastVisible(`The library object has been successfully imported.+`, undefined, {
await this.isToastVisible(`The library has been successfully loaded.+`, undefined, {
timeout: 15000
});
await this.tab('Imported libraries').click();
expect(this.tab('Imported libraries').getAttribute('aria-selected')).toBeTruthy();
await this.tab('Loaded libraries').click();
expect(this.tab('Loaded libraries').getAttribute('aria-selected')).toBeTruthy();
expect(this.getRow(ref)).toBeVisible();
}

Expand Down

0 comments on commit 4c9f4e3

Please sign in to comment.