░▒▓████████████████████████████████▓▒░ ░▒▓█ ▓▒░ ░▒▓█ ~ S W A M P ~ ▓▒░ ░▒▓█ ▓▒░ ░▒▓████████████████████████████████▓▒░
pplmvsvm
LOCATION:
/var/www/canvas/ui/features/navigation_header/react/HelpDialog/__tests__
☗ ROOT
↻ REFRESH
✎ CARVE FLESH
EDITING: HelpLinks.test.js
// Copyright (C) 2020 - present Instructure, Inc. // // This file is part of Canvas. // // Canvas is free software: you can redistribute it and/or modify it under // the terms of the GNU Affero General Public License as published by the Free // Software Foundation, version 3 of the License. // // Canvas is distributed in the hope that it will be useful, but WITHOUT ANY // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR // A PARTICULAR PURPOSE. See the GNU Affero General Public License for more // details. // // You should have received a copy of the GNU Affero General Public License along // with this program. If not, see <http://www.gnu.org/licenses/>. import React from 'react' import {fireEvent, render, waitFor} from '@testing-library/react' import HelpLinks from '../HelpLinks' describe('HelpLinks', () => { const featuredLink = { id: 'search_the_canvas_guides', type: 'default', available_to: ['user', 'student', 'teacher', 'admin', 'observer', 'unenrolled'], text: 'Search the Canvas Guides', subtext: 'Find answers to common questions', url: 'https://community.canvaslms.test/t5/Canvas/ct-p/canvas', is_featured: true, is_new: false, feature_headline: 'Little Lost? Try here first!', } const newLink = { id: 'link1', text: 'Google', subtext: 'Have you tried google?', url: 'https://google.com', type: 'custom', available_to: ['user', 'student', 'teacher', 'admin', 'observer', 'unenrolled'], is_featured: false, is_new: true, } const regularLink = { id: 'report_a_problem', type: 'default', available_to: ['user', 'student', 'teacher', 'admin', 'observer', 'unenrolled'], text: 'Report a Problem', subtext: 'If Canvas misbehaves, tell us about it', url: '#create_ticket', is_featured: false, is_new: false, } const noWindowLink = { id: 'inline_help_link', type: 'default', no_new_window: true, available_to: ['user', 'student', 'teacher', 'admin', 'observer', 'unenrolled'], text: 'Support Centre', subtext: 'Ask ur question', url: '?enjoy=this', is_featured: false, is_new: false, } const props = { links: [featuredLink, newLink, regularLink], hasLoaded: true, onClick() {}, } const savedLocation = window.location let mockedReplace beforeEach(() => { window.ENV = {FEATURES: {featured_help_links: true}} mockedReplace = jest.fn() delete global.window.location global.window = Object.create(window) global.window.location = {replace: mockedReplace} }) afterEach(() => { window.ENV = {} global.window.location = savedLocation }) it('renders all the links', () => { const {queryByText} = render(<HelpLinks {...props} />) expect(queryByText('Google')).toBeInTheDocument() expect(queryByText('Search the Canvas Guides')).toBeInTheDocument() expect(queryByText('Report a Problem')).toBeInTheDocument() }) it('renders all the links when the FF is disabled', () => { window.ENV = {FEATURES: {featured_help_links: false}} const {queryByText} = render(<HelpLinks {...props} />) expect(queryByText('Google')).toBeInTheDocument() expect(queryByText('Search the Canvas Guides')).toBeInTheDocument() expect(queryByText('Report a Problem')).toBeInTheDocument() }) it('renders the separator when there is a featured link, additional links, and the FF is enabled', () => { const {queryByText} = render(<HelpLinks {...props} />) expect(queryByText('OTHER RESOURCES')).toBeInTheDocument() }) it('does not render the separator if there is no featured link', () => { const {queryByText} = render(<HelpLinks {...props} links={[newLink, regularLink]} />) expect(queryByText('OTHER RESOURCES')).not.toBeInTheDocument() }) it('does not render the separator if the FF is disabled', () => { window.ENV = {FEATURES: {featured_help_links: false}} const {queryByText} = render(<HelpLinks {...props} />) expect(queryByText('OTHER RESOURCES')).not.toBeInTheDocument() }) it('does not render the separator if there is only a featured link', () => { const {queryByText} = render(<HelpLinks {...props} links={[featuredLink]} />) expect(queryByText('OTHER RESOURCES')).not.toBeInTheDocument() }) it('tries to load a new URL in place if the no_new_window flag is set', async () => { const links = [...props.links, noWindowLink] const {getByText} = render(<HelpLinks {...props} links={links} />) const link = getByText('Support Centre') fireEvent.click(link) await waitFor(() => expect(mockedReplace).toHaveBeenCalledWith('?enjoy=this')) }) it('renders a "NEW" pill when a link is tagged with is_new', () => { const {queryByText} = render(<HelpLinks {...props} links={[newLink]} />) expect(queryByText('NEW')).toBeInTheDocument() }) it('does not render a "NEW" pill if there is no link tagged with is_new', () => { const {queryByText} = render(<HelpLinks {...props} links={[featuredLink, regularLink]} />) expect(queryByText('NEW')).not.toBeInTheDocument() }) it('does not render a "NEW" pill if the FF is disabled', () => { window.ENV = {FEATURES: {featured_help_links: false}} const {queryByText} = render(<HelpLinks {...props} />) expect(queryByText('NEW')).not.toBeInTheDocument() }) })
CANCEL
Name
Type
Size
Modified
Actions
↩ ..
DIR
—
—
📄 CreateTicketForm.test.js
JS
3.4 KB
2023-09-24 03:39
EDIT
📄 FeaturedHelpLink.test.js
JS
2.1 KB
2023-09-24 03:39
EDIT
📄 HelpLinks.test.js
JS
5.3 KB
2023-09-24 03:39
EDIT
📄 TeacherFeedbackForm.test.js
JS
2.9 KB
2023-09-24 03:39
EDIT