it('renders the empty upload tab by default', async () => {
    const {container, getByTestId, getByText} = render(
      <ContentUploadTab assignment={mockAssignment()} />
    )
    const emptyRender = getByTestId('empty-upload')

    expect(emptyRender).toContainElement(getByText('Upload File'))
    expect(emptyRender).toContainElement(
      container.querySelector(`svg[name=${DEFAULT_ICON.type.displayName}]`)
    )
  })
  it('renders a button to remove the file', async () => {
    const {container, getByText} = render(<ContentUploadTab assignment={mockAssignment()} />)
    const emptyRender = container.querySelector('input[type="file"]')
    const file = new File(['foo'], 'awesome-test-file.pdf', {type: 'application/pdf'})

    uploadFiles(emptyRender, [file])
    const button = container.querySelector('button')

    expect(button).toContainElement(getByText('Remove awesome-test-file.pdf'))
    expect(button).toContainElement(container.querySelector('svg[name="IconTrash"]'))
  })
Example #3
0
  it('renders the install screen for the legacy add-on', () => {
    userAgent = FIREFOX_LEGACY;

    const { container } = render(
      <Provider store={createStore()}>
        <Home specialMessage="This is a special message" />
      </Provider>
    );

    expect(container.firstChild).toMatchSnapshot();
  });
Example #4
0
  it('includes an icon on an attachment', async () => {
    const comment = singleComment()
    const attachment = singleAttachment()
    comment.attachments = [attachment]

    const {container, getByText} = render(<CommentContent comments={[comment]} />)

    expect(
      getByText(attachment.displayName, {selector: `a[href*='${attachment.url}']`})
    ).toContainElement(container.querySelector("svg[name='IconPdf']"))
  })
Example #5
0
  it('renders the information screen for other browsers', () => {
    userAgent = SAFARI;

    const { container } = render(
      <Provider store={createStore()}>
        <Home specialMessage="This is a special message" />
      </Provider>
    );

    expect(container.firstChild).toMatchSnapshot();
  });
function renderOD(override, props = {}) {
  return render(
    <OverrideDetail
      override={override}
      onChangeOverride={() => {}}
      onValidate={() => true}
      invalidMessage={() => undefined}
      {...props}
    />
  )
}
Example #7
0
  it(`renders icon, if defined`, () => {
    const icon = <span>Icon</span>

    const { getByText } = render(
      <Button to="/with-icon" icon={icon}>
        Hello
      </Button>
    )

    expect(getByText(`Icon`)).toBeDefined()
  })
Example #8
0
it('label text content is correct', () => {
  // Arrange
  const coin = { id: 2 };
  const component = <Coin coin={coin} setOwnedValue={() => {}} />;

  // Act
  const { getByTestId } = render(component);

  // Assert
  expect(getByTestId('coin-label').textContent).toBe('');
});
Example #9
0
it('coin markup is correct', () => {
  // Arrange
  const coin = { id: 2, name: 'Kew Gardens' };
  const component = <Coin coin={coin} setOwnedValue={() => {}} />;

  // Act
  const { container } = render(component);

  // Assert
  expect(container.firstChild).toMatchSnapshot();
});
Example #10
0
    it('should have a value set', () => {
      const { container } = render(
        <Meter label="My Example Meter" initialValue={50} max={80} />
      )

      expect(container.firstChild).toMatchSnapshot()
      const input = container.querySelector('meter')

      expect(input.getAttribute('value')).toBe('50')
      expect(input.getAttribute('max')).toBe('80')
    })
  it('renders an icon if a non-image file is uploaded', async () => {
    const {container, getByTestId} = render(<ContentUploadTab assignment={mockAssignment()} />)
    const emptyRender = container.querySelector('input[type="file"]')
    const file = new File(['foo'], 'awesome-test-file.pdf', {type: 'application/pdf'})

    uploadFiles(emptyRender, [file])
    const uploadRender = getByTestId('non-empty-upload')

    expect(uploadRender).toContainElement(container.querySelector('svg[name="IconPdf"]'))
    expect(container.querySelector('img[alt="awesome-test-file.pdf preview"]')).toBeNull()
  })
function renderMessageStudentsWhoDialog(assignment = mockAssignment(), propsOverride = {}) {
  const props = {
    assignment,
    open: true,
    busy: false,
    onSend: () => {},
    onClose: () => {},
    ...propsOverride
  }
  return render(<MessageStudentsWhoDialog {...props} />)
}
function setup() {
  const childrenArg = {}
  const children = arg => {
    Object.assign(childrenArg, arg)
    return null
  }
  render(<Toggle>{children}</Toggle>)
  return {
    childrenArg,
  }
}
Example #14
0
  test('does not render anything if there is an integration point', () => {
    // Given
    const integrationPoint = { x: true }

    // When
    const { container } = render(
      <DesktopIntegration integrationPoint={integrationPoint} />
    )

    // Then
    expect(container).toMatchSnapshot()
  })
function setup({render = () => <div />, ...props} = {}) {
  let renderArg
  const renderSpy = jest.fn(controllerArg => {
    renderArg = controllerArg
    return render(controllerArg)
  })
  const domUtils = renderToDOM(<Downshift {...props} render={renderSpy} />)
  const input = domUtils.queryByTestId('input')
  const label = domUtils.queryByTestId('label')
  const item = domUtils.queryByTestId('item-0')
  return {input, label, item, ...domUtils, ...renderArg}
}
			() => {
				const {getByTestId} = render(
					<CriteriaSidebarSearchBar
						onChange={jest.fn()}
						searchValue={'test'}
					/>
				);

				const searchInput = getByTestId(SEARCH_INPUT_TESTID);

				expect(searchInput.value).toEqual('test');
			}
Example #17
0
  it('does not render several dot markers in the same position', () => {
    const flushRafCalls = mockRaf();
    window.devicePixelRatio = 2;
    const ctx = mockCanvasContext();
    jest
      .spyOn(HTMLCanvasElement.prototype, 'getBoundingClientRect')
      .mockImplementation(() => getBoundingBox(200, 300));
    jest
      .spyOn(HTMLCanvasElement.prototype, 'getContext')
      .mockImplementation(() => ctx);

    const markers = [
      // 2 very close dot markers. They shouldn't be drawn both together.
      ['Marker A', 5000, null],
      ['Marker B', 5001, null],
      // This is a longer marker starting at the same place, it should always be drawn
      ['Marker C', 5001, { startTime: 5001, endTime: 7000 }],
    ];
    const profile = getProfileWithMarkers(markers);

    render(
      <Provider store={storeWithProfile(profile)}>
        <TimelineMarkersOverview
          rangeStart={0}
          rangeEnd={15000}
          threadIndex={0}
          onSelect={() => {}}
        />
      </Provider>
    );

    // We need to flush twice since when the first flush is run, it
    // will request more code to be run in later animation frames.
    flushRafCalls();
    flushRafCalls();

    const drawCalls = ctx.__flushDrawLog();

    // We filter on height to get only 1 relevant fillRect operation for each marker.
    const fillRectOperations = drawCalls.filter(
      ([operation, , , , height]) => operation === 'fillRect' && height > 1
    );

    // Here 2 markers should be drawn: the first dot, and the long marker.
    expect(fillRectOperations).toHaveLength(2);
    expect(
      fillRectOperations.every(
        ([, , , width]) => width >= MIN_MARKER_WIDTH / window.devicePixelRatio
      )
    ).toBe(true);

    delete window.devicePixelRatio;
  });
it('renders with delay correctly with hook', () => {
  const Hook = () => {
    const { countUp } = useCountUp({ delay: 1, end: 10 });
    return <span>{countUp}</span>;
  };

  const { container } = render(<Hook />);
  const span = container.firstChild;
  flushEffects();
  jest.runAllTimers();
  expect(span.textContent).toEqual('0');
});
function renderAssignmentPoints(props) {
  return render(
    <AssignmentPoints
      mode="view"
      onChange={() => {}}
      onChangeMode={() => {}}
      onValidate={validate}
      pointsPossible={1432}
      {...props}
    />
  )
}
    it('should set a value when passed in but not be valid', () => {
      const { getByLabelText, container } = render(
        <Password label="My Example Label" initialValue="password" />
      )

      expect(container.firstChild).toMatchSnapshot()
      const input = getByLabelText('My Example Label')
      expect(input.value).toBe('password')
      expect(input.validity.valid).toBe(true)
      fireEvent.change(input, { target: { value: 'Updated Value' } })
      expect(input.validity.valid).toBe(true)
    })
    it('should have a label', () => {
      const labelText = 'My Password Label'
      const { getByText, getByLabelText, container } = render(
        <Password label={labelText} />
      )

      expect(container.firstChild).toMatchSnapshot()
      const label = getByText(labelText)
      const input = getByLabelText(labelText)
      expect(label.textContent).toBe(labelText)
      expect(input.type).toBe('password')
    })
Example #22
0
  it(`does not send tracking event if ga is undefined`, () => {
    delete window.ga

    const { getByText } = render(
      <Button to="/not-tracked" tracking={true}>
        Hello
      </Button>
    )
    fireEvent.click(getByText(`Hello`))

    expect(ga).not.toHaveBeenCalled()
  })
Example #23
0
  it(`invokes custom onClick handler`, () => {
    const onClick = jest.fn()

    const { getByText } = render(
      <Button to="/custom-click" onClick={onClick}>
        Hello
      </Button>
    )
    fireEvent.click(getByText(`Hello`))

    expect(onClick).toHaveBeenCalledWith(expect.any(Object))
  })
function renderAssignmentName(props) {
  return render(
    <AssignmentName
      mode="view"
      onChange={() => {}}
      onChangeMode={() => {}}
      onValidate={validate}
      name="the name"
      {...props}
    />
  )
}
			() => {
				const {getByTestId} = render(
					<CriteriaSidebarSearchBar
						onChange={jest.fn()}
						searchValue={'test'}
					/>
				);

				const searchButton = getByTestId(SEARCH_BUTTON_TESTID);

				expect(searchButton).toMatchSnapshot();
			}
Example #26
0
  test('should load photo', () => {
    const props = {
      ...getProps(),
      loadPhoto: jest.fn(),
      photo: undefined
    }

    const { container } = render(<Edit {...props} />)

    expect(container).toMatchSnapshot()
    expect(props.loadPhoto).toHaveBeenCalledWith(199)
  })
    test('displays nothing if no notifications', () => {
      // Given
      const props = {
        result: {}
      }

      // When
      const { container } = render(<WarningsView {...props} />)

      // Then
      expect(container).toMatchSnapshot()
    })
  it('renders in an img tag if an image is uploaded', async () => {
    const {container, getByTestId} = render(<ContentUploadTab assignment={mockAssignment()} />)
    const emptyRender = container.querySelector('input[type="file"]')
    const file = new File(['foo'], 'awesome-test-image.png', {type: 'image/png'})

    uploadFiles(emptyRender, [file])
    const uploadRender = getByTestId('non-empty-upload')

    expect(uploadRender).toContainElement(
      container.querySelector('img[alt="awesome-test-image.png preview"]')
    )
  })
 it('renders the value in edit mode', () => {
   const {getByDisplayValue} = render(
     <EditableNumber
       mode="edit"
       onChange={() => {}}
       onChangeMode={() => {}}
       label="Pick a number"
       value="17"
     />
   )
   expect(getByDisplayValue('17')).toBeInTheDocument()
 })
  it('should eject on unmount with a correct saga key', () => {
    const props = { test: 'test' };
    const { unmount } = render(
      <Provider store={store}>
        <ComponentWithSaga {...props} />
      </Provider>,
    );
    unmount();

    expect(injectors.ejectSaga).toHaveBeenCalledTimes(1);
    expect(injectors.ejectSaga).toHaveBeenCalledWith('test');
  });