refactor: 💡 Show View instead of Play if channel not asciicast (#325)
* refactor: 💡 Show View instead of Play if channel not asciicast ✅ Closes: ICU-9524 * refactor: 💡 every third channel is missing mime_types * refactor: 💡 create new abilities for channel-recording * refactor: 💡 use abilities for button logic for channels * test: 💍 update channel-recording ability tests * refactor: 💡 fix ChannelRecording ability import name * refactor: 💡 change ability name to canPlay from canPlayChannel * refactor: 💡 update OverrideChannelRecording ability methods
This commit is contained in:
1 parent
0ac8ec0290
commit
b01d5f0271
5 files changed
+102
-3
No files matched your search
@@ -6,6 +6,7 @@
|
||||
import factory from '../generated/factories/channel-recording';
|
||||
import generateId from '../helpers/id';
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { MIME_TYPE_ASCIICAST } from 'api/models/channel-recording';
|
||||
|
||||
export default factory.extend({
|
||||
id: () => generateId('chr_'),
|
||||
@@ -14,4 +15,5 @@ export default factory.extend({
|
||||
},
|
||||
end_time: (i) => (i % 3 === 2 ? null : faker.date.recent()),
|
||||
duration: (i) => (i % 3 === 2 ? null : `${faker.datatype.number()}s`),
|
||||
mime_types: (i) => (i % 3 === 2 ? null : [MIME_TYPE_ASCIICAST]),
|
||||
});
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
import { Factory } from 'miragejs';
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { MIME_TYPE_ASCIICAST } from 'api/models/channel-recording';
|
||||
|
||||
/**
|
||||
* GeneratedChannelRecordingModelFactory
|
||||
@@ -16,5 +15,4 @@ export default Factory.extend({
|
||||
bytes_down: () =>
|
||||
faker.random.numeric(faker.datatype.number({ min: 1, max: 12 })),
|
||||
errors: () => faker.datatype.number({ max: 10 }),
|
||||
mime_types: () => [MIME_TYPE_ASCIICAST],
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import ChannelRecordingAbility from 'api/abilities/channel-recording';
|
||||
import { inject as service } from '@ember/service';
|
||||
|
||||
export default class OverrideChannelRecordingAbility extends ChannelRecordingAbility {
|
||||
// =service
|
||||
@service features;
|
||||
|
||||
/**
|
||||
* returns true if session recording is completed and the channel
|
||||
* has the correct mime type
|
||||
*/
|
||||
get canPlay() {
|
||||
const { session_recording } = this.model.connection_recording;
|
||||
return session_recording.isAvailable && this.model.isAsciicast;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns true if session recording is completed and the channel
|
||||
* is not the correct mime type
|
||||
*/
|
||||
get canViewOnly() {
|
||||
const { session_recording } = this.model.connection_recording;
|
||||
return session_recording.isAvailable && !this.model.isAsciicast;
|
||||
}
|
||||
}
|
||||
+10
-1
@@ -128,7 +128,7 @@
|
||||
</Copyable>
|
||||
</B.Td>
|
||||
<B.Td align='right'>
|
||||
{{#if @model.sessionRecording.isAvailable}}
|
||||
{{#if (can 'play channel-recording' B.data)}}
|
||||
<Hds::Button
|
||||
@icon='play'
|
||||
@color='secondary'
|
||||
@@ -136,6 +136,15 @@
|
||||
@route='scopes.scope.session-recordings.session-recording.channels-by-connection.channel'
|
||||
@model={{B.data.id}}
|
||||
/>
|
||||
{{else if (can 'viewOnly channel-recording' B.data)}}
|
||||
<Hds::Button
|
||||
@icon='arrow-right'
|
||||
@iconPosition='trailing'
|
||||
@color='secondary'
|
||||
@text={{t 'actions.view'}}
|
||||
@route='scopes.scope.session-recordings.session-recording.channels-by-connection.channel'
|
||||
@model={{B.data.id}}
|
||||
/>
|
||||
{{/if}}
|
||||
</B.Td>
|
||||
</B.Tr>
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Copyright (c) HashiCorp, Inc.
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import { STATE_SESSION_RECORDING_AVAILABLE } from 'api/models/session-recording';
|
||||
import { MIME_TYPE_ASCIICAST } from 'api/models/channel-recording';
|
||||
|
||||
module('Unit | Abilities | channel-recording', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
let canService;
|
||||
let store;
|
||||
let sessionRecording;
|
||||
let connectionRecording;
|
||||
let asciicastChannel;
|
||||
let noneAsciicastChannel;
|
||||
|
||||
hooks.beforeEach(function () {
|
||||
canService = this.owner.lookup('service:can');
|
||||
store = this.owner.lookup('service:store');
|
||||
|
||||
sessionRecording = store.createRecord('session-recording', {
|
||||
state: STATE_SESSION_RECORDING_AVAILABLE,
|
||||
});
|
||||
connectionRecording = store.createRecord('connection-recording', {
|
||||
session_recording: sessionRecording,
|
||||
});
|
||||
asciicastChannel = store.createRecord('channel-recording', {
|
||||
mime_types: [MIME_TYPE_ASCIICAST],
|
||||
connection_recording: connectionRecording,
|
||||
});
|
||||
noneAsciicastChannel = store.createRecord('channel-recording', {
|
||||
mime_types: null,
|
||||
connection_recording: connectionRecording,
|
||||
});
|
||||
});
|
||||
|
||||
test('returns true if session recording complete and channel mime type is asciicast', function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
assert.true(canService.can('play channel-recording', asciicastChannel));
|
||||
assert.false(
|
||||
canService.can('play channel-recording', noneAsciicastChannel)
|
||||
);
|
||||
});
|
||||
|
||||
test('returns false if session recording complete and channel mime type is not asciicast', function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
assert.true(
|
||||
canService.can('viewOnly channel-recording', noneAsciicastChannel)
|
||||
);
|
||||
assert.false(
|
||||
canService.can('viewOnly channel-recording', asciicastChannel)
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user