1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
import {
setupInternalUserRegexHandler,
ID_USER_EMAIL,
ID_USER_EXTERNAL,
ID_WARNING,
} from '~/admin/users/new';
import { loadHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
describe('admin/users/new', () => {
const FIXTURE = 'admin/users/new_with_internal_user_regex.html';
let elExternal;
let elUserEmail;
let elWarningMessage;
beforeEach(() => {
loadHTMLFixture(FIXTURE);
setupInternalUserRegexHandler();
elExternal = document.getElementById(ID_USER_EXTERNAL);
elUserEmail = document.getElementById(ID_USER_EMAIL);
elWarningMessage = document.getElementById(ID_WARNING);
elExternal.checked = true;
});
afterEach(() => {
resetHTMLFixture();
});
const changeEmail = (val) => {
elUserEmail.value = val;
elUserEmail.dispatchEvent(new Event('input'));
};
const hasHiddenWarning = () => elWarningMessage.classList.contains('hidden');
describe('Behaviour of userExternal checkbox', () => {
it('hides warning by default', () => {
expect(hasHiddenWarning()).toBe(true);
});
describe('when matches email as internal', () => {
beforeEach(() => {
changeEmail('test@');
});
it('has external unchecked', () => {
expect(elExternal.checked).toBe(false);
});
it('shows warning', () => {
expect(hasHiddenWarning()).toBe(false);
});
describe('when external is checked again', () => {
beforeEach(() => {
elExternal.dispatchEvent(new Event('change'));
});
it('hides warning', () => {
expect(hasHiddenWarning()).toBe(true);
});
});
});
describe('when matches emails as external', () => {
beforeEach(() => {
changeEmail('test.ext@');
});
it('has external checked', () => {
expect(elExternal.checked).toBe(true);
});
it('hides warning', () => {
expect(hasHiddenWarning()).toBe(true);
});
});
});
});
|