feat: 🎸 implement sort for session recordings (#2837)

* feat: 🎸 implement sort for session recordings

* refactor: 💡 update selectors w/ pr feedback

* refactor: 💡 remove click in tests

* test: 💍 update selectors due to merge

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-17065
This commit is contained in:
Lisbet Alvarez authored and GitHub committed 2025-05-22 10:27:19 -07:00
1 parent 44bd5ee1c6
commit c12edc7f73
4 files changed
+240 -84

No files matched your search

@@ -12,13 +12,27 @@ import { authenticateSession } from 'ember-simple-auth/test-support';
import { faker } from '@faker-js/faker';
import * as commonSelectors from 'admin/tests/helpers/selectors';
import * as selectors from './selectors';
import {
STATE_SESSION_RECORDING_STARTED,
STATE_SESSION_RECORDING_AVAILABLE,
STATE_SESSION_RECORDING_UNKNOWN,
} from 'api/models/session-recording';
module('Acceptance | session recordings | list', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
setupIndexedDb(hooks);
const CREATED_TIME_VALUES_ARRAY = [
'2020-01-01T00:00:00.010Z',
'2020-01-01T00:00:00.100Z',
'2020-01-01T00:00:01.000Z',
'2020-01-01T00:00:10.000Z',
'2020-01-01T00:01:00.000Z',
];
let featuresService;
let createdTimeValues;
// Instances
const instances = {
@@ -66,20 +80,21 @@ module('Acceptance | session recordings | list', function (hooks) {
});
instances.user = this.server.create('user');
instances.user2 = this.server.create('user');
createdTimeValues = {
target: {
id: instances.target.id,
name: instances.target.name,
scope: {
id: instances.scopes.project.id,
name: instances.scopes.project.name,
parent_scope_id: instances.scopes.org.id,
},
},
user: instances.user.attrs,
};
instances.sessionRecording = this.server.create('session-recording', {
scope: instances.scopes.global,
create_time_values: {
target: {
id: instances.target.id,
name: instances.target.name,
scope: {
id: instances.scopes.project.id,
name: instances.scopes.project.name,
parent_scope_id: instances.scopes.org.id,
},
},
user: instances.user.attrs,
},
create_time_values: createdTimeValues,
});
instances.sessionRecording2 = this.server.create('session-recording', {
scope: instances.scopes.global,
@@ -231,4 +246,96 @@ module('Acceptance | session recordings | list', function (hooks) {
assert.dom(commonSelectors.TABLE_ROWS).isVisible({ count: 1 });
});
test('session recordings table is sorted by `created_time` descending by default', async function (assert) {
this.server.schema.sessionRecordings.all().destroy();
const expectedDescendingSort = CREATED_TIME_VALUES_ARRAY.toReversed();
faker.helpers.shuffle(expectedDescendingSort).forEach((value) => {
this.server.create('session-recording', {
created_time: value,
scope: instances.scopes.global,
create_time_values: createdTimeValues,
});
});
await visit(urls.sessionRecordings);
assert
.dom(commonSelectors.TABLE_ROWS)
.isVisible({ count: CREATED_TIME_VALUES_ARRAY.length });
expectedDescendingSort.forEach((expected, index) => {
// nth-child index starts at 1
assert.dom(commonSelectors.TABLE_ROW(index + 1)).containsText(expected);
});
});
test.each(
'sorting',
{
'on created_time': {
attribute: {
key: 'created_time',
values: CREATED_TIME_VALUES_ARRAY,
},
expectedAscendingSort: CREATED_TIME_VALUES_ARRAY,
column: 1,
},
'on state': {
attribute: {
key: 'state',
values: [
STATE_SESSION_RECORDING_AVAILABLE,
STATE_SESSION_RECORDING_UNKNOWN,
STATE_SESSION_RECORDING_STARTED,
],
},
expectedAscendingSort: ['Completed', 'Recording', 'Failed'],
column: 2,
},
},
async function (assert, input) {
this.server.schema.sessionRecordings.all().destroy();
faker.helpers.shuffle(input.attribute.values).forEach((value) => {
this.server.create('session-recording', {
[input.attribute.key]: value,
scope: instances.scopes.global,
create_time_values: createdTimeValues,
});
});
await visit(urls.sessionRecordings);
// click the sort button to sort in ascending order for provided column key
await click(commonSelectors.TABLE_SORT_BTN(input.column));
assert.true(currentURL().includes('sortDirection=asc'));
assert.true(
currentURL().includes(`sortAttribute=${input.attribute.key}`),
);
assert
.dom(commonSelectors.TABLE_SORT_BTN_ARROW_UP(input.column))
.isVisible();
assert
.dom(commonSelectors.TABLE_ROWS)
.isVisible({ count: input.attribute.values.length });
input.expectedAscendingSort.forEach((expected, index) => {
// nth-child index starts at 1
assert.dom(commonSelectors.TABLE_ROW(index + 1)).containsText(expected);
});
// click the sort button again to sort in descending order
await click(commonSelectors.TABLE_SORT_BTN(input.column));
assert.true(currentURL().includes('sortDirection=desc'));
assert.true(
currentURL().includes(`sortAttribute=${input.attribute.key}`),
);
assert
.dom(commonSelectors.TABLE_SORT_BTN_ARROW_DOWN(input.column))
.isVisible();
input.expectedAscendingSort.toReversed().forEach((expected, index) => {
// nth-child index starts at 1
assert.dom(commonSelectors.TABLE_ROW(index + 1)).containsText(expected);
});
},
);
});