|
| 1 | +import { beforeEach, describe, expect, it, vi } from 'vitest' |
| 2 | +import { mockFiles, mockParser, mockSessionStorage, registerMockRouter } from './mocks' |
| 3 | + |
| 4 | +registerMockRouter() |
| 5 | +mockSessionStorage() |
| 6 | +mockParser() |
| 7 | + |
| 8 | +import { reportStore } from '../../../src/stores/reportStore' |
| 9 | +import { setActivePinia, createPinia } from 'pinia' |
| 10 | + |
| 11 | +describe('Test Anonymization', () => { |
| 12 | + beforeEach(() => { |
| 13 | + setActivePinia(createPinia()) |
| 14 | + vi.clearAllMocks() |
| 15 | + reportStore().reset() |
| 16 | + reportStore().loadReport(mockFiles, [], 'test') |
| 17 | + }) |
| 18 | + |
| 19 | + it('Getting Display Name', () => { |
| 20 | + expect(reportStore().getPlainDisplayName('test1')).toEqual('Test1') |
| 21 | + expect(reportStore().getDisplayName('test1')).toEqual('Test1') |
| 22 | + }) |
| 23 | + |
| 24 | + it('Getting Display Name with Anonymization', () => { |
| 25 | + reportStore().setAnonymous('test1', true) |
| 26 | + expect(reportStore().getAnonymizedName('test1')).toEqual('anon1') |
| 27 | + expect(reportStore().getDisplayName('test1')).toEqual('anon1') |
| 28 | + expect(reportStore().getPlainDisplayName('test1')).toEqual('Test1') |
| 29 | + }) |
| 30 | + |
| 31 | + it('Keep number asociated with anonymized names', () => { |
| 32 | + reportStore().setAnonymous('test1', true) |
| 33 | + reportStore().setAnonymous('test2', true) |
| 34 | + expect(reportStore().getDisplayName('test1')).toEqual('anon1') |
| 35 | + expect(reportStore().getDisplayName('test2')).toEqual('anon2') |
| 36 | + |
| 37 | + reportStore().setAnonymous('test1', false) |
| 38 | + reportStore().setAnonymous('test3', true) |
| 39 | + |
| 40 | + expect(reportStore().getDisplayName('test1')).toEqual('Test1') |
| 41 | + expect(reportStore().getDisplayName('test2')).toEqual('anon2') |
| 42 | + expect(reportStore().getDisplayName('test3')).toEqual('anon3') |
| 43 | + |
| 44 | + reportStore().setAnonymous('test1', true) |
| 45 | + expect(reportStore().getDisplayName('test1')).toEqual('anon1') |
| 46 | + }) |
| 47 | + |
| 48 | + it('Test isAnonymized', () => { |
| 49 | + expect(reportStore().isAnonymized('test1')).toEqual(false) |
| 50 | + reportStore().setAnonymous('test1', true) |
| 51 | + expect(reportStore().isAnonymized('test1')).toEqual(true) |
| 52 | + reportStore().setAnonymous('test1', false) |
| 53 | + expect(reportStore().isAnonymized('test1')).toEqual(false) |
| 54 | + reportStore().setAnonymous('test1', true) |
| 55 | + |
| 56 | + reportStore().setAnonymous('test2', true) |
| 57 | + expect(reportStore().isAnonymized('test2')).toEqual(true) |
| 58 | + reportStore().setAnonymous('test2', false) |
| 59 | + expect(reportStore().isAnonymized('test2')).toEqual(false) |
| 60 | + }) |
| 61 | + |
| 62 | + it('Test toggleAnonymous', () => { |
| 63 | + expect(reportStore().isAnonymized('test1')).toEqual(false) |
| 64 | + reportStore().toggleAnonymous('test1') |
| 65 | + expect(reportStore().isAnonymized('test1')).toEqual(true) |
| 66 | + reportStore().toggleAnonymous('test1') |
| 67 | + expect(reportStore().isAnonymized('test1')).toEqual(false) |
| 68 | + |
| 69 | + reportStore().setAnonymous('test2', true) |
| 70 | + expect(reportStore().isAnonymized('test2')).toEqual(true) |
| 71 | + reportStore().toggleAnonymous('test2') |
| 72 | + expect(reportStore().isAnonymized('test2')).toEqual(false) |
| 73 | + reportStore().toggleAnonymous('test2') |
| 74 | + expect(reportStore().isAnonymized('test2')).toEqual(true) |
| 75 | + }) |
| 76 | + |
| 77 | + it('Test allAreAnonymized', () => { |
| 78 | + expect(reportStore().allAreAnonymized()).toEqual(false) |
| 79 | + reportStore().setAnonymous('test1', true) |
| 80 | + expect(reportStore().allAreAnonymized()).toEqual(false) |
| 81 | + reportStore().setAnonymous('test2', true) |
| 82 | + expect(reportStore().allAreAnonymized()).toEqual(false) |
| 83 | + reportStore().setAnonymous('test3', true) |
| 84 | + expect(reportStore().allAreAnonymized()).toEqual(true) |
| 85 | + reportStore().setAnonymous('test2', false) |
| 86 | + expect(reportStore().allAreAnonymized()).toEqual(false) |
| 87 | + reportStore().setAnonymous('test1', false) |
| 88 | + expect(reportStore().allAreAnonymized()).toEqual(false) |
| 89 | + reportStore().setAnonymous('test2', true) |
| 90 | + expect(reportStore().allAreAnonymized()).toEqual(false) |
| 91 | + reportStore().setAnonymous('test1', true) |
| 92 | + expect(reportStore().allAreAnonymized()).toEqual(true) |
| 93 | + }) |
| 94 | + |
| 95 | + it('Test toggleAnonymousForAll', () => { |
| 96 | + expect(reportStore().isAnonymized('test1')).toEqual(false) |
| 97 | + expect(reportStore().isAnonymized('test2')).toEqual(false) |
| 98 | + expect(reportStore().isAnonymized('test3')).toEqual(false) |
| 99 | + reportStore().toggleAnonymousForAll() |
| 100 | + expect(reportStore().isAnonymized('test1')).toEqual(true) |
| 101 | + expect(reportStore().isAnonymized('test2')).toEqual(true) |
| 102 | + expect(reportStore().isAnonymized('test3')).toEqual(true) |
| 103 | + reportStore().toggleAnonymousForAll() |
| 104 | + expect(reportStore().isAnonymized('test1')).toEqual(false) |
| 105 | + expect(reportStore().isAnonymized('test2')).toEqual(false) |
| 106 | + expect(reportStore().isAnonymized('test3')).toEqual(false) |
| 107 | + |
| 108 | + // Test behavior when some are already anonymized and some are not |
| 109 | + reportStore().setAnonymous('test1', true) |
| 110 | + reportStore().setAnonymous('test2', true) |
| 111 | + expect(reportStore().isAnonymized('test1')).toEqual(true) |
| 112 | + expect(reportStore().isAnonymized('test2')).toEqual(true) |
| 113 | + expect(reportStore().isAnonymized('test3')).toEqual(false) |
| 114 | + reportStore().toggleAnonymousForAll() |
| 115 | + expect(reportStore().isAnonymized('test1')).toEqual(true) |
| 116 | + expect(reportStore().isAnonymized('test2')).toEqual(true) |
| 117 | + expect(reportStore().isAnonymized('test3')).toEqual(true) |
| 118 | + }) |
| 119 | +}) |
0 commit comments