• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / gui / 951400782

pending completion
951400782

Pull #3900

gitlab-ci

web-flow
chore: bump @testing-library/jest-dom from 5.16.5 to 5.17.0

Bumps [@testing-library/jest-dom](https://github.com/testing-library/jest-dom) from 5.16.5 to 5.17.0.
- [Release notes](https://github.com/testing-library/jest-dom/releases)
- [Changelog](https://github.com/testing-library/jest-dom/blob/main/CHANGELOG.md)
- [Commits](https://github.com/testing-library/jest-dom/compare/v5.16.5...v5.17.0)

---
updated-dependencies:
- dependency-name: "@testing-library/jest-dom"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #3900: chore: bump @testing-library/jest-dom from 5.16.5 to 5.17.0

4446 of 6414 branches covered (69.32%)

8342 of 10084 relevant lines covered (82.73%)

186.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.93
/src/js/components/settings/organization/ssoeditor.js
1
// Copyright 2022 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14
import React, { useCallback, useEffect, useRef, useState } from 'react';
15
import Dropzone from 'react-dropzone';
16

17
// material ui
18
import { Close as CloseIcon, CloudUpload, FileCopyOutlined as CopyPasteIcon } from '@mui/icons-material';
19
import { Button, Divider, Drawer, IconButton } from '@mui/material';
20

21
import Editor, { loader } from '@monaco-editor/react';
22
import copy from 'copy-to-clipboard';
23

24
import { createFileDownload } from '../../../helpers';
25
import Loader from '../../common/loader';
26

27
loader.config({ paths: { vs: '/ui/vs' } });
8✔
28

29
const editorProps = {
8✔
30
  defaultLanguage: 'xml',
31
  height: 700,
32
  language: 'xml',
33
  loading: <Loader show />,
34
  options: {
35
    autoClosingOvertype: 'auto',
36
    codeLens: false,
37
    contextmenu: false,
38
    enableSplitViewResizing: false,
39
    formatOnPaste: true,
40
    lightbulb: { enabled: false },
41
    lineNumbers: 'off',
42
    minimap: { enabled: false },
43
    quickSuggestions: false,
44
    readOnly: true,
45
    renderOverviewRuler: false,
46
    scrollBeyondLastLine: false,
47
    wordWrap: 'on'
48
  }
49
};
50

51
export const SSOEditor = ({ config, fileContent, hasSSOConfig, open, onCancel, onClose, onSave, setFileContent }) => {
8✔
52
  const [isEditing, setIsEditing] = useState(false);
23✔
53
  const [isMetadataValid, setIsMetadataValid] = useState(false);
23✔
54
  const editorRef = useRef();
23✔
55

56
  useEffect(() => {
23✔
57
    if (!fileContent) {
10✔
58
      return;
5✔
59
    }
60
    const parser = new DOMParser();
5✔
61
    const theDom = parser.parseFromString(fileContent, 'application/xml');
5✔
62
    setIsMetadataValid(!theDom.getElementsByTagName('parsererror').length);
5✔
63
  }, [fileContent]);
64

65
  const onEditClick = () => setIsEditing(true);
23✔
66

67
  const onDownloadClick = () => createFileDownload(fileContent, 'metadata.xml');
23✔
68

69
  const onCancelClick = useCallback(() => {
23✔
70
    if (isEditing) {
×
71
      setFileContent(config);
×
72
      if (!hasSSOConfig) {
×
73
        return onCancel();
×
74
      }
75
      return setIsEditing(false);
×
76
    }
77
    onCancel();
×
78
  }, [config, isEditing, onCancel]);
79

80
  const onSubmitClick = () => {
23✔
81
    onSave();
×
82
    setIsEditing(false);
×
83
  };
84

85
  const onCopyClick = () => copy(fileContent);
23✔
86

87
  const onDrop = acceptedFiles => {
23✔
88
    let reader = new FileReader();
1✔
89
    reader.fileName = acceptedFiles[0].name;
1✔
90
    reader.onerror = error => {
1✔
91
      console.log('Error: ', error);
×
92
      setIsEditing(false);
×
93
    };
94
    reader.onload = () => {
1✔
95
      setFileContent(reader.result);
1✔
96
      setIsEditing(true);
1✔
97
    };
98
    reader.readAsBinaryString(acceptedFiles[0]);
1✔
99
  };
100

101
  const handleEditorDidMount = (editor, monaco) => {
23✔
102
    monaco.languages.html.registerHTMLLanguageService('xml', {}, { documentFormattingEdits: true });
×
103
    editorRef.current = { editor, monaco, modifiedEditor: editor };
×
104
  };
105

106
  return (
23✔
107
    <Drawer className={`${open ? 'fadeIn' : 'fadeOut'}`} anchor="right" open={open} onClose={onClose} PaperProps={{ style: { minWidth: '75vw' } }}>
23✔
108
      <div className="flexbox margin-bottom-small space-between">
109
        <h3>SAML metadata</h3>
110
        <div className="flexbox center-aligned">
111
          <Dropzone multiple={false} onDrop={onDrop}>
112
            {({ getRootProps, getInputProps }) => (
113
              <div {...getRootProps()}>
11✔
114
                <input {...getInputProps()} />
115
                <Button color="secondary" startIcon={<CloudUpload fontSize="small" />}>
116
                  Import from a file
117
                </Button>
118
              </div>
119
            )}
120
          </Dropzone>
121

122
          <IconButton onClick={onClose} size="large">
123
            <CloseIcon />
124
          </IconButton>
125
        </div>
126
      </div>
127
      <Divider light />
128
      <Editor
129
        {...editorProps}
130
        options={{
131
          ...editorProps.options,
132
          readOnly: hasSSOConfig && !isEditing
38✔
133
        }}
134
        className="editor modified"
135
        onChange={setFileContent}
136
        onMount={handleEditorDidMount}
137
        value={fileContent}
138
      />
139
      {!isMetadataValid && fileContent.length > 4 && <div className="error">There was an error parsing the metadata.</div>}
50✔
140
      <Divider className="margin-top-large margin-bottom" light />
141
      <div>
142
        {hasSSOConfig && !isEditing ? (
61✔
143
          <div className="flexbox center-aligned">
144
            <Button onClick={onEditClick}>Edit</Button>
145
            <Button onClick={onDownloadClick}>Download file</Button>
146
            <Button onClick={onCopyClick} startIcon={<CopyPasteIcon />}>
147
              Copy to clipboard
148
            </Button>
149
          </div>
150
        ) : (
151
          <>
152
            <Button onClick={onCancelClick}>Cancel</Button>
153
            <Button variant="contained" disabled={!isMetadataValid} onClick={onSubmitClick} color="secondary" style={{ marginLeft: 10 }}>
154
              Save
155
            </Button>
156
          </>
157
        )}
158
      </div>
159
    </Drawer>
160
  );
161
};
162

163
export default SSOEditor;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc