81 lines
2.6 KiB
JavaScript
81 lines
2.6 KiB
JavaScript
// UserPanel.spec.js
|
|
import UserPanel from 'src/components/common/UserPanel.vue';
|
|
import { ref } from 'vue';
|
|
|
|
describe.only('<UserPanel />', () => {
|
|
beforeEach(() => {
|
|
// Mock composables and dependencies
|
|
cy.stub(window, 'useI18n').returns({
|
|
t: (key) => key,
|
|
locale: 'en',
|
|
});
|
|
cy.stub(window, 'useRouter').returns({});
|
|
cy.stub(window, 'useState').returns({});
|
|
cy.stub(window, 'useSession').returns({});
|
|
cy.stub(window, 'useClipboard').returns({
|
|
copyText: cy.stub().as('copyTextStub'),
|
|
});
|
|
cy.stub(window, 'useRole').returns({});
|
|
cy.stub(window, 'useNotify').returns({
|
|
notify: cy.stub().as('notifyStub'),
|
|
});
|
|
cy.stub(window, 'axios').as('axiosStub');
|
|
});
|
|
|
|
it('renders user panel components', () => {
|
|
cy.createWrapper(UserPanel);
|
|
cy.getComponent('VnSelect').should('exist');
|
|
cy.getComponent('VnRow').should('exist');
|
|
cy.getComponent('FetchData').should('exist');
|
|
cy.getComponent('VnAvatar').should('exist');
|
|
});
|
|
|
|
it('displays user locale correctly', () => {
|
|
cy.createWrapper(UserPanel);
|
|
cy.wrap(Cypress.vueWrapper.vm.userLocale).should('equal', 'en');
|
|
});
|
|
|
|
it('updates locale when userLocale is changed', () => {
|
|
cy.createWrapper(UserPanel);
|
|
cy.wrap(Cypress.vueWrapper.vm.userLocale).set('fr');
|
|
cy.wrap(Cypress.vueWrapper.vm.locale).should('equal', 'fr');
|
|
});
|
|
|
|
it('copies text to clipboard', () => {
|
|
cy.createWrapper(UserPanel);
|
|
cy.get('.copy-button').click();
|
|
cy.get('@copyTextStub').should('have.been.called');
|
|
});
|
|
|
|
it('notifies user on copy', () => {
|
|
cy.createWrapper(UserPanel);
|
|
cy.get('.copy-button').click();
|
|
cy.get('@notifyStub').should('have.been.called');
|
|
});
|
|
|
|
it('fetches user data on mount', () => {
|
|
cy.createWrapper(UserPanel);
|
|
cy.get('@axiosStub').should('have.been.called');
|
|
});
|
|
|
|
it('renders user avatar', () => {
|
|
cy.createWrapper(UserPanel);
|
|
cy.getComponent('VnAvatar').should('exist');
|
|
});
|
|
|
|
it('handles dark mode toggle', () => {
|
|
cy.createWrapper(UserPanel);
|
|
cy.get('.dark-mode-toggle').click();
|
|
cy.wrap(Cypress.vueWrapper.vm.$q.dark.isActive).should('be.true');
|
|
});
|
|
|
|
it('handles logout action', () => {
|
|
const routerPush = cy.spy().as('routerPush');
|
|
cy.stub(window, 'useRouter').returns({ push: routerPush });
|
|
|
|
cy.createWrapper(UserPanel);
|
|
cy.get('.logout-button').click();
|
|
cy.get('@routerPush').should('have.been.calledWith', '/login');
|
|
});
|
|
});
|