Skip to content

Commit

Permalink
Add group settings test
Browse files Browse the repository at this point in the history
  • Loading branch information
MattyMay committed Oct 1, 2024
1 parent 7ff6650 commit c6b2d18
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 11 deletions.
51 changes: 50 additions & 1 deletion cypress/e2e/admin/project_settings.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,56 @@ describe('project settings page as admin', () => {
assert_checkbox_values();
})

it('allows user to update grading policy', function() {
it('allows user to update group settings with valid values', function() {
enum ElementId {
min = 'min-group-size',
max = 'max-group-size',
disallow = 'disallow-group-registration'
}

const assert_correct_values = (min: number, max: number, disallow: boolean) => {
cy.get_by_testid(ElementId.min).should('have.value', min)
.get_by_testid(ElementId.max).should('have.value', max);

if (disallow) {
cy.get_by_testid(ElementId.disallow).should('be.checked');
}
else {
cy.get_by_testid(ElementId.disallow).should('not.be.checked');
}
}

cy.visit(this.page_uri);
assert_correct_values(1, 1, false);

cy.get_by_testid(ElementId.max).should('be.visible').type('{moveToEnd}{backspace}12');
assert_correct_values(1, 12, false);
cy.get_by_testid('save-button').click().reload()
assert_correct_values(1, 12, false);

cy.get_by_testid(ElementId.min).should('be.visible').type('{moveToEnd}{backspace}2');
assert_correct_values(2, 12, false);
cy.get_by_testid('save-button').click().reload()
assert_correct_values(2, 12, false);

cy.get_by_testid(ElementId.disallow).should('be.visible').check();
assert_correct_values(2, 12, true);
cy.get_by_testid('save-button').click().reload()
assert_correct_values(2, 12, true);

cy.get_by_testid(ElementId.max).should('be.visible').type('{moveToEnd}{backspace}{backspace}9');
assert_correct_values(2, 9, true);
cy.get_by_testid('save-button').click().reload()
assert_correct_values(2, 9, true);

cy.get_by_testid(ElementId.min).should('be.visible').type('{moveToEnd}{backspace}3');
assert_correct_values(3, 9, true);
cy.get_by_testid('save-button').click().reload()
assert_correct_values(3, 9, true);

cy.get_by_testid(ElementId.disallow).should('be.visible').uncheck();
assert_correct_values(3, 9, false);
cy.get_by_testid('save-button').click().reload()
assert_correct_values(3, 9, false);
})
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"lint": "./static_analysis.bash",
"build": "vue-cli-service build",
"component": "python3 run_tests.py && cypress run --component",
"test": "npm run component && npm run e2e"
"test": "npm run lint && npm run component && npm run e2e"
},
"dependencies": {
"@fortawesome/fontawesome-free": "^5.15.4",
Expand Down
4 changes: 3 additions & 1 deletion src/components/project_admin/project_settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
<div class="group-size-container">
<label class="label"> Min group size </label>
<validated-input id="min-group-size"
data_testid="min-group-size"
v-model="d_project.min_group_size"
:validators="[is_integer, is_not_empty, is_positive]"
:from_string_fn="string_to_num"
Expand All @@ -151,6 +152,7 @@
members the first time they visit the project page.
</tooltip>
<validated-input id="max-group-size"
data_testid="max-group-size"
v-model="d_project.max_group_size"
:validators="[is_integer, is_not_empty, is_positive]"
:from_string_fn="string_to_num"
Expand All @@ -162,7 +164,7 @@

<div class="checkbox-input-container">
<label class="checkbox-label">
<input data-testid="disallow_group_registration"
<input data-testid="disallow-group-registration"
type="checkbox"
class="checkbox"
v-model="d_project.disallow_group_registration"/>
Expand Down
1 change: 1 addition & 0 deletions src/components/validated_input.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe("<Validated_input />", () => {
const propsData = {
value: 1,
validators: [IS_NUMBER],
data_testid: "input",
from_string_fn: (val: string) => parseInt(val, 10),
};

Expand Down
5 changes: 4 additions & 1 deletion src/components/validated_input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="validated-input-wrapper">
<slot name="prefix"> </slot>
<input class="input"
data-testid="input"
:data-testid="data_testid"
v-if="num_rows === 1"
:style="input_style"
:class="{
Expand Down Expand Up @@ -97,6 +97,9 @@ export default class ValidatedInput extends Vue implements Created, Destroyed {
@Prop({default: false})
show_warnings_on_blur!: boolean;
@Prop({required: false, default: "validated-input"})
data_testid!: string;
d_input_value: string = "";
private d_is_valid: boolean = false;
d_error_msg: string = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('ProjectSettings tests', () => {
wrapper.vm.d_project.soft_closing_time = (new Date()).toISOString();
await wrapper.vm.$nextTick();

let button = wrapper.find('[data-testid=clear_soft_closing_time]');
let button = wrapper.find('[data-testid=clear-soft-deadline]');
expect(button.element).not.toBeDisabled();

button.trigger('click');
Expand Down Expand Up @@ -81,7 +81,7 @@ describe('ProjectSettings tests', () => {
wrapper.vm.d_project.closing_time = (new Date()).toISOString();
await wrapper.vm.$nextTick();

let button = wrapper.find('[data-testid=clear_closing_time]');
let button = wrapper.find('[data-testid=clear-hard-deadline]');
expect(button.element).not.toBeDisabled();

button.trigger('click');
Expand All @@ -107,7 +107,7 @@ describe('ProjectSettings tests', () => {
});

test('visible_to_students binding', async () => {
let checkbox = wrapper.find('[data-testid=visible_to_students]');
let checkbox = wrapper.find('[data-testid=visible-to-students]');

await checkbox.setChecked(true);
expect(wrapper.vm.d_project?.visible_to_students).toEqual(true);
Expand All @@ -129,7 +129,7 @@ describe('ProjectSettings tests', () => {
});

test('guests_can_submit binding', async () => {
let checkbox = wrapper.find('[data-testid=guests_can_submit]');
let checkbox = wrapper.find('[data-testid=guests-can-submit]');

await checkbox.setChecked(true);
expect(wrapper.vm.d_project?.guests_can_submit).toEqual(true);
Expand All @@ -151,7 +151,7 @@ describe('ProjectSettings tests', () => {
});

test('disallow_student_submissions binding', async () => {
let checkbox = wrapper.find('[data-testid=disallow_student_submissions]');
let checkbox = wrapper.find('[data-testid=disallow-student-submissions]');

await checkbox.setChecked(true);
expect(wrapper.vm.d_project?.disallow_student_submissions).toEqual(true);
Expand All @@ -173,7 +173,7 @@ describe('ProjectSettings tests', () => {
});

test('disallow_group_registration binding', async () => {
let checkbox = wrapper.find('[data-testid=disallow_group_registration]');
let checkbox = wrapper.find('[data-testid=disallow-group-registration]');

await checkbox.setChecked(true);
expect(wrapper.vm.d_project?.disallow_group_registration).toEqual(true);
Expand Down Expand Up @@ -218,7 +218,7 @@ describe('ProjectSettings tests', () => {
});

test('Publish final grades binding', async () => {
let publish_grades = wrapper.find('[data-testid=publish_final_grades]');
let publish_grades = wrapper.find('[data-testid=publish-final-grades]');

await publish_grades.setChecked(true);
expect(wrapper.vm.d_project?.hide_ultimate_submission_fdbk).toEqual(false);
Expand Down

0 comments on commit c6b2d18

Please sign in to comment.