-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMultiIdentityPicker.test.tsx
More file actions
80 lines (55 loc) · 2.35 KB
/
MultiIdentityPicker.test.tsx
File metadata and controls
80 lines (55 loc) · 2.35 KB
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
/**
* @jest-environment jsdom
*/
import '@testing-library/jest-dom'
import {
fireEvent,
render,
screen,
waitFor
} from '@testing-library/react';
import React from 'react';
import { mockGetFieldValue } from '../__mocks__/azure-devops-extension-sdk'
import MultiIdentityPicker from '../MultiIdentityPicker/MultiIdentityPicker'
// AzDO related Mocks (implementations /src/__mocks__)
// Extension related Mocks
jest.mock('../Common');
test('MultiIdentityPicker - use current Identity if no one can loaded', async () => {
// Start with no Identities provided in the work item field assigned
mockGetFieldValue.mockReturnValue("");
// This will start rendering the control for the test and
// therefore invoke componentDidMount() of MultiIdentityPicker
render(<MultiIdentityPicker />);
// Check if the current user was assigned
await waitFor(() => screen.getByText('Jest Wagner'));
expect(screen.getByText('Jest Wagner')).toBeDefined();
});
test('MultiIdentityPicker - load and display Identity', async () => {
// Identities Field Value is set to git@h2floh.net
mockGetFieldValue.mockReturnValue("[\"git@h2floh.net\"]");
// Render the MultiIdentityPicker control
render(<MultiIdentityPicker />);
// Check if the user associated to git@h2floh.net is displayed
await waitFor(() => screen.getByText('Florian Wagner'));
expect(screen.getByText('Florian Wagner')).toBeDefined();
});
test('MultiIdentityPicker - invalid Identity input', async () => {
// Identities Field Value is set to invalid
mockGetFieldValue.mockReturnValue("asdfasdf");
render(<MultiIdentityPicker />);
await waitFor(() => {
expect(screen.getByLabelText('Add people')).toBeDefined();
});
});
test('MultiIdentityPicker - On Identity Removed', async () => {
// Identities Field Value is set to git@h2floh.net, gdhong@h2floh.net
mockGetFieldValue.mockReturnValue("[\"git@h2floh.net\",\"gdhong@h2floh.net\"]");
render(<MultiIdentityPicker />);
await waitFor(() => screen.getByText('GilDong Hong'));
expect(screen.getByText('GilDong Hong')).toBeDefined();
const buttons = screen.getAllByLabelText('Remove GilDong Hong');
// Button 'GilDong Hong' Delete
fireEvent.click(buttons[0]);
await waitFor(() => screen.getByText('Florian Wagner'));
expect((screen.queryAllByText('GilDong Hong')).length).toBe(0);
});