Skip to content

Commit e007438

Browse files
Merge branch 'develop' into migrate/profile_view_PR-3
2 parents 06547fb + a0f0a99 commit e007438

File tree

5 files changed

+466
-0
lines changed

5 files changed

+466
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import { module, test } from 'qunit';
2+
import { setupRenderingTest } from 'website-www/tests/helpers';
3+
import { click, render, fillIn } from '@ember/test-helpers';
4+
import { hbs } from 'ember-cli-htmlbars';
5+
6+
module('Integration | Component | user-status-modal', function (hooks) {
7+
setupRenderingTest(hooks);
8+
9+
test('modal is visible if showModal is true', async function (assert) {
10+
this.setProperties({
11+
updateStatus: () => {},
12+
toggleUserStateModal: () => {},
13+
newStatus: 'ACTIVE',
14+
showUserStateModal: true,
15+
});
16+
await render(hbs`
17+
<UserStatusModal
18+
@newStatus={{this.newStatus}}
19+
@showUserStateModal={{this.showUserStateModal}}
20+
@toggleUserStateModal={{this.toggleUserStateModal}}
21+
@updateStatus={{this.updateStatus}}
22+
/>
23+
`);
24+
assert.dom('.status-modal').exists();
25+
assert.dom('.modal__close').exists();
26+
assert.dom('.modal__close').hasProperty('button');
27+
});
28+
29+
test('modal is not visible if showModal is false', async function (assert) {
30+
this.setProperties({
31+
updateStatus: () => {},
32+
toggleUserStateModal: () => {},
33+
newStatus: 'ACTIVE',
34+
showUserStateModal: false,
35+
});
36+
await render(hbs`
37+
<UserStatusModal
38+
@newStatus={{this.newStatus}}
39+
@showUserStateModal={{this.showUserStateModal}}
40+
@toggleUserStateModal={{this.toggleUserStateModal}}
41+
@updateStatus={{this.updateStatus}}
42+
/>
43+
`);
44+
assert.dom('.status-modal').doesNotExist();
45+
assert.dom('.modal__close').doesNotExist();
46+
});
47+
48+
test('payload contains relevant data when status is changed to OOO', async function (assert) {
49+
assert.expect(6);
50+
this.setProperties({
51+
newStatus: 'OOO',
52+
showUserStateModal: true,
53+
toggleUserStateModal: () => {
54+
this.set('showUserStateModal', !this.showUserStateModal);
55+
},
56+
updateStatus: (statusPayLoad) => {
57+
const {
58+
currentStatus: { state, from, until, message, updatedAt },
59+
} = statusPayLoad;
60+
console.log('Payload:', JSON.stringify(statusPayLoad, null, 2));
61+
assert.strictEqual(state, 'OOO', 'New state is present in the payload');
62+
assert.strictEqual(
63+
message,
64+
'OOO due to Bad Health',
65+
'Message is present in the payload',
66+
);
67+
assert.strictEqual(
68+
typeof from,
69+
'number',
70+
'From is a numeric timestamp',
71+
);
72+
assert.strictEqual(
73+
typeof until,
74+
'number',
75+
'Until is a numeric timestamp',
76+
);
77+
assert.strictEqual(
78+
typeof updatedAt,
79+
'number',
80+
'UpdatedAt is a numeric timestamp',
81+
);
82+
},
83+
});
84+
await render(hbs`
85+
<UserStatusModal
86+
@showUserStateModal={{this.showUserStateModal}}
87+
@newStatus={{this.newStatus}}
88+
@toggleUserStateModal={{this.toggleUserStateModal}}
89+
@updateStatus={{this.updateStatus}}
90+
/>
91+
`);
92+
93+
assert.dom('[data-test-modal]').exists();
94+
await fillIn('[data-test-date-picker-from]', '2025-01-05');
95+
await fillIn('[data-test-date-picker-until]', '2025-01-10');
96+
await fillIn('[data-test-textarea-reason]', 'OOO due to Bad Health');
97+
await click('.modal__submit');
98+
});
99+
100+
test('modal is closed on click of close button', async function (assert) {
101+
this.setProperties({
102+
newStatus: 'ACTIVE',
103+
showUserStateModal: true,
104+
toggleUserStateModal: () => {
105+
this.set('showUserStateModal', !this.showUserStateModal);
106+
},
107+
});
108+
await render(hbs`
109+
<UserStatusModal
110+
@newStatus={{this.newStatus}}
111+
@showUserStateModal={{this.showUserStateModal}}
112+
@toggleUserStateModal={{this.toggleUserStateModal}}
113+
/>
114+
`);
115+
assert.dom('.status-modal').exists();
116+
assert.dom('.modal__close').exists();
117+
await click('.modal__close');
118+
assert.dom('.status-modal').doesNotExist();
119+
});
120+
});
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { module, test } from 'qunit';
2+
import { setupRenderingTest } from 'website-www/tests/helpers';
3+
import { click, render } from '@ember/test-helpers';
4+
import { hbs } from 'ember-cli-htmlbars';
5+
6+
module('Integration | Component | user-status', function (hooks) {
7+
setupRenderingTest(hooks);
8+
9+
test('show relevant data when status is Onboarding', async function (assert) {
10+
this.setProperties({
11+
changeStatus: () => {},
12+
updateStatus: () => {},
13+
status: 'ONBOARDING',
14+
isStatusUpdating: false,
15+
});
16+
await render(hbs`
17+
<UserStatus
18+
@status={{this.status}}
19+
@changeStatus={{this.changeStatus}}
20+
@isStatusUpdating={{this.isStatusUpdating}}
21+
@updateStatus={{this.updateStatus}}
22+
/>`);
23+
24+
assert.dom('[data-test-onboarding-details]').exists();
25+
assert
26+
.dom('[data-test-status]')
27+
.containsText('You are undergoing onboarding');
28+
});
29+
30+
test('show relevant data when status is IDLE', async function (assert) {
31+
this.setProperties({
32+
changeStatus: () => {},
33+
updateStatus: () => {},
34+
status: 'IDLE',
35+
isStatusUpdating: false,
36+
});
37+
await render(hbs`
38+
<UserStatus
39+
@status={{this.status}}
40+
@changeStatus={{this.changeStatus}}
41+
@isStatusUpdating={{this.isStatusUpdating}}
42+
@updateStatus={{this.updateStatus}}
43+
/>
44+
`);
45+
46+
assert.dom('[data-test-status]').containsText('You are Idle');
47+
assert
48+
.dom('[data-test-update-status-OOO]')
49+
.containsText('Change your status to OOO');
50+
});
51+
52+
test('show relevant data when status is OOO', async function (assert) {
53+
this.setProperties({
54+
status: 'OOO',
55+
isStatusUpdating: false,
56+
changeStatus: () => {},
57+
updateStatus: () => {},
58+
});
59+
await render(hbs`
60+
<UserStatus
61+
@status={{this.status}}
62+
@changeStatus={{this.changeStatus}}
63+
@isStatusUpdating={{this.isStatusUpdating}}
64+
@updateStatus={{this.updateStatus}}
65+
/>
66+
`);
67+
68+
assert.dom('[data-test-status]').containsText('You are OOO');
69+
assert.dom('[ data-test-cancel-status-OOO]').hasProperty('button');
70+
assert.dom('[ data-test-cancel-status-OOO]').containsText('Cancel OOO');
71+
});
72+
73+
test('payload shows relevant data when status is changed from OOO', async function (assert) {
74+
assert.expect(1);
75+
this.setProperties({
76+
status: 'OOO',
77+
isStatusUpdating: false,
78+
changeStatus: () => {},
79+
updateStatus: (cancelOOOPayload) => {
80+
const { cancelOOOStatus } = cancelOOOPayload;
81+
assert.true(cancelOOOStatus, 'cancel OOO status');
82+
},
83+
});
84+
await render(hbs`
85+
<UserStatus
86+
@status={{this.status}}
87+
@changeStatus={{this.changeStatus}}
88+
@isStatusUpdating={{this.isStatusUpdating}}
89+
@updateStatus={{this.updateStatus}}
90+
/>
91+
`);
92+
await click('.buttons__cancel--ooo');
93+
});
94+
});
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import { module, test } from 'qunit';
2+
import { setupTest } from 'website-www/tests/helpers';
3+
import { USER_STATES } from 'website-www/constants/user-status';
4+
import Service from '@ember/service';
5+
import sinon from 'sinon';
6+
import { APPS } from 'website-www/constants/urls';
7+
const API_BASE_URL = APPS.API_BACKEND;
8+
9+
class MockToastService extends Service {
10+
success() {}
11+
error() {}
12+
}
13+
14+
module('Unit | Controller | status', function (hooks) {
15+
setupTest(hooks);
16+
17+
hooks.beforeEach(function () {
18+
this.owner.register('service:toast', MockToastService);
19+
this.fetchStub = sinon.stub(window, 'fetch');
20+
});
21+
22+
hooks.afterEach(function () {
23+
this.fetchStub.restore();
24+
});
25+
26+
test('it initializes with default values', function (assert) {
27+
const controller = this.owner.lookup('controller:status');
28+
assert.false(
29+
controller.isStatusUpdating,
30+
'isStatusUpdating is false by default',
31+
);
32+
assert.false(
33+
controller.showUserStateModal,
34+
'showUserStateModal is false by default',
35+
);
36+
assert.strictEqual(
37+
controller.newStatus,
38+
undefined,
39+
'newStatus is undefined by default',
40+
);
41+
});
42+
43+
test('updateStatus sends the correct request', async function (assert) {
44+
const mockResponse = {
45+
data: {
46+
currentStatus: { state: USER_STATES.ACTIVE },
47+
},
48+
};
49+
50+
this.fetchStub.resolves(
51+
new Response(JSON.stringify(mockResponse), {
52+
status: 200,
53+
headers: { 'Content-Type': 'application/json' },
54+
}),
55+
);
56+
57+
const controller = this.owner.lookup('controller:status');
58+
const newStatus = { currentStatus: { state: 'ACTIVE' } };
59+
await controller.updateStatus(newStatus);
60+
61+
assert.ok(this.fetchStub.calledOnce, 'Fetch was called once');
62+
assert.ok(
63+
this.fetchStub.calledWith(
64+
`${API_BASE_URL}/users/status/self?userStatusFlag=true`,
65+
),
66+
'Fetch was called with the correct URL',
67+
);
68+
});
69+
70+
test('updateStatus correctly handles different user states', async function (assert) {
71+
assert.expect(10);
72+
const controller = this.owner.lookup('controller:status');
73+
const toastService = this.owner.lookup('service:toast');
74+
toastService.success = sinon.spy();
75+
toastService.error = sinon.spy();
76+
77+
const mockResponses = {
78+
ACTIVE: { data: { currentStatus: { state: USER_STATES.ACTIVE } } },
79+
OOO: { data: { currentStatus: { state: USER_STATES.OOO } } },
80+
ONBOARDING: {
81+
data: { currentStatus: { state: USER_STATES.ONBOARDING } },
82+
},
83+
IDLE: { data: { currentStatus: { state: USER_STATES.IDLE } } },
84+
DNE: { data: { currentStatus: { state: USER_STATES.DNE } } },
85+
};
86+
87+
const setupFetchResponse = (status) => {
88+
this.fetchStub.resolves(
89+
new Response(JSON.stringify(mockResponses[status]), {
90+
status: 200,
91+
headers: { 'Content-Type': 'application/json' },
92+
}),
93+
);
94+
};
95+
96+
for (const state of Object.keys(mockResponses)) {
97+
setupFetchResponse(state);
98+
99+
const newStatus = { currentStatus: { state: USER_STATES[state] } };
100+
await controller.updateStatus(newStatus);
101+
assert.ok(
102+
toastService.success.calledOnce,
103+
`Success toast is shown for ${state}`,
104+
);
105+
assert.strictEqual(
106+
controller.status,
107+
USER_STATES[state],
108+
`Status is updated to ${state}`,
109+
);
110+
toastService.success.resetHistory();
111+
this.fetchStub.resetHistory();
112+
}
113+
});
114+
115+
test('toggleUserStateModal works with OOO status', function (assert) {
116+
let controller = this.owner.lookup('controller:status');
117+
controller.status = USER_STATES.OOO;
118+
controller.toggleUserStateModal();
119+
assert.ok(
120+
controller.showUserStateModal,
121+
'User state modal is shown for OOO status',
122+
);
123+
});
124+
});

0 commit comments

Comments
 (0)