123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- import selectEvent from 'react-select-event';
- import {render, screen} from 'sentry-test/reactTestingLibrary';
- import ProjectsStore from 'sentry/stores/projectsStore';
- import {DiscoverLanding} from 'sentry/views/discover/landing';
- describe('Discover > Landing', function () {
- const eventTitle = 'Oh no something bad';
- const features = ['discover-basic', 'discover-query'];
- beforeEach(function () {
- ProjectsStore.loadInitialData([TestStubs.Project()]);
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/projects/',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/eventsv2/',
- body: {
- meta: {
- id: 'string',
- title: 'string',
- 'project.name': 'string',
- timestamp: 'date',
- 'user.id': 'string',
- },
- data: [
- {
- id: 'deadbeef',
- 'user.id': 'alberto leal',
- title: eventTitle,
- 'project.name': 'project-slug',
- timestamp: '2019-05-23T22:12:48+00:00',
- },
- ],
- },
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events/project-slug:deadbeef/',
- method: 'GET',
- body: {
- id: '1234',
- size: 1200,
- eventID: 'deadbeef',
- title: 'Oh no something bad',
- message: 'It was not good',
- dateCreated: '2019-05-23T22:12:48+00:00',
- entries: [
- {
- type: 'message',
- message: 'bad stuff',
- data: {},
- },
- ],
- tags: [{key: 'browser', value: 'Firefox'}],
- },
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/events-stats/',
- method: 'GET',
- body: [],
- });
- MockApiClient.addMockResponse({
- url: '/organizations/org-slug/discover/saved/',
- method: 'GET',
- body: [],
- });
- });
- it('denies access on missing feature', function () {
- render(
- <DiscoverLanding
- organization={TestStubs.Organization()}
- location={{query: {}}}
- router={{}}
- />
- );
- expect(screen.getByText("You don't have access to this feature")).toBeInTheDocument();
- });
- it('has the right sorts', function () {
- const org = TestStubs.Organization({features});
- render(<DiscoverLanding organization={org} location={{query: {}}} router={{}} />);
- const expectedSorts = [
- 'My Queries',
- 'Recently Edited',
- 'Query Name (A-Z)',
- 'Date Created (Newest)',
- 'Date Created (Oldest)',
- 'Most Outdated',
- 'Most Popular',
- 'Recently Viewed',
- ];
- // Open menu
- selectEvent.openMenu(screen.getByRole('button', {name: 'Sort By My Queries'}));
- // Check that all sorts are there
- expectedSorts.forEach(sort =>
- expect(screen.getAllByText(sort)[0]).toBeInTheDocument()
- );
- });
- it('links back to the homepage', () => {
- const org = TestStubs.Organization({
- features: [...features, 'discover-query-builder-as-landing-page'],
- });
- render(<DiscoverLanding organization={org} location={{query: {}}} router={{}} />, {
- context: TestStubs.routerContext(),
- });
- expect(screen.getByText('Discover')).toHaveAttribute(
- 'href',
- '/organizations/org-slug/discover/homepage/'
- );
- });
- });
|