|
| 1 | +import { FileType, JFile } from '@models/file.model'; |
| 2 | + |
| 3 | +import { FilesAttackTableComponent } from '@components/tables/files-attack-table/files-attack-table.component'; |
| 4 | +import { CheckboxChangeEvent } from '@components/tables/ht-table/ht-table.models'; |
| 5 | + |
| 6 | +describe('FilesAttackTableComponent', () => { |
| 7 | + const rule = (id: number, filename: string): JFile => ({ |
| 8 | + id, |
| 9 | + type: 'file', |
| 10 | + filename, |
| 11 | + size: 0, |
| 12 | + isSecret: false, |
| 13 | + fileType: FileType.RULES, |
| 14 | + accessGroupId: 1, |
| 15 | + lineCount: 0 |
| 16 | + }); |
| 17 | + |
| 18 | + const unchecked = (row: JFile): CheckboxChangeEvent => ({ |
| 19 | + row, |
| 20 | + columnType: 'CMD', |
| 21 | + checked: false |
| 22 | + }); |
| 23 | + |
| 24 | + // onPrepareAttack is pure, so no Angular fixture is needed for these command transformations. |
| 25 | + const component = Object.create(FilesAttackTableComponent.prototype) as FilesAttackTableComponent; |
| 26 | + |
| 27 | + it('does not remove another rule flag when the unchecked rule was manually removed', () => { |
| 28 | + const result = component.onPrepareAttack( |
| 29 | + { |
| 30 | + attackCmd: '#HL# -r dive.rule', |
| 31 | + files: [9, 10] |
| 32 | + }, |
| 33 | + unchecked(rule(9, 'best66.rule')) |
| 34 | + ); |
| 35 | + |
| 36 | + expect(result.attackCmd).toBe('#HL# -r dive.rule'); |
| 37 | + expect(result.files).toEqual([10]); |
| 38 | + }); |
| 39 | + |
| 40 | + it('removes only the flag paired with the unchecked rule', () => { |
| 41 | + const result = component.onPrepareAttack( |
| 42 | + { |
| 43 | + attackCmd: '#HL# -r best66.rule -r dive.rule', |
| 44 | + files: [9, 10] |
| 45 | + }, |
| 46 | + unchecked(rule(9, 'best66.rule')) |
| 47 | + ); |
| 48 | + |
| 49 | + expect(result.attackCmd).toBe('#HL# -r dive.rule'); |
| 50 | + expect(result.files).toEqual([10]); |
| 51 | + }); |
| 52 | +}); |
0 commit comments