21720:
[arvados.git] / services / workbench2 / src / components / refresh-button / refresh-button.cy.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from "react";
6 import { LAST_REFRESH_TIMESTAMP, RefreshButton } from './refresh-button';
7
8 describe('<RefreshButton />', () => {
9     let props;
10     let replace;
11     let urlPath;
12
13     beforeEach(() => {
14         props = {
15             history: {
16                 replace: () => { },
17             },
18             classes: {},
19         };
20
21         replace = cy.spy(props.history, 'replace').as('replace');
22     });
23
24     it('should render without issues', () => {
25         // when
26         cy.mount(<RefreshButton {...props} />);
27
28         // then
29         cy.get('button').should('exist');
30     });
31
32     it('should pass window location to router', () => {
33         // setup
34         cy.mount(<RefreshButton {...props} />);
35
36         cy.window().then((win) => {
37             urlPath = win.location.pathname;
38             expect(!!win.localStorage.getItem(LAST_REFRESH_TIMESTAMP)).to.equal(false);
39         });
40
41         // when
42         cy.get('button').should('exist').click();
43
44         // then
45         cy.window().then((win) => {
46             cy.get('@replace').should('have.been.calledWith', urlPath);
47             expect(!!win.localStorage.getItem(LAST_REFRESH_TIMESTAMP)).not.to.equal(false);
48         });
49     });
50 });