-
Notifications
You must be signed in to change notification settings - Fork 249
[Remove Vuetify from Studio] Channel details in Channels - content #5540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: unstable
Are you sure you want to change the base?
Changes from all commits
6cfccd3
1c2b8a2
6dd35e6
3a7efef
b88a08b
356b8a0
bb42e69
a14b62e
5c41386
e92cd60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| <template> | ||
|
|
||
| <span | ||
| class="studio-chip" | ||
| :class="{ notranslate }" | ||
| :style="chipStyle" | ||
| > | ||
| <slot></slot> | ||
| </span> | ||
|
|
||
| </template> | ||
|
|
||
|
|
||
| <script> | ||
|
|
||
| export default { | ||
| name: 'StudioChip', | ||
| props: { | ||
| notranslate: { | ||
| type: Boolean, | ||
| default: false, | ||
| }, | ||
| }, | ||
| computed: { | ||
| chipStyle() { | ||
| return { | ||
| color: this.$themeTokens.text, | ||
| backgroundColor: this.$themePalette.grey.v_200, | ||
| }; | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| </script> | ||
|
|
||
|
|
||
| <style lang="scss" scoped> | ||
|
|
||
| .studio-chip { | ||
| display: inline-block; | ||
| padding: 4px 8px; | ||
| margin: 2px 4px 2px 0; | ||
| font-size: 12px; | ||
| font-weight: bold; | ||
| line-height: 16px; | ||
| border-radius: 10px; | ||
| } | ||
|
|
||
| </style> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import { render, screen } from '@testing-library/vue'; | ||
| import VueRouter from 'vue-router'; | ||
| import StudioChip from '../StudioChip.vue'; | ||
|
|
||
| const router = new VueRouter({ | ||
| routes: [], | ||
| }); | ||
|
|
||
| describe('StudioChip', () => { | ||
| it('renders chip with text content', () => { | ||
| render(StudioChip, { | ||
| router, | ||
| slots: { | ||
| default: 'Test Tag', | ||
| }, | ||
| }); | ||
|
|
||
| expect(screen.getByText('Test Tag')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('applies notranslate class when prop is true', () => { | ||
| const { container } = render(StudioChip, { | ||
| router, | ||
| props: { | ||
| notranslate: true, | ||
| }, | ||
| slots: { | ||
| default: 'User Content', | ||
| }, | ||
| }); | ||
|
|
||
| const chip = container.querySelector('.studio-chip'); | ||
| expect(chip).toHaveClass('notranslate'); | ||
| }); | ||
|
|
||
| it('does not apply notranslate class when prop is false', () => { | ||
| const { container } = render(StudioChip, { | ||
| router, | ||
| props: { | ||
| notranslate: false, | ||
| }, | ||
| slots: { | ||
| default: 'Regular Content', | ||
| }, | ||
| }); | ||
|
|
||
| const chip = container.querySelector('.studio-chip'); | ||
| expect(chip).not.toHaveClass('notranslate'); | ||
| }); | ||
|
|
||
| it('renders multiple chips independently', () => { | ||
| const { container: container1 } = render(StudioChip, { | ||
| router, | ||
| slots: { | ||
| default: 'Chip 1', | ||
| }, | ||
| }); | ||
|
|
||
| const { container: container2 } = render(StudioChip, { | ||
| router, | ||
| slots: { | ||
| default: 'Chip 2', | ||
| }, | ||
| }); | ||
|
|
||
| expect(container1.querySelector('.studio-chip')).toHaveTextContent('Chip 1'); | ||
| expect(container2.querySelector('.studio-chip')).toHaveTextContent('Chip 2'); | ||
| }); | ||
|
|
||
| it('has correct styling classes', () => { | ||
| const { container } = render(StudioChip, { | ||
| router, | ||
| slots: { | ||
| default: 'Styled Chip', | ||
| }, | ||
| }); | ||
|
|
||
| const chip = container.querySelector('.studio-chip'); | ||
| expect(chip).toBeTruthy(); | ||
| expect(chip.tagName).toBe('SPAN'); | ||
| }); | ||
| }); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test suite needs to test things like
This is just one of many examples. Same applies for all other information on the page - preview it as a user for channel with/without data, and then make unit tests to document the behavior. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| import { render } from '@testing-library/vue'; | ||
| import VueRouter from 'vue-router'; | ||
| import StudioDetailsPanel from '../details/StudioDetailsPanel.vue'; | ||
|
|
||
| const router = new VueRouter({ | ||
| routes: [], | ||
| }); | ||
|
|
||
| const mockChannelDetails = { | ||
| name: 'Test Channel', | ||
| description: 'Test channel description', | ||
| thumbnail_url: null, | ||
| published: true, | ||
| version: 1, | ||
| primary_token: 'test-token', | ||
| language: 'en', | ||
| resource_count: 10, | ||
| kind_count: [], | ||
| }; | ||
|
|
||
| describe('StudioDetailsPanel', () => { | ||
| it('renders without crashing with minimal props', () => { | ||
| const { container } = render(StudioDetailsPanel, { | ||
| router, | ||
| props: { | ||
| details: {}, | ||
| isChannel: false, | ||
| loading: false, | ||
| }, | ||
| mocks: { | ||
| $formatNumber: jest.fn(n => String(n)), | ||
| $formatDate: jest.fn(() => 'Test Date'), | ||
| $tr: jest.fn(key => key), | ||
| }, | ||
| }); | ||
|
|
||
| expect(container).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('displays loader when loading is true', () => { | ||
| const { container } = render(StudioDetailsPanel, { | ||
| router, | ||
| props: { | ||
| details: {}, | ||
| isChannel: true, | ||
| loading: true, | ||
| }, | ||
| mocks: { | ||
| $formatNumber: jest.fn(n => String(n)), | ||
| $formatDate: jest.fn(() => 'Test Date'), | ||
| $tr: jest.fn(key => key), | ||
| }, | ||
| }); | ||
|
|
||
| expect(container).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders channel information', () => { | ||
| const { container } = render(StudioDetailsPanel, { | ||
| router, | ||
| props: { | ||
| details: mockChannelDetails, | ||
| isChannel: true, | ||
| loading: false, | ||
| }, | ||
| mocks: { | ||
| $formatNumber: jest.fn(n => String(n)), | ||
| $formatDate: jest.fn(() => 'Test Date'), | ||
| $tr: jest.fn(key => key), | ||
| }, | ||
| }); | ||
|
|
||
| expect(container).toHaveTextContent('Test Channel'); | ||
| }); | ||
|
|
||
| it('does not use VDataTable', () => { | ||
| const { container } = render(StudioDetailsPanel, { | ||
| router, | ||
| props: { | ||
| details: mockChannelDetails, | ||
| isChannel: true, | ||
| loading: false, | ||
| }, | ||
| mocks: { | ||
| $formatNumber: jest.fn(n => String(n)), | ||
| $formatDate: jest.fn(() => 'Test Date'), | ||
| $tr: jest.fn(key => key), | ||
| }, | ||
| }); | ||
|
|
||
| expect(container.querySelector('.v-datatable')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('does not use VChip', () => { | ||
| const { container } = render(StudioDetailsPanel, { | ||
| router, | ||
| props: { | ||
| details: mockChannelDetails, | ||
| isChannel: true, | ||
| loading: false, | ||
| }, | ||
| mocks: { | ||
| $formatNumber: jest.fn(n => String(n)), | ||
| $formatDate: jest.fn(() => 'Test Date'), | ||
| $tr: jest.fn(key => key), | ||
| }, | ||
| }); | ||
|
|
||
| expect(container.querySelector('.v-chip')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('does not use VLayout or VFlex', () => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Users are not interested in our Vuetify refactor - for them it doesn't matter if we use Would you find some articles around good unit testing practices, and also have a look at VTL guiding principles? For each test scenario you write, reflect critically on why is the scenario useful or not, and what it tests from the user point of view. |
||
| const { container } = render(StudioDetailsPanel, { | ||
| router, | ||
| props: { | ||
| details: mockChannelDetails, | ||
| isChannel: true, | ||
| loading: false, | ||
| }, | ||
| mocks: { | ||
| $formatNumber: jest.fn(n => String(n)), | ||
| $formatDate: jest.fn(() => 'Test Date'), | ||
| $tr: jest.fn(key => key), | ||
| }, | ||
| }); | ||
|
|
||
| expect(container.querySelector('.v-layout')).not.toBeInTheDocument(); | ||
| expect(container.querySelector('.v-flex')).not.toBeInTheDocument(); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be removed.
We typically don't test styling or classes in unit tests - it doesn't say that much about resulting experience. And is extra maintenance - when class or style is removed or renamed, we'd need to update test.
Generally in all our tests you can focus on testing (1) rendered content, (2) business logic. Please revisit other tests too.