Skip to content

Commit

Permalink
Testing topics + adding code to add new configuration test-int
Browse files Browse the repository at this point in the history
  • Loading branch information
reganha committed Aug 19, 2020
1 parent 5ab65ac commit 488d13d
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ scripts

backend/src/main/resources/static/images/questions/
data/
frontend/cypress.env.json
14 changes: 7 additions & 7 deletions backend/src/main/resources/application-prod.properties.example
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
## Datasource
spring.datasource.url=jdbc:postgresql://localhost:<DATABASE PORT>/<DATABASE NAME>
spring.datasource.username= <DATABASE USERNAME>
spring.datasource.password= <DATABASE PASSWORD>
spring.datasource.url=jdbc:postgresql://localhost:5432/tutortestdb
spring.datasource.username=
spring.datasource.password=

## Jpa
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect

## Resources
figures.dir=<DIRECTORY_WITH_FIGURES>
export.dir=<DIRECTORY_TO_EXPORT>
load.dir=<DIRECTORY_FOR_LOAD>
figures.dir=./folder
export.dir=./folder
load.dir=./folder

## Fenix oauth
oauth.consumer.key=<FENIX CLIENT KEY>
oauth.consumer.secret=<FENIX SECRET>
callback.url=<URL FENIX REDIRECTS TO>
base.url=https://fenix.tecnico.ulisboa.pt
base.url=https://fenix.tecnico.ulisboa.pt
18 changes: 18 additions & 0 deletions backend/src/main/resources/application-test-int.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Datasource
spring.datasource.url=jdbc:postgresql://${PSQL_INT_TEST_DB_HOST}:${PSQL_INT_TEST_DB_PORT}/${PSQL_INT_TEST_DB_NAME}
spring.datasource.username= ${PSQL_INT_TEST_DB_USERNAME}
spring.datasource.password = ${PSQL_INT_TEST_DB_PASSWORD}

## Jpa
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect

## Resources
figures.dir=./folder
export.dir=./folder
load.dir=./folder

## Fenix oauth
oauth.consumer.key=<FENIX CLIENT KEY>
oauth.consumer.secret=<FENIX SECRET>
callback.url=http://localhost:8081/login
base.url=https://fenix.tecnico.ulisboa.pt
7 changes: 7 additions & 0 deletions frontend/cypress.env.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"psql_db_name": "<DB NAME>",
"psql_db_username": "<USERNAME>",
"psql_db_password": "<PASSWORD>",
"psql_db_host": "<HOST>",
"psql_db_port": "5432"
}
2 changes: 1 addition & 1 deletion frontend/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ VUE_APP_ROOT_API=http://localhost:8080
VUE_APP_FENIX_CLIENT_ID=<FENIX CLIENT KEY>
VUE_APP_FENIX_CLIENT_SECRET=<FENIX CLIENT SECRET>
VUE_APP_FENIX_REDIRECT_URI=http://localhost:8081/login
VUE_APP_FENIX_URL=https://fenix.tecnico.ulisboa.pt/oauth/userdialog?client_id=${VUE_APP_FENIX_CLIENT_ID}&redirect_uri=${VUE_APP_FENIX_REDIRECT_URI}
VUE_APP_FENIX_URL=https://fenix.tecnico.ulisboa.pt/oauth/userdialog?client_id=${VUE_APP_FENIX_CLIENT_ID}&redirect_uri=${VUE_APP_FENIX_REDIRECT_URI}
4 changes: 2 additions & 2 deletions frontend/src/components/TopBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

<v-menu offset-y v-if="isTeacher && currentCourse" open-on-hover>
<template v-slot:activator="{ on }">
<v-btn v-on="on" text dark>
<v-btn v-on="on" text dark data-cy="managementMenuButton">
Management
<v-icon>fas fa-file-alt</v-icon>
</v-btn>
Expand All @@ -61,7 +61,7 @@
<v-list-item-title>Questions</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-list-item to="/management/topics">
<v-list-item to="/management/topics" data-cy="manageTopicsMenuButton">
<v-list-item-action>
<v-icon>category</v-icon>
</v-list-item-action>
Expand Down
11 changes: 6 additions & 5 deletions frontend/src/views/teacher/TopicsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
:mobile-breakpoint="0"
:items-per-page="50"
:footer-props="{ itemsPerPageOptions: [15, 30, 50, 100] }"
data-cy="topicsGrid"
>
<template v-slot:top>
<v-card-title>
Expand All @@ -19,14 +20,14 @@
hide-details
/>
<v-spacer />
<v-btn color="primary" dark @click="newTopic">New Topic</v-btn>
<v-btn color="primary" dark @click="newTopic" data-cy="topicsNewTopicBtn">New Topic</v-btn>
</v-card-title>
</template>
<template v-slot:item.action="{ item }">
<v-tooltip bottom>
<template v-slot:activator="{ on }">
<v-icon class="mr-2" v-on="on" @click="editTopic(item)"
>edit</v-icon
data-cy="topicsGridEditButton">edit</v-icon
>
</template>
<span>Edit Topic</span>
Expand All @@ -38,7 +39,7 @@
v-on="on"
@click="deleteTopic(item)"
color="red"
>delete</v-icon
data-cy="topicsGridDeleteButton">delete</v-icon
>
</template>
<span>Delete Topic</span>
Expand All @@ -55,13 +56,13 @@
</footer>

<v-dialog v-model="topicDialog" max-width="75%">
<v-card>
<v-card data-cy="topicsCreateOrEditDialog">
<v-card-title>
<span class="headline">{{ formTitle() }}</span>
</v-card-title>

<v-card-text v-if="editedTopic">
<v-text-field v-model="editedTopic.name" label="Topic" />
<v-text-field v-model="editedTopic.name" label="Topic" data-cy="topicsFormTopicNameInput"/>
</v-card-text>

<v-card-actions>
Expand Down
107 changes: 107 additions & 0 deletions frontend/tests/e2e/specs/teacher/manageTopics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
describe('Manage Topics Walk-through', () => {

function createTopicWithName(topicName){
cy.get('[data-cy="topicsNewTopicBtn"]', { force: true }).click();

cy.get('[data-cy="topicsCreateOrEditDialog"]')
.should('be.visible');

cy.get('[data-cy="topicsFormTopicNameInput"]')
.should('be.empty')
.type(topicName);

cy.route('POST', '/courses/*/topics/').as('postTopic');

cy.get('button')
.contains('Save')
.click();

cy.wait('@postTopic')
.its('status')
.should('eq', 200);
}

beforeEach(() => {
cy.cleanTestTopics();
cy.demoTeacherLogin();
cy.server();
cy.route('GET', '/courses/*/topics').as('getTopics');
cy.get('[data-cy="managementMenuButton"]').click();
cy.get('[data-cy="manageTopicsMenuButton"]').click();

cy.wait('@getTopics')
.its('status')
.should('eq', 200);
});

afterEach(() => {
cy.logout();
});

it('Can create a new topic', function() {
let topicName = `CY - Test topic ${new Date().toJSON()}`

createTopicWithName(topicName);

cy.get('[data-cy="topicsGrid"]')
.first()
.should('contain', topicName);
});

it('Can edit created new topics', function() {
let topicName = `CY - Test topic ${new Date().toJSON()}`

createTopicWithName(topicName);

cy.get('[data-cy="topicsGrid"] table > tbody > tr:first')
.should('contain', topicName)
.within(() => {
cy.get('[data-cy="topicsGridEditButton"]').click();
})

cy.get('[data-cy="topicsCreateOrEditDialog"]')
.should('be.visible');

cy.get('[data-cy="topicsFormTopicNameInput"]')
.should('contain.value', topicName)
.clear()
.type('CY - EDITED');

cy.route('PUT', '/topics/*').as('putTopic');

cy.get('button')
.contains('Save')
.click();

cy.wait('@putTopic')
.its('status')
.should('eq', 200);

cy.get('[data-cy="topicsGrid"]')
.first()
.should('contain', 'CY - EDITED');
});

it('Can delete created topics', function() {
let topicName = `CY - Test topic ${new Date().toJSON()}`

createTopicWithName(topicName);

cy.route('DELETE', '/topics/*').as('deleteTopic');

cy.get('[data-cy="topicsGrid"]').contains(topicName).should('exist');

cy.get('[data-cy="topicsGrid"] table > tbody > tr:first')
.should('contain', topicName)
.within(() => {
cy.get('[data-cy="topicsGridDeleteButton"]').click();
})

cy.wait('@deleteTopic')
.its('status')
.should('eq', 200);

cy.get('[data-cy="topicsGrid"]').contains(topicName).should('not.exist');
});
});

27 changes: 27 additions & 0 deletions frontend/tests/e2e/support/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function dbPasswordCommand(password){
if (Cypress.platform === 'win32'){
return `set PGPASSWORD=${password}&& `
}
else{
return `PGPASSWORD=${password} `
}
}

function dbCommand(command){
return cy.exec(
dbPasswordCommand(Cypress.env('psql_db_password')) +
`psql -d ${Cypress.env('psql_db_name')} ` +
`-U ${Cypress.env('psql_db_username')} ` +
`-h ${Cypress.env('psql_db_host')} ` +
`-p ${Cypress.env('psql_db_port')} ` +
`-c "${command.replace(/\r?\n/g, " ")}"`
);
}

Cypress.Commands.add('cleanTestTopics', () => {
dbCommand(`
DELETE FROM topics
WHERE name like 'CY%'
`)
});

1 change: 1 addition & 0 deletions frontend/tests/e2e/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
// Import commands.js using ES2015 syntax:
import './login';
import './commands';
import './database';

0 comments on commit 488d13d

Please sign in to comment.