Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test/document tests single test #576

Draft
wants to merge 31 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
640ac69
Commit to merge latest dev
Dec 4, 2023
71e41a7
Merge branch 'dev' into Documents_Tests
Dec 4, 2023
0a6bc4a
Commit to merge latest dev
Dec 5, 2023
ad09068
Merge branch 'dev' into Documents_Tests
Dec 5, 2023
f36995e
Documents Tests Added_5Dec
Dec 5, 2023
af3463c
Fix the directory path
Dec 5, 2023
4b02d3e
Merge branch 'dev' into Documents_Tests
Dec 6, 2023
8bcc753
Merge branch 'dev' into Documents_Tests
Dec 8, 2023
c8bd4d4
Added Aws secrets to the test.yml file
Dec 8, 2023
49c56f9
fix env variables
ForeverYoung1208 Dec 8, 2023
0d1f60d
remove some tests
ForeverYoung1208 Dec 8, 2023
cab8c79
remove some tests
ForeverYoung1208 Dec 8, 2023
7063e5c
remove some tests
ForeverYoung1208 Dec 8, 2023
b82bdb6
try to fix
ForeverYoung1208 Dec 8, 2023
3ffdda8
try to fix
ForeverYoung1208 Dec 8, 2023
ee528e1
try to fix
ForeverYoung1208 Dec 8, 2023
f63c167
test
ForeverYoung1208 Dec 11, 2023
3781014
test
ForeverYoung1208 Dec 11, 2023
6c50a28
Merge branch 'dev' into test/Document_Tests-single-test
ForeverYoung1208 Dec 14, 2023
5912f88
add logs
ForeverYoung1208 Dec 14, 2023
0044614
reduce timeout to 10sec
ForeverYoung1208 Dec 14, 2023
1c30e9a
no test-buildable to test problem test
ForeverYoung1208 Dec 14, 2023
6eea75e
test
ForeverYoung1208 Dec 14, 2023
dc592b7
test2
ForeverYoung1208 Dec 14, 2023
b6f71d3
test
ForeverYoung1208 Dec 14, 2023
a0fd2eb
test
ForeverYoung1208 Dec 14, 2023
afab72a
test 5
ForeverYoung1208 Dec 14, 2023
3274a2e
test 6
ForeverYoung1208 Dec 14, 2023
f365af8
test
ForeverYoung1208 Dec 14, 2023
c1164b8
test
ForeverYoung1208 Dec 14, 2023
fade4ef
test
ForeverYoung1208 Dec 14, 2023
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
21 changes: 12 additions & 9 deletions .github/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ services:
api:
image: etenlab/crowd-rocks:test
environment:
CR_DB_URL: postgres
CR_DB_PORT: 5432
CR_DB_USER: postgres
CR_DB_PASSWORD: asdfasdf
CR_DB: crowdrocks
ADMIN_PASSWORD: asdfasdf
MODE: DEV
OPENAI_API_KEY: asdf
DEEPL_KEY: asdf
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
- AWS_REGION=${AWS_REGION}
- CR_DB_URL=postgres
- CR_DB_PORT=5432
- CR_DB_USER=postgres
- CR_DB_PASSWORD=asdfasdf
- CR_DB=crowdrocks
- ADMIN_PASSWORD=asdfasdf
- MODE=DEV
- OPENAI_API_KEY=asdf
- DEEPL_KEY=asdf
ports:
- 3000:3000
depends_on:
Expand Down
60 changes: 38 additions & 22 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_GITHUB_S3_PUSHER_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_GITHUB_S3_PUSHER_SECRET_ACCESS_KEY }}
aws-region: us-east-2

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
Expand All @@ -35,30 +42,30 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
build-args: BUILD_MODE=test

test-api-e2e:
runs-on: ubuntu-latest
needs: test-buildable
steps:
- name: Checkout
uses: actions/checkout@v1
# test-api-e2e:
# runs-on: ubuntu-latest
# needs: test-buildable
# steps:
# - name: Checkout
# uses: actions/checkout@v1

- uses: isbang/[email protected]
with:
compose-file: "./.github/docker/docker-compose.yml"
down-flags: "--volumes"
services: |
postgres
# - uses: isbang/[email protected]
# with:
# compose-file: "./.github/docker/docker-compose.yml"
# down-flags: "--volumes"
# services: |
# postgres

- uses: actions/setup-node@v3
with:
node-version: 16
# - uses: actions/setup-node@v3
# with:
# node-version: 16

- run: cd utils && npm ci
# - run: cd utils && npm ci

- run: cd api && cp .env.example .env && yarn install
# - run: cd api && cp .env.example .env && yarn install

- name: Test
run: cd api && yarn test:e2e
# - name: Test
# run: cd api && yarn test:e2e

test-frontend-playwright:
runs-on: ubuntu-latest
Expand All @@ -75,9 +82,11 @@ jobs:
with:
compose-file: "./.github/docker/docker-compose.yml"
down-flags: "--volumes"
services: |
postgres
api
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_GITHUB_S3_PUSHER_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_GITHUB_S3_PUSHER_SECRET_ACCESS_KEY }}
AWS_REGION: us-east-2


- run: cd utils && npm ci

Expand All @@ -86,9 +95,16 @@ jobs:
- name: Install Playwright Browsers
run: cd frontend && npx playwright install --with-deps

- name: Show logs before Playwright tests
run: docker-compose -f "./.github/docker/docker-compose.yml" logs

- name: Run Playwright tests
run: cd frontend && npx playwright test

- name: Logs after playwright tests
if: always()
run: docker-compose -f "./.github/docker/docker-compose.yml" logs

- uses: actions/upload-artifact@v3
if: always()
with:
Expand Down
1 change: 1 addition & 0 deletions api/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export enum ErrorType {
FileRecordNotFound = 'FileRecordNotFound',
FileSaveFailed = 'FileSaveFailed',
FileUpdateFailed = 'FileUpdateFailed',
FileUploadFailed = 'FileUploadFailed',
FileDeleteFailed = 'FileDeleteFailed',
FileWithFilenameAlreadyExists = 'FileWithFilenameAlreadyExists',
FolderIdNotDefined = 'FolderIdNotDefined',
Expand Down
7 changes: 6 additions & 1 deletion api/src/components/file/file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,12 @@ export class FileService {
});
} catch (err) {
Logger.log(`File upload failed. #file_name[${fileName}]`, err);
return { error: ErrorType.FileUpdateFailed, file: null };
return {
error: `${JSON.stringify(err)}, [AWS_REGION env]: ${
process.env.AWS_REGION
}` as ErrorType.FileUploadFailed,
file: null,
};
}
}

Expand Down
4 changes: 4 additions & 0 deletions api/src/core/database-version-control.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export class DatabaseVersionControlService {

if (!exists) {
console.log('Creating database schema');
console.log(
`env AWS_REGION ${process.env.AWS_REGION} AWS_ACCESS_KEY_ID ${process.env.AWS_ACCESS_KEY_ID}`,
'FileService#constructor',
);
await this.loadVersion1();
}

Expand Down
7 changes: 7 additions & 0 deletions api/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { NestFactory } from '@nestjs/core';
import { graphqlUploadExpress } from 'graphql-upload-ts';
import { AppModule } from './app.module';
import * as dotenv from 'dotenv';
dotenv.config();

async function bootstrap() {
console.log(
`==============> env AWS_REGION ${process.env.AWS_REGION} AWS_ACCESS_KEY_ID ${process.env.AWS_ACCESS_KEY_ID}`,
'FileService#constructor',
);
const app = await NestFactory.create(AppModule);
app.enableCors({
origin: '*',
allowedHeaders: '*',
});

app.use(
'/graphql',
graphqlUploadExpress({
Expand Down
2 changes: 1 addition & 1 deletion frontend/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default defineConfig({
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
timeout: 300 * 1000,
timeout: 10 * 1000,
},

// {
Expand Down
17 changes: 17 additions & 0 deletions frontend/tests/constants/DocumentConstants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import path from 'path';
import { fileURLToPath } from 'url';

// Define the base directory for test data
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const baseTestDataDirectory = path.join(__dirname, '../testData/');

// Define the constants
const constants = {
filePath: (documentName: string) =>
path.join(baseTestDataDirectory, documentName),
invalidFile: path.join(baseTestDataDirectory, 'gifSample.gif'),
fileContent: 'Hello, this is the content of the file.',
};

export default constants;
2 changes: 1 addition & 1 deletion frontend/tests/pages/Community/CommonPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CommonPage extends BasePage {
return await this.page.getByRole('heading', { name: name }).isVisible();
}
async getValidationMessage() {
return await this.page.locator(`.toast-message`).textContent();
return await this.page.locator(`.toast-message`).last().textContent();
}
}
export default CommonPage;
99 changes: 99 additions & 0 deletions frontend/tests/pages/Community/DocumentsPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import BasePage from '../BasePage';

const addNewDocumentButton = `(//span[text()='Select your language']//..//..//div)[4]//button`;
const selectedLanguage = (languageName: string) =>
`//h4[text()='${languageName}']`;
const languageName = (language: string) =>
`//h5[text()='${language}']//..//input`;
const documents = (documentName: string) => `//p[text()='${documentName}']`;
const meatBallsMenuButton = (documentName: string) =>
`//p[text()='${documentName}']//..//..//button`;

class DocumentsPage extends BasePage {
async isPageTitleVisible() {
return await this.page.locator(`//h2[text()='Documents']`).isVisible();
}
async isDocumentDetailsPageVisible() {
return await this.page
.getByRole('heading', { name: 'Details' })
.isVisible();
}
async clickOnSelectYourLanguageDropdown() {
await this.page
.getByRole('heading', { name: 'Select your language' })
.click();
}
async clickOnSelectDocumentLanguageDropdown() {
await this.page
.getByRole('heading', { name: 'Select document language' })
.click();
}
async isSelectYourLanguagePopupVisible() {
return await this.page
.locator(`//h2[text()='Select your language']`)
.first()
.isVisible();
}
async isAddNewDocumentPopupVisible() {
return await this.page
.getByRole('heading', { name: 'Add new document' })
.isVisible();
}
async selectLanguage(language: string) {
await this.page
.getByRole('textbox', { name: 'Search by language...' })
.fill(language);
await this.page.locator(languageName(language)).first().click();
await this.page.getByRole('button', { name: 'Confirm' }).click();
}
async isLanguageSelected(languageName: string) {
return await this.page
.locator(selectedLanguage(languageName))
.last()
.isVisible();
}
async clickOnAddNewDocumentPopupCrossButton() {
await this.page.getByRole('button').first().click();
}
async clickOnCrossButton() {
await this.page.click(
`(//span[text()='Select your language']//..//..//div)[2]//button`,
);
}
async clickOnAddNewDocumentsButton() {
await this.page.click(addNewDocumentButton);
}
async clickOnCancelButton() {
await this.page.getByRole('button', { name: 'Cancel' }).click();
}
async uploadTextFile(filePath: string) {
await this.page.setInputFiles('input[type="file"]', filePath);
}
async clickOnUploadButton() {
await this.page.getByRole('button', { name: 'Upload' }).click();
}
async searchDocuments(documentName: string) {
await this.page
.getByPlaceholder(`Search by document...`)
.fill(documentName);
await this.page.waitForTimeout(1000);
}
async clickOnDocument(documentName: string) {
await this.page.locator(documents(documentName)).click();
}
async isCreatedDocumentVisible(documentName: string) {
return await this.page.locator(documents(documentName)).isVisible();
}
async clickOnMeatBallsMenuButton(documentName: string) {
await this.page.locator(meatBallsMenuButton(documentName)).click();
}
async clickOnGoToDocumentsButton() {
await this.page.getByRole('button', { name: 'Go to Documents' }).click();
}
async downloadDocument(documentName: string) {
await this.clickOnMeatBallsMenuButton(documentName);
await this.page.getByRole('button', { name: 'Download' }).click();
}
}

export default DocumentsPage;
11 changes: 10 additions & 1 deletion frontend/tests/pages/HomePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import BasePage from './BasePage';
const homePageTitle =
'//div[@class="section"]/ion-item-group//ion-label[text() = "Media"]';
const homePageText = `//ion-label[text()]`;
const headerText = '#crowd-rock-app #app-name-text';
const expandIcon = '#app-menu-button';
const languageText = '//ion-label[text() = "Language"]';

Expand All @@ -11,7 +12,9 @@ class HomePage extends BasePage {
await this.page.locator(homePageTitle).waitFor();
return await this.page.locator(homePageTitle).isVisible();
}

async clickOnCrowdRocks() {
await this.page.locator(headerText).first().click();
}
async getHomePageTitle() {
return await this.page.locator(homePageText).first().textContent();
}
Expand All @@ -33,6 +36,12 @@ class HomePage extends BasePage {
.filter({ hasText: 'Forums' })
.click();
}
async clickOnTheDocumentsSection() {
await this.page
.locator('ion-card-header')
.filter({ hasText: 'Documents' })
.click();
}
}

export default HomePage;
5 changes: 1 addition & 4 deletions frontend/tests/pages/MenuPage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import BasePage from './BasePage';

const headerText = '#crowd-rock-app #app-name-text';

const leftMenuFeatureButton = (featureName: string) =>
`//h4[text()="${featureName}"]`;

Expand All @@ -18,10 +19,6 @@ class MenuPage extends BasePage {
await this.page.locator(leftMenuFeatureButton(featureName)).first().click();
await this.page.waitForTimeout(1000);
}

async clickOnCrowdRocks() {
await this.page.locator(headerText).first().click();
}
}

export default MenuPage;
Loading
Loading