Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion make/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: Testrun
Version: 2.4.0-beta.5
Version: 2.4.0-beta.6
Architecture: amd64
Maintainer: Google <ssm-orcas@google.com>
Homepage: https://github.com/google/testrun
Expand Down
23 changes: 23 additions & 0 deletions modules/ui/src/app/mocks/profile.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,29 @@ export const NEW_PROFILE_MOCK_DRAFT = {
],
};

export const NEW_PROFILE_MOCK_CHANGED = {
...NEW_PROFILE_MOCK,
questions: [
{
question: 'What is the email of the device owner(s)?',
answer: 'a@test.te;b@test.te, c@test.te, d@test.te',
},
{
question: 'What type of device do you need reviewed?',
answer: 'new',
},
{
question: 'Are any of the following statements true about your device?',
answer: 'new',
},
{
question: 'What features does the device have?',
answer: [0, 1, 2, 4],
},
{ question: 'Comments', answer: 'no' },
],
};

export const RENAME_PROFILE_MOCK = {
...NEW_PROFILE_MOCK,
name: 'Primary profile',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,105 @@ describe('DeviceQualificationFromComponent', () => {
expect(saveSpy).toHaveBeenCalledWith(MOCK_DEVICE);
});
});

describe('compareDevices', () => {
it('should return false if manufacturer has changes', () => {
const updated_device = {
...device,
manufacturer: 'new manufacturer',
};

expect(component.compareDevices(device, updated_device)).toBeFalse();
});
});

it('should return false if model has changes', () => {
const updated_device = {
...device,
model: 'new model',
};

expect(component.compareDevices(device, updated_device)).toBeFalse();
});

it('should return false if mac_addr has changes', () => {
const updated_device = {
...device,
mac_addr: 'new mac_addr',
};

expect(component.compareDevices(device, updated_device)).toBeFalse();
});

it('should return false if type has changes', () => {
const updated_device = {
...device,
type: 'new type',
};

expect(component.compareDevices(device, updated_device)).toBeFalse();
});

it('should return false if technology has changes', () => {
const updated_device = {
...device,
technology: 'new technology',
};

expect(component.compareDevices(device, updated_device)).toBeFalse();
});

it('should return false if test_pack has changes', () => {
const updated_device = {
...device,
test_pack: TestingType.Qualification,
};

expect(component.compareDevices(device, updated_device)).toBeFalse();
});

it('should return false if test modules has changes', () => {
const updated_device = {
...device,
test_modules: {
dns: {
enabled: true,
},
connection: {
enabled: true,
},
},
};

expect(component.compareDevices(device, updated_device)).toBeFalse();
});

it('should return false if additional info has changes', () => {
const updated_device = {
...device,
additional_info: [
{
question: 'Please select the technology this device falls into',
answer: 'Building Automation',
},
],
};

expect(component.compareDevices(device, updated_device)).toBeFalse();
});

it('should return true if device has no changes', () => {
const new_device = {
...device,
additional_info: [
{
question: 'Please select the technology this device falls into',
answer: 'Building Automation',
},
],
};
expect(component.compareDevices(new_device, new_device)).toBeTrue();
});
});

@Component({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,36 +295,63 @@ export class DeviceQualificationFromComponent implements OnInit, AfterViewInit {
);
}

private deviceIsEmpty(device: Device) {
if (device.manufacturer && device.manufacturer !== '') {
compareDevices(device1: Device, device2: Device) {
if (device1.manufacturer !== device2.manufacturer) {
return false;
}
if (device.model && device.model !== '') {
if (device1.model !== device2.model) {
return false;
}
if (device.mac_addr && device.mac_addr !== '') {
if (device1.mac_addr !== device2.mac_addr) {
return false;
}
if (device.type && device.type !== '') {
if (device1.type !== device2.type) {
return false;
}
if (device.technology && device.technology !== '') {
if (device1.technology !== device2.technology) {
return false;
}
if (device.test_pack !== TestingType.Qualification) {
if (device1.test_pack !== device2.test_pack) {
return false;
}
const keys1 = Object.keys(device.test_modules!);
const keys1 = Object.keys(device1.test_modules!);

for (const key of keys1) {
const val1 = device.test_modules![key];
if (!val1.enabled) {
const val1 = device1.test_modules![key];
const val2 = device2.test_modules![key];
if (val1?.enabled !== val2?.enabled) {
return false;
}
}
if (device.additional_info) {
for (const question of device.additional_info) {
if (question.answer && question.answer !== '') {

// the 2nd device has the newest version of risk assessment
if (device2.additional_info) {
for (const question of device2.additional_info) {
const answer2 = device1.additional_info?.find(
question1 => question1.question === question.question
)?.answer;
const answer1 = question.answer;
if (!this.isEmptyAnswer(answer1) && !this.isEmptyAnswer(answer2)) {
if (typeof question.answer === 'string') {
if (answer1 !== answer2) {
return false;
}
} else {
//the type of answer is array
if (answer1?.length !== answer2?.length) {
return false;
}
if (
(answer1 as number[]).some(
answer => !(answer2 as number[]).includes(answer)
)
)
return false;
}
} else if (
this.isEmptyAnswer(answer2) &&
!this.isEmptyAnswer(answer1)
) {
return false;
}
}
Expand All @@ -334,43 +361,36 @@ export class DeviceQualificationFromComponent implements OnInit, AfterViewInit {
return true;
}

private compareDevices(device1: Device, device2: Device) {
if (device1.manufacturer !== device2.manufacturer) {
private deviceIsEmpty(device: Device) {
if (device.manufacturer && device.manufacturer !== '') {
return false;
}
if (device1.model !== device2.model) {
if (device.model && device.model !== '') {
return false;
}
if (device1.mac_addr !== device2.mac_addr) {
if (device.mac_addr && device.mac_addr !== '') {
return false;
}
if (device1.type !== device2.type) {
if (device.type && device.type !== '') {
return false;
}
if (device1.technology !== device2.technology) {
if (device.technology && device.technology !== '') {
return false;
}
if (device1.test_pack !== device2.test_pack) {
if (device.test_pack !== TestingType.Qualification) {
return false;
}
const keys1 = Object.keys(device1.test_modules!);
const keys1 = Object.keys(device.test_modules!);

for (const key of keys1) {
const val1 = device1.test_modules![key];
const val2 = device2.test_modules![key];
if (val1?.enabled !== val2?.enabled) {
const val1 = device.test_modules![key];
if (!val1.enabled) {
return false;
}
}

if (device1.additional_info) {
for (const question of device1.additional_info) {
if (
question.answer !==
device2.additional_info?.find(
question2 => question2.question === question.question
)?.answer
) {
if (device.additional_info) {
for (const question of device.additional_info) {
if (question.answer && question.answer !== '') {
return false;
}
}
Expand All @@ -380,6 +400,12 @@ export class DeviceQualificationFromComponent implements OnInit, AfterViewInit {
return true;
}

private isEmptyAnswer(answer: unknown): boolean {
if (answer === undefined || answer === null || answer === '') return true;
if (Array.isArray(answer) && answer.length === 0) return true;
return false;
}

private fillDeviceForm(format: QuestionFormat[], device: Device): void {
format.forEach((question, index) => {
const answer = device.additional_info?.find(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
COPY_PROFILE_MOCK,
EXPIRED_PROFILE_MOCK,
NEW_PROFILE_MOCK,
NEW_PROFILE_MOCK_CHANGED,
NEW_PROFILE_MOCK_DRAFT,
OUTDATED_DRAFT_PROFILE_MOCK,
PROFILE_FORM,
Expand Down Expand Up @@ -489,6 +490,48 @@ describe('ProfileFormComponent', () => {
done();
});
});

describe('compareProfiles', () => {
it('should return false if the name is different', () => {
const res = component.compareProfiles(PROFILE_MOCK, PROFILE_MOCK_2);

expect(res).toBeFalse();
});

it('should return false for copy of profile', () => {
const res = component.compareProfiles(
PROFILE_MOCK,
PROFILE_MOCK,
PROFILE_MOCK_2
);

expect(res).toBeFalse();
});

it('should return false is profile status is different', () => {
const res = component.compareProfiles(
NEW_PROFILE_MOCK,
NEW_PROFILE_MOCK_DRAFT
);

expect(res).toBeFalse();
});

it('should return false is profile has changes', () => {
const res = component.compareProfiles(
NEW_PROFILE_MOCK,
NEW_PROFILE_MOCK_CHANGED
);

expect(res).toBeFalse();
});

it('should return true is profile has no changes', () => {
const res = component.compareProfiles(PROFILE_MOCK, PROFILE_MOCK);

expect(res).toBeTrue();
});
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,12 @@ export class ProfileFormComponent implements OnInit, AfterViewInit {
return true;
}

private compareProfiles(profile1: Profile, profile2: Profile) {
if (profile1.name !== profile2.name || this.copyProfile) {
compareProfiles(
profile1: Profile,
profile2: Profile,
copyProfile = this.copyProfile
) {
if (profile1.name !== profile2.name || copyProfile) {
return false;
}
if (
Expand Down